forked from TrueBitFoundation/scrypt-interactive
-
Notifications
You must be signed in to change notification settings - Fork 2
/
cli.js
110 lines (90 loc) · 3.14 KB
/
cli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
require("dotenv").config();
const program = require("commander");
const selfText = require("./client/util/selfText");
const newStopper = require("./client/util/stopper");
const commands = require("./client/commands");
const Web3 = require("web3");
const HDWalletProvider = require("@truffle/hdwallet-provider");
const provider =
process.env.USE_LOCAL_SIGNER === "true"
? new HDWalletProvider(process.env.MNEMONIC, process.env.WEB3_HTTP_PROVIDER)
: process.env.WEB3_HTTP_PROVIDER;
const web3 = new Web3(provider);
// sets up bridge
const connectToBridge = async function (cmd) {
cmd.log("Connecting to bridge...");
const bridge = await require("./client")(web3);
cmd.log("Connected!");
return bridge;
};
const main = async () => {
const cmd = { log: console.log.bind(console) };
const operator =
process.env.OPERATOR_ADDRESS ||
(await web3.eth.getAccounts())[0] ||
(await web3.eth.getCoinbase());
web3.eth.defaultAccount = operator;
const bridge = await connectToBridge(cmd);
const { stop, stopper } = newStopper();
process.on("SIGINT", stop);
program.version("0.0.1").description(selfText);
program
.command("status [claimId]")
.description("Display the status of the bridge.")
.action(async function (claimId) {
await commands.status(cmd, bridge, operator, claimId);
});
program
.command("deposit <amount>")
.description("Deposit <amount> into ScryptClaims")
.action(async function (amount) {
await commands.deposit(cmd, bridge, operator, amount);
});
program
.command("withdraw <amount>")
.description('Withdraw <amount> from ScryptClaims. <amount> can be "all"')
.action(async function (amount) {
await commands.withdraw(cmd, bridge, operator, amount);
});
program
.command("resume-claim <proposal-id>")
.description("Resume defending a blockheader on the DogeRelay")
.action(async function (proposalId, /*options*/) {
await commands.resumeClaim(cmd, bridge, operator, proposalId);
});
program
.command("claim <blockheader> <hash> <proposal-id>")
.description("Claim a blockheader on the DogeRelay")
.action(async function (blockheader, hash, proposalId, /*options*/) {
const claim = {
claimant: operator,
input: blockheader,
hash,
proposalId,
};
await commands.claim(cmd, bridge, operator, claim, stopper);
});
program
.command("monitor")
.description(
"Monitors the Doge-Eth bridge and validates blockheader claims."
)
.option("-c, --auto-challenge", "Automatically challenge incorrect claims.")
.action(async function (/*options*/) {
await commands.monitor(cmd, bridge, operator, true, stopper);
});
program
.command("defend")
.description("Monitors the Doge-Eth bridge and defend our own claims.")
.action(async function (/*options*/) {
await commands.defend(cmd, bridge, operator, stopper);
});
program.parse(process.argv);
};
process.on("unhandledRejection", (error, p) => {
console.error("Unhandled Rejection at:", p, "error:", error);
});
main().catch((err) => {
console.error(err);
process.exit(1);
});