mirror of
https://github.com/tornadocash/tornado-core.git
synced 2025-04-28 10:56:29 -04:00
cli updates
This commit is contained in:
parent
6d383235bb
commit
ea1435b115
25
cli.js
25
cli.js
@ -24,7 +24,6 @@ let MERKLE_TREE_HEIGHT, ETH_AMOUNT, TOKEN_AMOUNT, PRIVATE_KEY
|
||||
/** Whether we are in a browser or node.js */
|
||||
const inBrowser = (typeof window !== 'undefined')
|
||||
let isLocalRPC = false
|
||||
const networks = { '1': 'mainnet', '42': 'kovan' }
|
||||
|
||||
/** Generate random number of specified byte length */
|
||||
const rbigint = nbytes => snarkjs.bigInt.leBuff2int(crypto.randomBytes(nbytes))
|
||||
@ -215,7 +214,7 @@ async function withdraw({ deposit, currency, amount, recipient, relayerURL, refu
|
||||
try {
|
||||
const relay = await axios.post(relayerURL + '/relay', { contract: tornado._address, proof, args })
|
||||
if (netId === 1 || netId === 42) {
|
||||
console.log(`Transaction submitted through the relay. View transaction on etherscan https://${networks[netId]}.etherscan.io/tx/${relay.data.txHash}`)
|
||||
console.log(`Transaction submitted through the relay. View transaction on etherscan https://${getCurrentNetworkName()}etherscan.io/tx/${relay.data.txHash}`)
|
||||
} else {
|
||||
console.log(`Transaction submitted through the relay. The transaction hash is ${relay.data.txHash}`)
|
||||
}
|
||||
@ -236,7 +235,7 @@ async function withdraw({ deposit, currency, amount, recipient, relayerURL, refu
|
||||
await tornado.methods.withdraw(proof, ...args).send({ from: senderAccount, value: refund.toString(), gas: 1e6 })
|
||||
.on('transactionHash', function (txHash) {
|
||||
if (netId === 1 || netId === 42) {
|
||||
console.log(`View transaction on etherscan https://${networks[netId]}.etherscan.io/tx/${txHash}`)
|
||||
console.log(`View transaction on etherscan https://${getCurrentNetworkName()}etherscan.io/tx/${txHash}`)
|
||||
} else {
|
||||
console.log(`The transaction hash is ${txHash}`)
|
||||
}
|
||||
@ -346,7 +345,12 @@ function getCurrentNetworkName() {
|
||||
}
|
||||
|
||||
function calculateFee({ gasPrices, currency, amount, refund, ethPrices, relayerServiceFee, decimals }) {
|
||||
const feePercent = toBN(fromDecimals({ amount, decimals })).mul(toBN(relayerServiceFee * 10)).div(toBN('1000'))
|
||||
const decimalsPoint = Math.floor(relayerServiceFee) === Number(relayerServiceFee) ?
|
||||
0 :
|
||||
relayerServiceFee.toString().split('.')[1].length
|
||||
const roundDecimal = 10 ** decimalsPoint
|
||||
const total = toBN(fromDecimals({ amount, decimals }))
|
||||
const feePercent = total.mul(toBN(relayerServiceFee * roundDecimal)).div(toBN(roundDecimal * 100))
|
||||
const expense = toBN(toWei(gasPrices.fast.toString(), 'gwei')).mul(toBN(5e5))
|
||||
let desiredFee
|
||||
switch (currency) {
|
||||
@ -355,8 +359,7 @@ function calculateFee({ gasPrices, currency, amount, refund, ethPrices, relayerS
|
||||
break
|
||||
}
|
||||
default: {
|
||||
desiredFee =
|
||||
expense.add(toBN(refund))
|
||||
desiredFee = expense.add(toBN(refund))
|
||||
.mul(toBN(10 ** decimals))
|
||||
.div(toBN(ethPrices[currency]))
|
||||
desiredFee = desiredFee.add(feePercent)
|
||||
@ -515,16 +518,6 @@ async function init({ rpc, noteNetId, currency = 'dai', amount = '100' }) {
|
||||
tokenAddress = currency !== 'eth' ? erc20ContractJson.networks[netId].address : null
|
||||
senderAccount = (await web3.eth.getAccounts())[0]
|
||||
} else {
|
||||
try {
|
||||
const account = web3.eth.accounts.privateKeyToAccount('0x' + PRIVATE_KEY)
|
||||
web3.eth.accounts.wallet.add('0x' + PRIVATE_KEY)
|
||||
// eslint-disable-next-line require-atomic-updates
|
||||
web3.eth.defaultAccount = account.address
|
||||
senderAccount = account.address
|
||||
} catch(e) {
|
||||
console.error('Please provide PRIVATE_KEY in .env file')
|
||||
process.exit(1)
|
||||
}
|
||||
try {
|
||||
tornadoAddress = config.deployments[`netId${netId}`][currency].instanceAddress[amount]
|
||||
if (!tornadoAddress) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user