mirror of
https://github.com/tornadocash/tornado-core.git
synced 2025-04-28 10:56:29 -04:00
cli compiance done
This commit is contained in:
parent
4e120f26cb
commit
c7d912c2e7
141
cli.js
141
cli.js
@ -300,6 +300,51 @@ function fromDecimals({ amount, decimals }) {
|
|||||||
return new BN(wei.toString(10), 10)
|
return new BN(wei.toString(10), 10)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toDecimals(value, decimals, fixed) {
|
||||||
|
const zero = new BN(0)
|
||||||
|
const negative1 = new BN(-1)
|
||||||
|
decimals = decimals || 18
|
||||||
|
fixed = fixed || 7
|
||||||
|
|
||||||
|
value = new BN(value)
|
||||||
|
const negative = value.lt(zero)
|
||||||
|
const base = new BN('10').pow(new BN(decimals))
|
||||||
|
const baseLength = base.toString(10).length - 1 || 1
|
||||||
|
|
||||||
|
if (negative) {
|
||||||
|
value = value.mul(negative1)
|
||||||
|
}
|
||||||
|
|
||||||
|
let fraction = value.mod(base).toString(10)
|
||||||
|
while (fraction.length < baseLength) {
|
||||||
|
fraction = `0${fraction}`
|
||||||
|
}
|
||||||
|
fraction = fraction.match(/^([0-9]*[1-9]|0)(0*)/)[1]
|
||||||
|
|
||||||
|
const whole = value.div(base).toString(10)
|
||||||
|
value = `${whole}${fraction === '0' ? '' : `.${fraction}`}`
|
||||||
|
|
||||||
|
if (negative) {
|
||||||
|
value = `-${value}`
|
||||||
|
}
|
||||||
|
|
||||||
|
if (fixed) {
|
||||||
|
value = value.slice(0, fixed)
|
||||||
|
}
|
||||||
|
|
||||||
|
return value
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCurrentNetworkName() {
|
||||||
|
switch(netId) {
|
||||||
|
case 1:
|
||||||
|
return ''
|
||||||
|
case 42:
|
||||||
|
return 'kovan.'
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
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 feePercent = toBN(fromDecimals({ amount, decimals })).mul(toBN(relayerServiceFee * 10)).div(toBN('1000'))
|
||||||
const expense = toBN(toWei(gasPrices.fast.toString(), 'gwei')).mul(toBN(5e5))
|
const expense = toBN(toWei(gasPrices.fast.toString(), 'gwei')).mul(toBN(5e5))
|
||||||
@ -389,56 +434,35 @@ async function loadDepositData({ deposit }) {
|
|||||||
}
|
}
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
// async loadWithdrawalData({ getters, commit, rootGetters }, { withdrawNote }) {
|
async function loadWithdrawalData({ amount, currency, deposit }) {
|
||||||
// try {
|
try {
|
||||||
// const { currency, amount, netId, nullifierHex } = getters.parseNote(withdrawNote)
|
const events = await await tornado.getPastEvents('Withdrawal', {
|
||||||
// const contractInstance = getters.mixerContract({ currency, amount, netId })
|
fromBlock: 0,
|
||||||
// let cached = []
|
toBlock: 'latest'
|
||||||
// let fromBlock = 0
|
})
|
||||||
// if (Number(netId) === 1 && currency === 'eth') {
|
|
||||||
// if (Number(amount) === 0.1) {
|
|
||||||
// cached = require('./events/withdraw_eth_01.json')
|
|
||||||
// fromBlock = 10000030
|
|
||||||
// }
|
|
||||||
// if (Number(amount) === 1) {
|
|
||||||
// cached = require('./events/withdraw_eth_1.json')
|
|
||||||
// fromBlock = 9999498
|
|
||||||
// }
|
|
||||||
// if (Number(amount) === 10) {
|
|
||||||
// cached = require('./events/withdraw_eth_10.json')
|
|
||||||
// fromBlock = 9997251
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// let events = await contractInstance.getPastEvents('Withdrawal', {
|
const withdrawEvent = events.filter((event) => {
|
||||||
// fromBlock,
|
return event.returnValues.nullifierHash === deposit.nullifierHex
|
||||||
// toBlock: 'latest'
|
})[0]
|
||||||
// })
|
|
||||||
|
|
||||||
// events = events.concat(cached)
|
const fee = withdrawEvent.returnValues.fee
|
||||||
|
const decimals = config.deployments[`netId${netId}`][currency].decimals
|
||||||
// const withdrawEvent = events.filter((event) => {
|
const withdrawalAmount = toBN(fromDecimals({ amount, decimals })).sub(
|
||||||
// return event.returnValues.nullifierHash === nullifierHex
|
toBN(fee)
|
||||||
// })[0]
|
)
|
||||||
|
const { timestamp } = await web3.eth.getBlock(withdrawEvent.blockHash)
|
||||||
// const fee = withdrawEvent.returnValues.fee
|
return {
|
||||||
// const decimals = rootGetters['metamask/networkConfig'].tokens[currency].decimals
|
amount: toDecimals(withdrawalAmount, decimals, 9),
|
||||||
// const withdrawalAmount = toBN(rootGetters['token/fromDecimals'](amount.toString())).sub(
|
txHash: withdrawEvent.transactionHash,
|
||||||
// toBN(fee)
|
to: withdrawEvent.returnValues.to,
|
||||||
// )
|
timestamp,
|
||||||
|
nullifier: deposit.nullifierHex,
|
||||||
// return {
|
fee: toDecimals(fee, decimals, 9)
|
||||||
// amount: rootGetters['token/toDecimals'](withdrawalAmount, decimals, 9),
|
}
|
||||||
// txHash: withdrawEvent.transactionHash,
|
} catch (e) {
|
||||||
// to: withdrawEvent.returnValues.to,
|
console.error('loadWithdrawalData', e)
|
||||||
// blockHash: withdrawEvent.blockHash,
|
}
|
||||||
// fee: rootGetters['token/toDecimals'](fee, decimals, 9)
|
}
|
||||||
// }
|
|
||||||
// } catch (e) {
|
|
||||||
// console.error('e', e)
|
|
||||||
// commit('SAVE_ERROR', e.message)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Init web3, contracts, and snark
|
* Init web3, contracts, and snark
|
||||||
@ -558,13 +582,26 @@ async function main() {
|
|||||||
const { currency, amount, netId, deposit } = parseNote(noteString)
|
const { currency, amount, netId, deposit } = parseNote(noteString)
|
||||||
await init({ rpc: program.rpc, noteNetId: netId, currency, amount })
|
await init({ rpc: program.rpc, noteNetId: netId, currency, amount })
|
||||||
const depositInfo = await loadDepositData({ deposit })
|
const depositInfo = await loadDepositData({ deposit })
|
||||||
console.log('Date', new Date(depositInfo.timestamp * 1000))
|
const depositDate = new Date(depositInfo.timestamp * 1000)
|
||||||
console.log('From', `https://kovan.etherescan.io/tx/${depositInfo.from}`)
|
console.log('\n=============Deposit=================')
|
||||||
console.log('Transaction', `https://kovan.etherescan.io/tx/${depositInfo.txHash}`)
|
console.log('Deposit :', amount, currency)
|
||||||
console.log('Commitment', depositInfo.commitment)
|
console.log('Date :', depositDate.toLocaleDateString(), depositDate.toLocaleTimeString())
|
||||||
|
console.log('From :', `https://${getCurrentNetworkName()}etherscan.io/address/${depositInfo.from}`)
|
||||||
|
console.log('Transaction :', `https://${getCurrentNetworkName()}etherscan.io/tx/${depositInfo.txHash}`)
|
||||||
|
console.log('Commitment :', depositInfo.commitment)
|
||||||
if (deposit.isSpent) {
|
if (deposit.isSpent) {
|
||||||
console.log('The note was not spent')
|
console.log('The note was not spent')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const withdrawInfo = await loadWithdrawalData({ amount, currency, deposit })
|
||||||
|
const withdrawalDate = new Date(withdrawInfo.timestamp * 1000)
|
||||||
|
console.log('\n=============Withdrawal==============')
|
||||||
|
console.log('Withdrawal :', withdrawInfo.amount, currency)
|
||||||
|
console.log('Relayer Fee :', withdrawInfo.fee, currency)
|
||||||
|
console.log('Date :', withdrawalDate.toLocaleDateString(), withdrawalDate.toLocaleTimeString())
|
||||||
|
console.log('To :', `https://${getCurrentNetworkName()}etherscan.io/address/${withdrawInfo.to}`)
|
||||||
|
console.log('Transaction :', `https://${getCurrentNetworkName()}etherscan.io/tx/${withdrawInfo.txHash}`)
|
||||||
|
console.log('Nullifier :', withdrawInfo.nullifier)
|
||||||
})
|
})
|
||||||
program
|
program
|
||||||
.command('test')
|
.command('test')
|
||||||
|
Loading…
x
Reference in New Issue
Block a user