Merge pull request #1343 from chaotixkilla/fix-sweeping-negative-amounts
Throw error when attempting to sweep negative amounts
This commit is contained in:
commit
597448db55
4 changed files with 12 additions and 7 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -159,6 +159,10 @@ function generateErc20Tx (_toAddress, wallet, amount, includesFee, cryptoCode) {
|
|||
const maxPriorityFeePerGas = new BN(web3.utils.toWei('2.5', 'gwei')) // web3 default value
|
||||
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 (Transaction ID: ${txId} | Value provided: ${toSend.toNumber()}). This is probably caused due to the estimated fee being higher than the address' balance.`)
|
||||
}
|
||||
|
||||
const rawTx = {
|
||||
chainId: 1,
|
||||
nonce: txCount,
|
||||
|
|
@ -180,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()
|
||||
|
|
@ -247,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()
|
||||
|
||||
|
|
@ -255,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))
|
||||
})
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue