From 710054547ab09d35112bc7a122faacdf869eeebc Mon Sep 17 00:00:00 2001 From: Ayanami Date: Mon, 24 Jan 2022 20:39:40 +0900 Subject: [PATCH 1/2] Fix bug & Show remote ip from console --- cli.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/cli.js b/cli.js index 666da53..4740b25 100755 --- a/cli.js +++ b/cli.js @@ -894,11 +894,13 @@ async function init({ rpc, noteNetId, currency = 'dai', amount = '100', torPort, TOKEN_AMOUNT = 1e19 senderAccount = (await web3.eth.getAccounts())[0] } else { + let ipOptions = {}; if (torPort) { console.log("Using tor network") web3Options = { agent: { https: new SocksProxyAgent('socks5h://127.0.0.1:'+torPort) }, timeout: 60000 } // Use forked web3-providers-http from local file to modify user-agent header value which improves privacy. web3 = new Web3(new Web3HttpProvider(rpc, web3Options), null, { transactionConfirmationBlocks: 1 }) + ipOptions = { httpsAgent: new SocksProxyAgent('socks5h://127.0.0.1:'+torPort), headers: { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; rv:91.0) Gecko/20100101 Firefox/91.0' } } } else if (rpc.includes("ipc")) { console.log("Using ipc connection") web3 = new Web3(new Web3.providers.IpcProvider(rpc, net), null, { transactionConfirmationBlocks: 1 }) @@ -910,6 +912,9 @@ async function init({ rpc, noteNetId, currency = 'dai', amount = '100', torPort, console.log("Connecting to remote node") web3 = new Web3(rpc, null, { transactionConfirmationBlocks: 1 }) } + const fetchRemoteIP = await axios.get('https://ip.tornado.cash', ipOptions) + const { country, ip } = fetchRemoteIP.data + console.log('Your remote IP address is',ip,'from',country+'.'); contractJson = require('./build/contracts/TornadoProxy.abi.json') instanceJson = require('./build/contracts/Instance.abi.json') circuit = require('./build/circuits/tornado.json') @@ -918,10 +923,12 @@ async function init({ rpc, noteNetId, currency = 'dai', amount = '100', torPort, ETH_AMOUNT = process.env.ETH_AMOUNT TOKEN_AMOUNT = process.env.TOKEN_AMOUNT const privKey = process.env.PRIVATE_KEY - if (privKey.includes("0x")) { - PRIVATE_KEY = process.env.PRIVATE_KEY.substring(2) - } else { - PRIVATE_KEY = process.env.PRIVATE_KEY + if (privKey) { + if (privKey.includes("0x")) { + PRIVATE_KEY = process.env.PRIVATE_KEY.substring(2) + } else { + PRIVATE_KEY = process.env.PRIVATE_KEY + } } if (PRIVATE_KEY) { const account = web3.eth.accounts.privateKeyToAccount('0x' + PRIVATE_KEY) From bceb74b9b3adecc6aeb7476ea35f8946fdc811de Mon Sep 17 00:00:00 2001 From: Ayanami Date: Mon, 24 Jan 2022 21:50:58 +0900 Subject: [PATCH 2/2] Read address from private key for querying balance --- cli.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/cli.js b/cli.js index 4740b25..546c2f3 100755 --- a/cli.js +++ b/cli.js @@ -1033,10 +1033,14 @@ async function main() { }) }) program - .command('balance
[token_address]') + .command('balance [address] [token_address]') .description('Check ETH and ERC20 balance') .action(async (address, tokenAddress) => { await init({ rpc: program.rpc, torPort: program.tor, balanceCheck: true }) + if (!address && senderAccount) { + console.log("Using address",senderAccount,"from private key") + address = senderAccount; + } await printETHBalance({ address, name: 'Account', symbol: netSymbol }) if (tokenAddress) { await printERC20Balance({ address, name: 'Account', tokenAddress })