modify env file and remove logs

This commit is contained in:
koseoyoung 2020-10-13 00:31:19 +09:00
parent 72f666a166
commit 3af417484c
2 changed files with 24 additions and 19 deletions

View file

@ -13,3 +13,6 @@ ERC20_TOKEN=
#ERC20_TOKEN=0xf3e0d7bf58c5d455d31ef1c2d5375904df525105 #ERC20_TOKEN=0xf3e0d7bf58c5d455d31ef1c2d5375904df525105
#TOKEN_AMOUNT=1000000 #TOKEN_AMOUNT=1000000
# the block when 0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1 has some USDT is 13147586 # the block when 0x90F8bf6A479f320ead074411a4B0e7944Ea8c9C1 has some USDT is 13147586
# IOTX in TESTNET
IOTX_AMOUNT=1000000000000000000

View file

@ -16,10 +16,10 @@ const websnarkUtils = require('websnark/src/utils')
const { sha3, toWei, fromWei, toBN, BN, hexToBytes } = require('web3-utils') const { sha3, toWei, fromWei, toBN, BN, hexToBytes } = require('web3-utils')
const config = require('./config') const config = require('./config')
const program = require('commander') const program = require('commander')
const linker = require('solc/linker'); const linker = require('solc/linker')
const Antenna = require('iotex-antenna') const Antenna = require('iotex-antenna')
const Address = require('iotex-antenna/lib/crypto/address') const Address = require('iotex-antenna/lib/crypto/address')
const Web3EthAbi = require('web3-eth-abi'); const Web3EthAbi = require('web3-eth-abi')
let circuit, proving_key, groth16, senderAccount, netId, tornadoAddress, deloyedBlkHeight, currency, amount let circuit, proving_key, groth16, senderAccount, netId, tornadoAddress, deloyedBlkHeight, currency, amount
let MERKLE_TREE_HEIGHT, IOTX_AMOUNT let MERKLE_TREE_HEIGHT, IOTX_AMOUNT
@ -62,7 +62,7 @@ function createDeposit({ nullifier, secret }) {
*/ */
async function deposit() { async function deposit() {
const deposit = createDeposit({ nullifier: rbigint(31), secret: rbigint(31) }) const deposit = createDeposit({ nullifier: rbigint(31), secret: rbigint(31) })
console.log("commitment:", toHex(deposit.commitment)); console.log("commitment:", toHex(deposit.commitment))
console.log('Submitting deposit transaction') console.log('Submitting deposit transaction')
actionHash = await IOTXTornado.methods.deposit(toHex(deposit.commitment), { actionHash = await IOTXTornado.methods.deposit(toHex(deposit.commitment), {
account: senderAccount, account: senderAccount,
@ -143,14 +143,14 @@ async function generateMerkleProof(deposit) {
contractAddress: tornadoAddress, contractAddress: tornadoAddress,
abi: ContractJson.abi, abi: ContractJson.abi,
method: "isKnownRoot", method: "isKnownRoot",
}, toHex(root)); }, toHex(root))
const isSpent = await Provider.readContractByMethod({ const isSpent = await Provider.readContractByMethod({
from: senderAccount.address, from: senderAccount.address,
contractAddress: tornadoAddress, contractAddress: tornadoAddress,
abi: ContractJson.abi, abi: ContractJson.abi,
method: "isSpent", method: "isSpent",
}, toHex(deposit.nullifierHash)); }, toHex(deposit.nullifierHash))
assert(isValidRoot === true, 'Merkle tree is corrupted') assert(isValidRoot === true, 'Merkle tree is corrupted')
assert(isSpent === false, 'The note is already spent') assert(isSpent === false, 'The note is already spent')
@ -214,11 +214,14 @@ async function generateProof({ deposit, recipient, relayerAddress = 0, fee = 0,
return { args } return { args }
} }
/** /**
* Do an ETH withdrawal * Do an ETH withdrawal
* @param noteString Note to withdraw * @param noteString Note to withdraw
* @param recipient Recipient address * @param recipient Recipient address
*/ */
/*
async function withdraw({ deposit, currency, amount, recipient, relayerURL, refund = '0' }) { async function withdraw({ deposit, currency, amount, recipient, relayerURL, refund = '0' }) {
if (currency === 'eth' && refund !== '0') { if (currency === 'eth' && refund !== '0') {
throw new Error('The ETH purchase is supposted to be 0 for ETH withdrawals') throw new Error('The ETH purchase is supposted to be 0 for ETH withdrawals')
@ -389,11 +392,11 @@ function calculateFee({ gasPrices, currency, amount, refund, ethPrices, relayerS
return desiredFee return desiredFee
} }
*/
function sleep(ms) { function sleep(ms) {
return new Promise((resolve) => { return new Promise((resolve) => {
setTimeout(resolve, ms); setTimeout(resolve, ms)
}); })
} }
/** /**
@ -426,7 +429,7 @@ async function init() {
ContractJson = require('./build/contracts/ETHTornado.json') ContractJson = require('./build/contracts/ETHTornado.json')
circuit = require('./build/circuits/withdraw.json') circuit = require('./build/circuits/withdraw.json')
proving_key = fs.readFileSync('build/circuits/withdraw_proving_key.bin').buffer proving_key = fs.readFileSync('build/circuits/withdraw_proving_key.bin').buffer
Provider = new Antenna.default.modules.Iotx("http://api.testnet.iotex.one:80"); Provider = new Antenna.default.modules.Iotx("http://api.testnet.iotex.one:80")
IOTXTornado = new Antenna.default.modules.Contract ( IOTXTornado = new Antenna.default.modules.Contract (
ContractJson.abi, ContractJson.abi,
tornadoAddress, tornadoAddress,
@ -441,7 +444,7 @@ async function init() {
IOTX_AMOUNT = process.env.IOTX_AMOUNT || 1000000000000000000 IOTX_AMOUNT = process.env.IOTX_AMOUNT || 1000000000000000000
senderAccount = Provider.accounts.privateKeyToAccount( senderAccount = Provider.accounts.privateKeyToAccount(
"51b7ef3cb87f73d8c5b65858ecfac791239c33103c2968dd5ec6716e62ae8ea1" "51b7ef3cb87f73d8c5b65858ecfac791239c33103c2968dd5ec6716e62ae8ea1"
); )
} }
async function deploy() { async function deploy() {
@ -457,7 +460,7 @@ async function deploy() {
from: senderAccount.address, from: senderAccount.address,
abi: ContractJson.abi, abi: ContractJson.abi,
data: Buffer.from(byteCode.substring(2, byteCode.length), "hex"), data: Buffer.from(byteCode.substring(2, byteCode.length), "hex"),
}, verifierContractAddress , IOTX_AMOUNT, MERKLE_TREE_HEIGHT, senderAccount.address); }, verifierContractAddress , IOTX_AMOUNT, MERKLE_TREE_HEIGHT, senderAccount.address)
console.log("action hash:", actionHash) console.log("action hash:", actionHash)
} }
@ -467,19 +470,19 @@ async function main() {
.option('-R, --relayer <URL>', 'Withdraw via relayer') .option('-R, --relayer <URL>', 'Withdraw via relayer')
program program
.command('deploy') .command('deploy')
.description('Submit a deposit of specified currency and amount from default eth account and return the resulting note. The currency is one of (ETH|DAI|cDAI|USDC|cUSDC|USDT). The amount depends on currency, see config.js file or visit https://tornado.cash.') .description('deploy ETHTornado contract by given hasher and verfier contract')
.action(async () => { .action(async () => {
await init(); await init()
await deploy(); await deploy()
process.exit(0) process.exit(0)
}) })
program program
.command('test') .command('test')
.description('dd') .description('test for submitting deposit and withdraw')
.action(async () => { .action(async () => {
await init(); await init()
noteString = await deposit(); noteString = await deposit()
await sleep(15000); await sleep(15000)
let parsedNote = parseNote(noteString) let parsedNote = parseNote(noteString)
recipient = '0x53FBC28FAF9a52dFe5F591948A23189E900381B5' recipient = '0x53FBC28FAF9a52dFe5F591948A23189E900381B5'
@ -491,7 +494,6 @@ async function main() {
account: senderAccount, account: senderAccount,
gasLimit: "1000000", gasLimit: "1000000",
gasPrice: "1000000000000", gasPrice: "1000000000000",
amount: "0",
}) })
console.log(actionHash) console.log(actionHash)
console.log("done") console.log("done")