From 3daf0ac86544327471fbdff524301a0b75c2b242 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9rgio=20Salgado?= Date: Tue, 16 Aug 2022 15:47:06 +0100 Subject: [PATCH] fix: add transaction ID to new sweep error logs --- lib/plugins.js | 3 ++- lib/plugins/wallet/geth/base.js | 8 ++++---- lib/plugins/wallet/pazuz-wallet/pazuz-wallet.js | 2 +- lib/wallet.js | 4 ++-- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/lib/plugins.js b/lib/plugins.js index b311b978..de194a36 100644 --- a/lib/plugins.js +++ b/lib/plugins.js @@ -789,9 +789,10 @@ function plugins (settings, deviceId) { } function sweepHdRow (row) { + const txId = row.id const cryptoCode = row.crypto_code - return wallet.sweep(settings, cryptoCode, row.hd_index) + return wallet.sweep(settings, txId, cryptoCode, row.hd_index) .then(txHash => { if (txHash) { logger.debug('[%s] Swept address with tx: %s', cryptoCode, txHash) diff --git a/lib/plugins/wallet/geth/base.js b/lib/plugins/wallet/geth/base.js index 9d4bb660..05f31805 100644 --- a/lib/plugins/wallet/geth/base.js +++ b/lib/plugins/wallet/geth/base.js @@ -160,7 +160,7 @@ function generateErc20Tx (_toAddress, wallet, amount, includesFee, cryptoCode) { const maxFeePerGas = new BN(2).times(baseFeePerGas).plus(maxPriorityFeePerGas) if (includesFee && (toSend.isNegative() || toSend.isZero())) { - throw new Error(`Trying to send a nil or negative amount. This is probably caused due to the estimated fee being higher than the address' balance. Value provided: ${toSend.toNumber()}`) + throw new Error(`Trying to send a nil or negative amount (Transaction ID: ${txId} | Value provided: ${toSend.toNumber()}). This is probably caused due to the estimated fee being higher than the address' balance.`) } const rawTx = { @@ -184,7 +184,7 @@ function generateErc20Tx (_toAddress, wallet, amount, includesFee, cryptoCode) { }) } -function generateTx (_toAddress, wallet, amount, includesFee, cryptoCode) { +function generateTx (_toAddress, wallet, amount, includesFee, cryptoCode, txId) { const fromAddress = '0x' + wallet.getAddress().toString('hex') const toAddress = _toAddress.toLowerCase() @@ -251,7 +251,7 @@ function defaultAddress (account) { return defaultWallet(account).getChecksumAddressString() } -function sweep (account, cryptoCode, hdIndex, settings, operatorId) { +function sweep (account, txId, cryptoCode, hdIndex, settings, operatorId) { const wallet = paymentHdNode(account).deriveChild(hdIndex).getWallet() const fromAddress = wallet.getChecksumAddressString() @@ -259,7 +259,7 @@ function sweep (account, cryptoCode, hdIndex, settings, operatorId) { .then(r => { if (r.eq(0)) return - return generateTx(defaultAddress(account), wallet, r, true, cryptoCode) + return generateTx(defaultAddress(account), wallet, r, true, cryptoCode, txId) .then(signedTx => pify(web3.eth.sendSignedTransaction)(signedTx)) }) ) diff --git a/lib/plugins/wallet/pazuz-wallet/pazuz-wallet.js b/lib/plugins/wallet/pazuz-wallet/pazuz-wallet.js index 9ed8c3b7..6fe38387 100644 --- a/lib/plugins/wallet/pazuz-wallet/pazuz-wallet.js +++ b/lib/plugins/wallet/pazuz-wallet/pazuz-wallet.js @@ -84,7 +84,7 @@ function newFunding (account, cryptoCode, settings, operatorId) { throw new E.NotImplementedError() } -function sweep (account, cryptoCode, hdIndex, settings, operatorId) { +function sweep (account, txId, cryptoCode, hdIndex, settings, operatorId) { throw new E.NotImplementedError() } diff --git a/lib/wallet.js b/lib/wallet.js index 9c6023d7..0f1ce2f2 100644 --- a/lib/wallet.js +++ b/lib/wallet.js @@ -206,9 +206,9 @@ function getStatus (settings, tx, machineId) { }) } -function sweep (settings, cryptoCode, hdIndex) { +function sweep (settings, txId, cryptoCode, hdIndex) { return fetchWallet(settings, cryptoCode) - .then(r => r.wallet.sweep(r.account, cryptoCode, hdIndex, settings, r.operatorId)) + .then(r => r.wallet.sweep(r.account, txId, cryptoCode, hdIndex, settings, r.operatorId)) } function isHd (settings, tx) {