Fix send command

This commit is contained in:
Ayanami 2022-01-26 22:24:58 +09:00
parent 00f68385e3
commit 8b63de6392
No known key found for this signature in database
GPG Key ID: 0CABDF03077D92E4
1 changed files with 16 additions and 9 deletions

25
cli.js
View File

@ -349,6 +349,11 @@ async function withdraw({ deposit, currency, amount, recipient, relayerURL, torP
console.log('Submitting withdraw transaction') console.log('Submitting withdraw transaction')
await generateTransaction(contractAddress, await tornado.methods.withdraw(tornadoInstance, proof, ...args).encodeABI()) await generateTransaction(contractAddress, await tornado.methods.withdraw(tornadoInstance, proof, ...args).encodeABI())
} }
if (currency === netSymbol.toLowerCase()) {
await printETHBalance({ address: recipient, name: 'Recipient', symbol: currency.toUpperCase() })
} else {
await printERC20Balance({ address: recipient, name: 'Recipient' })
}
console.log('Done withdrawal from Tornado Cash') console.log('Done withdrawal from Tornado Cash')
} }
@ -379,23 +384,25 @@ async function send({ address, amount, tokenAddress }) {
console.error("You have 0 balance, can't send") console.error("You have 0 balance, can't send")
process.exit(1); process.exit(1);
} }
if (!amount) { if (amount) {
toSend = amount * Math.pow(10, 18)
if (balance < toSend) {
console.error("You have",web3.utils.fromWei(toHex(balance)),netSymbol+", you can't send more than you have.")
process.exit(1);
}
} else {
console.log('Amount not defined, sending all available amounts') console.log('Amount not defined, sending all available amounts')
const gasPrice = await fetchGasPrice() const gasPrice = await fetchGasPrice()
const gasLimit = 21000; const gasLimit = 21000;
if (netId == 1 || netId == 5) { if (netId == 1 || netId == 5) {
const priorityFee = await gasPrices(3) const priorityFee = await gasPrices(3)
amount = (balance - (gasLimit * (parseInt(gasPrice) + parseInt(priorityFee)))) toSend = (balance - (gasLimit * (parseInt(gasPrice) + parseInt(priorityFee))))
} else { } else {
amount = (balance - (gasLimit * parseInt(gasPrice))) toSend = (balance - (gasLimit * parseInt(gasPrice)))
} }
} }
if (balance < amount) { await generateTransaction(address, null, toSend)
console.error("You have",web3.utils.fromWei(toHex(balance)),netSymbol,", you can't send more than you have.") console.log('Sent',web3.utils.fromWei(toHex(toSend)),netSymbol,'to',address);
process.exit(1);
}
await generateTransaction(address, null, amount)
console.log('Sent',web3.utils.fromWei(toHex(amount)),netSymbol,'to',address);
} }
} }