This commit is contained in:
poma 2019-07-15 19:32:08 +03:00
parent efe89a0b58
commit 44719acdf0

15
cli.js
View File

@ -1,5 +1,4 @@
#!/usr/bin/env node #!/usr/bin/env node
// browserify cli.js -o index.js --exclude worker_threads
const fs = require('fs'); const fs = require('fs');
const assert = require('assert'); const assert = require('assert');
const snarkjs = require("snarkjs"); const snarkjs = require("snarkjs");
@ -75,7 +74,7 @@ async function withdraw(note, receiver) {
async function init() { async function init() {
let contractJson; let contractJson;
if (inBrowser) { if (inBrowser) {
web3 = new Web3(window.web3.currentProvider); web3 = new Web3(window.web3.currentProvider, null, {transactionConfirmationBlocks: 1});
contractJson = await (await fetch('build/contracts/Mixer.json')).json(); contractJson = await (await fetch('build/contracts/Mixer.json')).json();
circuit = await (await fetch('build/circuits/withdraw.json')).json(); circuit = await (await fetch('build/circuits/withdraw.json')).json();
proving_key = await (await fetch('build/circuits/withdraw_proving_key.bin')).arrayBuffer(); proving_key = await (await fetch('build/circuits/withdraw_proving_key.bin')).arrayBuffer();
@ -136,11 +135,7 @@ if (inBrowser) {
switch (args[0]) { switch (args[0]) {
case 'deposit': case 'deposit':
if (args.length === 1) { if (args.length === 1) {
await init(); // then... init().then(async () => deposit()).then(() => process.exit(0)).catch(err => {console.log(err); process.exit(1)});
deposit().then(() => process.exit(0)).catch(err => {
console.log(err);
process.exit(1)
});
} }
else else
printHelp(1); printHelp(1);
@ -148,11 +143,7 @@ if (inBrowser) {
case 'withdraw': case 'withdraw':
if (args.length === 3 && /^0x[0-9a-fA-F]{128}$/.test(args[1]) && /^0x[0-9a-fA-F]{40}$/.test(args[2])) { if (args.length === 3 && /^0x[0-9a-fA-F]{128}$/.test(args[1]) && /^0x[0-9a-fA-F]{40}$/.test(args[2])) {
await init(); // then... init().then(async () => withdraw(args[1], args[2])).then(() => process.exit(0)).catch(err => {console.log(err); process.exit(1)});
withdraw(args[1], args[2]).then(() => process.exit(0)).catch(err => {
console.log(err);
process.exit(1)
});
} }
else else
printHelp(1); printHelp(1);