mirror of
https://github.com/tornadocash/tornado-core.git
synced 2025-01-27 12:26:58 -05:00
add env vars to cli
This commit is contained in:
parent
890e2fd78b
commit
e47a002bbf
27
cli.js
27
cli.js
@ -4,17 +4,11 @@ const snarkjs = require("snarkjs");
|
|||||||
const bigInt = snarkjs.bigInt;
|
const bigInt = snarkjs.bigInt;
|
||||||
const utils = require("./scripts/utils");
|
const utils = require("./scripts/utils");
|
||||||
const merkleTree = require('./lib/MerkleTree');
|
const merkleTree = require('./lib/MerkleTree');
|
||||||
const Web3 = require('web3')
|
const Web3 = require('web3');
|
||||||
|
require('dotenv').config();
|
||||||
|
const { MERKLE_TREE_HEIGHT, AMOUNT, EMPTY_ELEMENT } = process.env;
|
||||||
|
|
||||||
let web3, mixer;
|
let web3, mixer;
|
||||||
async function init() {
|
|
||||||
web3 = new Web3('http://localhost:8545', null, {transactionConfirmationBlocks: 1});
|
|
||||||
let netId = await web3.eth.net.getId()
|
|
||||||
const json = require('./build/contracts/Mixer.json');
|
|
||||||
mixer = new web3.eth.Contract(json.abi, json.networks[netId].address);
|
|
||||||
const tx = await web3.eth.getTransaction(json.networks[netId].transactionHash);
|
|
||||||
mixer.deployedBlock = tx.blockNumber;
|
|
||||||
}
|
|
||||||
|
|
||||||
function createDeposit(nullifier, secret) {
|
function createDeposit(nullifier, secret) {
|
||||||
let deposit = {nullifier, secret};
|
let deposit = {nullifier, secret};
|
||||||
@ -28,7 +22,7 @@ async function deposit() {
|
|||||||
const deposit = createDeposit(utils.rbigint(31), utils.rbigint(31));
|
const deposit = createDeposit(utils.rbigint(31), utils.rbigint(31));
|
||||||
|
|
||||||
console.log("Submitting deposit transaction");
|
console.log("Submitting deposit transaction");
|
||||||
await mixer.methods.deposit("0x" + deposit.commitment.toString(16)).send({ value: web3.utils.toWei("1", "ether"), from: (await web3.eth.getAccounts())[0], gas:1e6 });
|
await mixer.methods.deposit("0x" + deposit.commitment.toString(16)).send({ value: AMOUNT, from: (await web3.eth.getAccounts())[0], gas:1e6 });
|
||||||
|
|
||||||
const note = "0x" + deposit.preimage.toString('hex');
|
const note = "0x" + deposit.preimage.toString('hex');
|
||||||
console.log("Your note:", note);
|
console.log("Your note:", note);
|
||||||
@ -43,7 +37,7 @@ async function withdraw(note, receiver) {
|
|||||||
console.log("Getting current state from mixer contract");
|
console.log("Getting current state from mixer contract");
|
||||||
const events = await mixer.getPastEvents('LeafAdded', {fromBlock: mixer.deployedBlock, toBlock: 'latest'});
|
const events = await mixer.getPastEvents('LeafAdded', {fromBlock: mixer.deployedBlock, toBlock: 'latest'});
|
||||||
const leaves = events.sort(e => e.returnValues.leaf_index).map(e => e.returnValues.leaf);
|
const leaves = events.sort(e => e.returnValues.leaf_index).map(e => e.returnValues.leaf);
|
||||||
const tree = new merkleTree(16, 0, leaves);
|
const tree = new merkleTree(MERKLE_TREE_HEIGHT, EMPTY_ELEMENT, leaves);
|
||||||
const validRoot = await mixer.methods.isKnownRoot(await tree.root()).call();
|
const validRoot = await mixer.methods.isKnownRoot(await tree.root()).call();
|
||||||
assert(validRoot === true);
|
assert(validRoot === true);
|
||||||
|
|
||||||
@ -72,6 +66,17 @@ async function withdraw(note, receiver) {
|
|||||||
console.log("Done");
|
console.log("Done");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function init() {
|
||||||
|
web3 = new Web3('http://localhost:8545', null, {transactionConfirmationBlocks: 1});
|
||||||
|
let netId = await web3.eth.net.getId();
|
||||||
|
const json = require('./build/contracts/Mixer.json');
|
||||||
|
const tx = await web3.eth.getTransaction(json.networks[netId].transactionHash);
|
||||||
|
mixer = new web3.eth.Contract(json.abi, json.networks[netId].address);
|
||||||
|
mixer.deployedBlock = tx.blockNumber;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ========== CLI related stuff below ==============
|
||||||
|
|
||||||
function printHelp(code = 0) {
|
function printHelp(code = 0) {
|
||||||
console.log(`Usage:
|
console.log(`Usage:
|
||||||
Submit a deposit from default eth account and return the resulting note
|
Submit a deposit from default eth account and return the resulting note
|
||||||
|
Loading…
x
Reference in New Issue
Block a user