-
Notifications
You must be signed in to change notification settings - Fork 15
/
cli.js
executable file
·67 lines (54 loc) · 1.95 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
#!/usr/bin/env node
const Mallet = require('./lib/mallet.js');
const path = require('path');
const os = require('os');
const Repl = require('repl');
const ReplHistory = require('repl.history');
const prog = require('caporal');
const opn = require('opn');
const rlp = require('./lib/rlp.js');
const exportedProperties = [
'web3',
'listAccounts',
'newAccount',
'importPrivateKey',
'getBalance',
'getNonce',
'selectAccount',
'currentAccount',
'sendTransaction',
'lastTransaction',
'getReceipt',
'requestFunds',
'iele'
]
function listCommands() {
const ieleCommands = ['iele.simpleTransfer', 'iele.callContract', 'iele.deployContract', 'iele.constantCall', 'iele.compile'];
const utils = ['help', 'listCommands', 'rlp'];
return exportedProperties.filter(x => x !== 'iele').concat(ieleCommands).concat(utils).sort();
}
function help() {
opn('https://github.com/input-output-hk/mallet/blob/master/README.md');
}
function start(args, opts) {
console.log(`Mallet ${require('./package.json').version} - IELE/KEVM/EVM testnet utility\n` +
`Type 'help()' to view the online documentation or 'listCommands()' to view available commands\n`);
const mallet = new Mallet(args.testnet, opts.datadir);
const repl = Repl.start('mallet> ');
repl.context.mallet = mallet;
repl.context.listCommands = listCommands;
repl.context.help = help;
repl.context.rlp = rlp;
exportedProperties.forEach(prop => repl.context[prop] = mallet[prop]);
ReplHistory(repl, path.join(opts.datadir, '.history'));
}
prog
.bin('mallet')
.description('command line utility for KEVM/IELE testnets')
.version(require('./package.json').version)
.argument('<testnet>', "JSON RPC endpoint to connect. Possible values are: 'kevm', 'iele', or a custom HTTP(S) URL")
.option('-d, --datadir', 'Specify data directory', prog.STRING, path.join(os.homedir(), '.mallet2'))
.action(function(args, opts, logger) {
start(args, opts);
});
prog.parse(process.argv);