diff --git a/cli.js b/cli.js index 546c2f3..af54652 100755 --- a/cli.js +++ b/cli.js @@ -41,17 +41,20 @@ function toHex(number, length = 32) { } /** Display ETH account balance */ -async function printETHBalance({ address, name, symbol }) { - console.log(`${name} balance is`, web3.utils.fromWei(await web3.eth.getBalance(address)),`${symbol}`) +async function printETHBalance({ address, name }) { + const checkBalance = await web3.eth.getBalance(address) + console.log(`${name} balance is`, web3.utils.fromWei(checkBalance),`${netSymbol}`) } /** Display ERC20 account balance */ async function printERC20Balance({ address, name, tokenAddress }) { const erc20ContractJson = require('./build/contracts/ERC20Mock.json') erc20 = tokenAddress ? new web3.eth.Contract(erc20ContractJson.abi, tokenAddress) : erc20 - balance = await erc20.methods.balanceOf(address).call() - decimals = await erc20.methods.decimals().call() - console.log(`${name}`,(await erc20.methods.name().call()),`Token Balance is`,toDecimals(balance, decimals, (balance.length + decimals)).toString().replace(/\B(? { fetchedEvents = fetchedEvents.concat(r); console.log("Fetched",amount,currency.toUpperCase(),type,"events to block:", i) }, err => { console.error(i + " failed fetching",type,"events from node", err); process.exit(1); }).catch(console.log); + }).then(r => { fetchedEvents = fetchedEvents.concat(r); console.log("Fetched",amount,currency.toUpperCase(),type,"events to block:", i+chunks-1) }, err => { console.error(i + " failed fetching",type,"events from node", err); process.exit(1); }).catch(console.log); } async function mapDepositEvents() { @@ -943,6 +953,7 @@ async function init({ rpc, noteNetId, currency = 'dai', amount = '100', torPort, groth16 = await buildGroth16() netId = await web3.eth.net.getId() netName = getCurrentNetworkName() + netSymbol = getCurrentNetworkSymbol() if (noteNetId && Number(noteNetId) !== netId) { throw new Error('This note is for a different network. Specify the --rpc option explicitly') } @@ -951,15 +962,13 @@ async function init({ rpc, noteNetId, currency = 'dai', amount = '100', torPort, } if (isLocalRPC) { - tornadoAddress = currency === 'eth' ? contractJson.networks[netId].address : erc20tornadoJson.networks[netId].address - tokenAddress = currency !== 'eth' ? erc20ContractJson.networks[netId].address : null - netSymbol = getCurrentNetworkSymbol() + tornadoAddress = currency === netSymbol.toLowerCase() ? contractJson.networks[netId].address : erc20tornadoJson.networks[netId].address + tokenAddress = currency !== netSymbol.toLowerCase() ? erc20ContractJson.networks[netId].address : null deployedBlockNumber = 0 senderAccount = (await web3.eth.getAccounts())[0] } else { try { if (balanceCheck) { - netSymbol = getCurrentNetworkSymbol() currency = netSymbol.toLowerCase() amount = Object.keys(config.deployments[`netId${netId}`][currency].instanceAddress)[0] } @@ -970,17 +979,16 @@ async function init({ rpc, noteNetId, currency = 'dai', amount = '100', torPort, if (!tornadoAddress) { throw new Error() } - tokenAddress = config.deployments[`netId${netId}`][currency].tokenAddress + tokenAddress = currency !== netSymbol.toLowerCase() ? config.deployments[`netId${netId}`][currency].tokenAddress : null } catch (e) { console.error('There is no such tornado instance, check the currency and amount you provide', e) process.exit(1) } } - netSymbol = getCurrentNetworkSymbol() tornado = new web3.eth.Contract(contractJson, tornadoAddress) tornadoContract = new web3.eth.Contract(instanceJson, tornadoInstance) contractAddress = tornadoAddress - erc20 = currency !== 'eth' ? new web3.eth.Contract(erc20ContractJson.abi, tokenAddress) : {} + erc20 = currency !== netSymbol.toLowerCase() ? new web3.eth.Contract(erc20ContractJson.abi, tokenAddress) : {} erc20Address = tokenAddress } @@ -1041,7 +1049,7 @@ async function main() { console.log("Using address",senderAccount,"from private key") address = senderAccount; } - await printETHBalance({ address, name: 'Account', symbol: netSymbol }) + await printETHBalance({ address, name: 'Account' }) if (tokenAddress) { await printERC20Balance({ address, name: 'Account', tokenAddress }) }