-
Notifications
You must be signed in to change notification settings - Fork 47
Expand file tree
/
Copy pathcli.ts
More file actions
50 lines (42 loc) · 1.47 KB
/
cli.ts
File metadata and controls
50 lines (42 loc) · 1.47 KB
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
import { Command } from 'commander'
import { createTestNetwork, scheduleTxCommand, stateTransition } from './command/index.js'
const program = new Command()
program.name('chopsticks utils').description('CLI to mange some chopsticks instances').version('0.0.1')
program
.command('spinUp')
.description('Spin up the network')
.action(async () => {
await createTestNetwork()
})
program
.command('scheduleTx')
.description('Executes a transaction on the network')
.argument('<endpoint>', 'The endpoint of the network')
.argument('<rawTx>', 'The raw transaction to execute')
.option(
'--origin, <origin>',
'The origin of the transaction Either "Root" or "Signed""',
(value) => {
if (value !== 'Root' && value !== 'Signed') {
throw new Error('Invalid origin. Must be either "Root" or "Signed"')
}
return value
},
'Root'
)
.option('--port <port>', 'The RPC port', '8888')
.action(async (endpoint, rawTx, options) => {
const { origin, port } = options
await scheduleTxCommand(endpoint, rawTx, origin, +port)
})
program
.command('stateTransition')
.description('Shows the state transition of the network by the latest block')
.argument('<endpoint>', 'The endpoint of the network')
.option('--block', 'The block number to do the state transition', 'undefined')
.action(async (endpoint, options) => {
const { block } = options
const blockNumber = block === 'undefined' ? undefined : +block
await stateTransition(endpoint, blockNumber)
})
program.parse()