forked from microsoft/vscode-mock-debug
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathethdbg.js
executable file
·151 lines (138 loc) · 4.15 KB
/
ethdbg.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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#! /usr/bin/env node
// TODO remove alot of the boilerplate by moving it into ethdbg main
const {DebugProvider} = require('/home/insi/Projects/ETHDBG/ethdbg/index.js');
const yargs = require('yargs');
const _ = require('lodash');
/**
Available Options (taken directly from ganache-cli:
Full docs: https://github.com/trufflesuite/ganache-cli
pass object to ethdbg.js in spawn, ie
`spawn('./ethdbg.js', JSON.stringify({...});`
/* eslint-disable */
/*
--port/-p: <port to bind to, default 8545>
--host/-h: <host to bind to, default 0.0.0.0>
--fork/-f: <url> (Fork from another currently running Ethereum client at a given block)
--db: <db path> (directory to save chain db)
--seed/-s <seed value for PRNG, default random>
--deterministic/-d (uses fixed seed)
--mnemonic/-m <mnemonic>
--accounts/-a <number of accounts to generate at startup>
--acctKeys <path to file> (saves generated accounts and private keys as JSON object in specified file)
--secure/-s (Lock accounts by default)
--unlock <accounts> (Comma-separated list of accounts or indices to unlock)
--blocktime/-b <block time in seconds>
--networkId/-i <network id> (default current time)
--gasPrice/-g <gas price> (default 20000000000)
--gasLimit/-l <gas limit> (default 90000)"
--debug (Output VM opcodes for debugging)
--verbose/-v
--mem (Only show memory output, not tx history)");
--log-level: level of output to show
} */
/* eslint-enable */
/* ETHDBG Specific Options:
loggerLevel: Amount of output to show,
- 6: Everything (Debug)
- 5: INFO (User Info)
- 4: Warnings
- 3: Errors
- 2: Critical Errors
- 1: Fatal Errors
- 0: Silent (Not Recommended)
a Level of '5' will also print error levels 1-4, level of 4, 1-3, and so on.
*/
console.log("Ethdbg started!");
const parser = yargs()
.options('unlock', {
type: 'string',
alias: 'u'
});
let argv = parser.parse(process.argv);
if (argv.d || argv.deterministic) {
// Seed phrase; don't change to Ganache, maintain original determinism
argv.s = 'TestRPC is awesome!';
}
if (typeof argv.unlock == 'string') {
argv.unlock = [argv.unlock];
}
let logger = console; // ganache-core logger
// If the mem argument is passed, only show memory output,
// not transaction history.
if (argv.mem === true) {
logger = {
log: function() {}
};
setInterval(function() {
console.log(process.memoryUsage()); // eslint-disable no-console
}, 1000);
}
/**
* get options from process.argv
* @return{Object}
*/
let options = {
port: argv.p || argv.port || '8545',
hostname: argv.h || argv.hostname,
debug: argv.debug,
seed: argv.s || argv.seed,
mnemonic: argv.m || argv.mnemonic,
total_accounts: argv.a || argv.accounts,
blocktime: argv.b || argv.blocktime,
gasPrice: argv.g || argv.gasPrice,
gasLimit: argv.l || argv.gasLimit,
accounts: parseAccounts(argv.account),
unlocked_accounts: argv.unlock,
fork: argv.f || argv.fork || false,
network_id: argv.i || argv.networkId,
verbose: argv.v || argv.verbose,
secure: argv.n || argv.secure || false,
db_path: argv.db || null,
account_keys_path: argv.acctKeys || null,
logger: logger,
loggerLevel: argv.loglvl || 5,
}
/**
* gets acc from cmd arg
* @param{string} accounts
* @return{Array}
* @private
*/
function parseAccounts(accounts) {
/**
* splits string up by acc
* @param{string} account
* @return{Object}
* @private
*/
function splitAccount(account) {
account = account.split(',')
return {
secretKey: account[0],
balance: account[1]
};
}
if (typeof accounts === 'string') return [splitAccount(accounts)];
else if (!Array.isArray(accounts)) return;
let ret = []
for (let i = 0; i < accounts.length; i++) {
ret.push(splitAccount(accounts[i]));
}
return ret;
}
(async () => {
try {
let opts = {};
_.forIn(options, (val, key) => { // conv string bools to intrinsic types
if (options[key] === 'false' || options[key] === 'true') {
opts[key] = (val == 'true');
} else {
opts[key] = val;
}
});
const ethdbg = new DebugProvider(opts);
await ethdbg.init();
} catch (err) {
throw new Error(`Error in ethdbg ${err}`);
}
})();