New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

find-replacement-tx

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

find-replacement-tx - npm Package Compare versions

Comparing version 1.1.0 to 1.2.0-0

6

dist/index.d.ts

@@ -1,2 +0,2 @@

import { Transaction } from 'web3-core';
import { ethers } from 'ethers';
export declare class SearchError extends Error {

@@ -13,3 +13,3 @@ }

*/
export declare function getTransactionByNonce(provider: any, startSearch: number, from: string, nonce: number): Promise<Transaction | null>;
export declare function getTransactionByNonce(provider: ethers.providers.Provider, startSearch: number, from: string, nonce: number): Promise<ethers.providers.TransactionResponse | null>;
/**

@@ -42,3 +42,3 @@ * Search and validate a replaced transaction (speed up)

}) => boolean;
}): Promise<Transaction | null>;
}): Promise<ethers.providers.TransactionResponse | null>;
//# sourceMappingURL=index.d.ts.map
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.findReplacementTx = exports.getTransactionByNonce = exports.TxValidationError = exports.SearchError = void 0;
const web3_1 = __importDefault(require("web3"));
const ethers_1 = require("ethers");
class SearchError extends Error {

@@ -22,5 +19,3 @@ }

async function getTransactionByNonce(provider, startSearch, from, nonce) {
// If available connect to rpcUrl to avoid issues with WalletConnectProvider receipt.status
const web3 = new web3_1.default(provider.rpcUrl ? provider.rpcUrl : provider);
const currentNonce = await web3.eth.getTransactionCount(from, 'latest');
const currentNonce = await provider.getTransactionCount(from, 'latest');
// Transaction still pending

@@ -31,7 +26,7 @@ if (currentNonce <= nonce)

let txBlock;
let maxBlock = await web3.eth.getBlockNumber(); // latest: chain head
let maxBlock = await provider.getBlockNumber(); // latest: chain head
let minBlock = startSearch;
while (minBlock <= maxBlock) {
const middleBlock = Math.floor((minBlock + maxBlock) / 2);
const middleNonce = await web3.eth.getTransactionCount(from, middleBlock) - 1;
const middleNonce = await provider.getTransactionCount(from, middleBlock) - 1;
if (middleNonce < nonce) {

@@ -44,3 +39,3 @@ // middleBlock was mined before the tx with broadcasted nonce, so take next block as lower bound

// lower nonce at previous block which would mean that tx.nonce was mined in this middleBlock.
if (await web3.eth.getTransactionCount(from, middleBlock - 1) - 1 < nonce) {
if (await provider.getTransactionCount(from, middleBlock - 1) - 1 < nonce) {
// Confirm the nonce changed by checking the previous block:

@@ -60,3 +55,3 @@ // use previous block nonce `>=` broadcasted nonce in case there are multiple user tx

}
const block = await web3.eth.getBlock(txBlock, true);
const block = await provider.getBlockWithTransactions(txBlock);
const transaction = block.transactions.find(blockTx => blockTx.from.toLowerCase() === from.toLowerCase() && blockTx.nonce === nonce);

@@ -88,5 +83,3 @@ if (!transaction) {

return null;
// If available connect to rpcUrl to avoid issues with WalletConnectProvider receipt.status
const web3 = new web3_1.default(provider.rpcUrl ? provider.rpcUrl : provider);
if (transaction.input === '0x' && transaction.from === transaction.to && transaction.value === '0') {
if (transaction.data === '0x' && transaction.from === transaction.to && transaction.value.isZero()) {
const error = 'Transaction canceled.';

@@ -102,5 +95,5 @@ throw new TxValidationError(error);

if (tx.data) {
if (transaction.input !== tx.data) {
if (transaction.data !== tx.data) {
const error = `Failed to validate transaction data.
Expected ${tx.data}, got ${transaction.input}.
Expected ${tx.data}, got ${transaction.data}.
Transaction was dropped and replaced by '${transaction.hash}'`;

@@ -111,5 +104,5 @@ throw new TxValidationError(error);

if (tx.value) {
if (transaction.value !== tx.value) {
if (transaction.value.toString() !== tx.value) {
const error = `Failed to validate transaction value.
Expected ${tx.value}, got ${transaction.value}.
Expected ${tx.value}, got ${transaction.value.toString()}.
Transaction was dropped and replaced by '${transaction.hash}'`;

@@ -120,10 +113,7 @@ throw new TxValidationError(error);

if (event) {
const tokenContract = new web3.eth.Contract(JSON.parse(event.abi), event.address);
const eventOptions = {
fromBlock: transaction.blockNumber,
toBlock: transaction.blockNumber
};
const events = await tokenContract.getPastEvents(event.name, eventOptions);
const tokenContract = new ethers_1.ethers.Contract(event.address, event.abi, provider);
const filter = tokenContract.filters[event.name]();
const events = await tokenContract.queryFilter(filter, transaction.blockNumber, transaction.blockNumber);
const foundEvent = events.find(e => e.transactionHash === transaction.hash);
if (!foundEvent || !event.validate(foundEvent)) {
if (!foundEvent || !event.validate({ returnValues: foundEvent.args })) {
const error = `Failed to validate event.

@@ -130,0 +120,0 @@ Transaction was dropped and replaced by '${transaction.hash}'`;

{
"name": "find-replacement-tx",
"version": "1.1.0",
"version": "1.2.0-0",
"license": "(MIT AND Apache-2.0)",

@@ -19,8 +19,6 @@ "main": "dist/index.js",

"@yarnpkg/pnpify": "^2.4.0",
"typescript": "4.1.5",
"web3-core": "^1.3.6",
"web3-eth-contract": "^1.3.6"
"typescript": "4.1.5"
},
"dependencies": {
"web3": "^1.3.4"
"ethers": "^5.4.0"
},

@@ -27,0 +25,0 @@ "browserslist": [

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc