mirror of
https://github.com/tornadocash/tornado-core.git
synced 2025-04-29 03:16:26 -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 */
|
/** Whether we are in a browser or node.js */
|
||||||
const inBrowser = (typeof window !== 'undefined')
|
const inBrowser = (typeof window !== 'undefined')
|
||||||
let isLocalRPC = false
|
let isLocalRPC = false
|
||||||
const networks = { '1': 'mainnet', '42': 'kovan' }
|
|
||||||
|
|
||||||
/** Generate random number of specified byte length */
|
/** Generate random number of specified byte length */
|
||||||
const rbigint = nbytes => snarkjs.bigInt.leBuff2int(crypto.randomBytes(nbytes))
|
const rbigint = nbytes => snarkjs.bigInt.leBuff2int(crypto.randomBytes(nbytes))
|
||||||
@ -215,7 +214,7 @@ async function withdraw({ deposit, currency, amount, recipient, relayerURL, refu
|
|||||||
try {
|
try {
|
||||||
const relay = await axios.post(relayerURL + '/relay', { contract: tornado._address, proof, args })
|
const relay = await axios.post(relayerURL + '/relay', { contract: tornado._address, proof, args })
|
||||||
if (netId === 1 || netId === 42) {
|
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 {
|
} else {
|
||||||
console.log(`Transaction submitted through the relay. The transaction hash is ${relay.data.txHash}`)
|
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 })
|
await tornado.methods.withdraw(proof, ...args).send({ from: senderAccount, value: refund.toString(), gas: 1e6 })
|
||||||
.on('transactionHash', function (txHash) {
|
.on('transactionHash', function (txHash) {
|
||||||
if (netId === 1 || netId === 42) {
|
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 {
|
} else {
|
||||||
console.log(`The transaction hash is ${txHash}`)
|
console.log(`The transaction hash is ${txHash}`)
|
||||||
}
|
}
|
||||||
@ -346,7 +345,12 @@ function getCurrentNetworkName() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function calculateFee({ gasPrices, currency, amount, refund, ethPrices, relayerServiceFee, decimals }) {
|
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))
|
const expense = toBN(toWei(gasPrices.fast.toString(), 'gwei')).mul(toBN(5e5))
|
||||||
let desiredFee
|
let desiredFee
|
||||||
switch (currency) {
|
switch (currency) {
|
||||||
@ -355,8 +359,7 @@ function calculateFee({ gasPrices, currency, amount, refund, ethPrices, relayerS
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
desiredFee =
|
desiredFee = expense.add(toBN(refund))
|
||||||
expense.add(toBN(refund))
|
|
||||||
.mul(toBN(10 ** decimals))
|
.mul(toBN(10 ** decimals))
|
||||||
.div(toBN(ethPrices[currency]))
|
.div(toBN(ethPrices[currency]))
|
||||||
desiredFee = desiredFee.add(feePercent)
|
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
|
tokenAddress = currency !== 'eth' ? erc20ContractJson.networks[netId].address : null
|
||||||
senderAccount = (await web3.eth.getAccounts())[0]
|
senderAccount = (await web3.eth.getAccounts())[0]
|
||||||
} else {
|
} 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 {
|
try {
|
||||||
tornadoAddress = config.deployments[`netId${netId}`][currency].instanceAddress[amount]
|
tornadoAddress = config.deployments[`netId${netId}`][currency].instanceAddress[amount]
|
||||||
if (!tornadoAddress) {
|
if (!tornadoAddress) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user