forked from TrueBitFoundation/scrypt-interactive
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcli.js
117 lines (96 loc) · 3.18 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
111
112
113
114
115
116
117
require('dotenv').config()
const promisify = require('es6-promisify')
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
)
: new Web3.providers.HttpProvider(process.env.WEB3_HTTP_PROVIDER)
const web3 = new Web3(provider)
const getDefaultAddress = promisify(web3.eth.getDefaultAddress, web3.eth)
const getCoinbase = promisify(web3.eth.getCoinbase, web3.eth)
// sets up bridge
const connectToBridge = async function (cmd) {
if (this.bridge) {
return this.bridge
}
cmd.log('Connecting to bridge...')
this.bridge = await require('./client')(web3)
cmd.log('Connected!')
return this.bridge
}
const main = async () => {
const cmd = { log: console.log.bind(console) }
const operator = process.env.OPERATOR_ADDRESS || (await getDefaultAddress()) || (await 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 ClaimManager')
.action(async function (amount) {
await commands.deposit(cmd, bridge, operator, amount)
})
program
.command('withdraw <amount>')
.description('Withdraw <amount> from ClaimManager. <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: hash,
proposalID: 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.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)
})