rocketh 0.4.40 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.prettierignore +3 -0
- package/.prettierrc +7 -0
- package/CHANGELOG.md +7 -0
- package/README.md +1 -21
- package/dist/chunk-KWY4QLNL.js +648 -0
- package/dist/chunk-KWY4QLNL.js.map +1 -0
- package/dist/cli.cjs +697 -0
- package/dist/cli.cjs.map +1 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +66 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.cjs +684 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +186 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/package.json +35 -20
- package/src/cli.ts +37 -0
- package/src/environment/deployments.ts +79 -0
- package/src/environment/index.ts +392 -0
- package/src/environment/types.ts +158 -0
- package/src/executor/index.ts +302 -0
- package/src/executor/types.ts +42 -0
- package/src/index.ts +5 -0
- package/src/internal/types.ts +6 -0
- package/src/utils/fs.ts +70 -0
- package/src/utils/json.ts +26 -0
- package/tsconfig.json +15 -0
- package/tsup.config.ts +5 -0
- package/.gitattributes +0 -1
- package/bitski_subprovider.js +0 -148
- package/geth_test_server.js +0 -194
- package/index.js +0 -424
- package/provider.js +0 -58
- package/providerengine.js +0 -128
- package/run.js +0 -1575
- package/run_ganache.js +0 -27
- package/utils.js +0 -188
- package/walletprovider.js +0 -232
package/geth_test_server.js
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const path = require('path');
|
|
3
|
-
const rimraf = require('rimraf');
|
|
4
|
-
const spawn = require('cross-spawn');
|
|
5
|
-
const {onExit} = require('@rauschma/stringio');
|
|
6
|
-
const terminate = require('terminate');
|
|
7
|
-
const tmp = require('tmp');
|
|
8
|
-
const portfinder = require('portfinder');
|
|
9
|
-
|
|
10
|
-
const {
|
|
11
|
-
requireLocal,
|
|
12
|
-
} = require('./utils');
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
function spawnGeth(gethPath, args, hookStd, logFile) {
|
|
16
|
-
|
|
17
|
-
let stdio;
|
|
18
|
-
if(logFile) {
|
|
19
|
-
fs.writeFileSync(logFile, '');
|
|
20
|
-
var output = fs.openSync(logFile, 'a');
|
|
21
|
-
var output2 = fs.openSync(logFile, 'a');
|
|
22
|
-
stdio = ['ignore', output, output2];
|
|
23
|
-
} else {
|
|
24
|
-
if(hookStd) {
|
|
25
|
-
stdio = [process.stdin, process.stdout, process.stderr];
|
|
26
|
-
} else {
|
|
27
|
-
// const devnull = require('dev-null');
|
|
28
|
-
stdio = ['ignore', 'ignore', 'ignore'];
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return spawn(
|
|
32
|
-
gethPath,
|
|
33
|
-
args,
|
|
34
|
-
{
|
|
35
|
-
stdio,
|
|
36
|
-
env:{
|
|
37
|
-
_GETH_CMD_ARGUMENTS: args.join(' ')
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
async function serve(port, wsPort, accounts, chainId, config) {
|
|
44
|
-
let gethBinary;
|
|
45
|
-
try{
|
|
46
|
-
gethBinary = requireLocal('geth-binary');
|
|
47
|
-
} catch(e) {
|
|
48
|
-
throw new Error('In order to use geth as a provider you need to install your desired geth-binary in your own project: "npm install geth-binary');
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
let gethPath = gethBinary ? gethBinary.path : 'geth';
|
|
52
|
-
|
|
53
|
-
/*
|
|
54
|
-
rm -Rf .geth
|
|
55
|
-
<generate .geth/genesis.json>
|
|
56
|
-
printf sesame > .geth/pass
|
|
57
|
-
printf 2bd8fd4e7c04075345677d3127842e737a62db1918beef4cbea6cbc95db0cbdb > .geth/priv
|
|
58
|
-
geth --datadir .geth init .geth/genesis.json
|
|
59
|
-
geth --datadir .geth account import --password .geth/pass .geth/priv
|
|
60
|
-
geth --datadir .geth --syncmode full --networkid 110 --gasprice 1 --password .geth/pass --unlock 30cb8ee8b1bfacdd5edf8ae9f82e59925263c966 --mine --targetgaslimit 6000000 --rpc --rpcaddr localhost --rpcport 8502 --rpcapi eth,net,web3
|
|
61
|
-
*/
|
|
62
|
-
|
|
63
|
-
var tmpobj = tmp.dirSync();
|
|
64
|
-
const gethDataPath = tmpobj.name;
|
|
65
|
-
rimraf.sync(gethDataPath);
|
|
66
|
-
try { fs.mkdirSync(gethDataPath); } catch(e) {}
|
|
67
|
-
const genesisPath = path.join(gethDataPath, 'genesis.json');
|
|
68
|
-
|
|
69
|
-
const gethPort = await portfinder.getPortPromise({
|
|
70
|
-
port: 30310, // minimum port
|
|
71
|
-
stopPort: 39999 // maximum port
|
|
72
|
-
});
|
|
73
|
-
const genesis = {
|
|
74
|
-
config: {
|
|
75
|
-
chainId: chainId || Math.floor(Date.now() / 1000),
|
|
76
|
-
homesteadBlock: 1,
|
|
77
|
-
eip150Block: 2,
|
|
78
|
-
eip150Hash: "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
79
|
-
eip155Block: 3,
|
|
80
|
-
eip158Block: 3,
|
|
81
|
-
byzantiumBlock: 4,
|
|
82
|
-
clique: {
|
|
83
|
-
period: 0,
|
|
84
|
-
epoch: 30000
|
|
85
|
-
}
|
|
86
|
-
},
|
|
87
|
-
nonce: "0x0000000000000042",
|
|
88
|
-
timestamp: "0x00",
|
|
89
|
-
extraData: "0x000000000000000000000000000000000000000000000000000000000000000030cb8ee8b1bfacdd5edf8ae9f82e59925263c9660000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
|
|
90
|
-
gasLimit: "0x59A5380",
|
|
91
|
-
difficulty: "0x1",
|
|
92
|
-
mixHash: "0x0000000000000000000000000000000000000000000000000000000000000000",
|
|
93
|
-
coinbase: "0x0000000000000000000000000000000000000000",
|
|
94
|
-
alloc: {},
|
|
95
|
-
number: "0x0",
|
|
96
|
-
gasUsed: "0x0",
|
|
97
|
-
parentHash: "0x0000000000000000000000000000000000000000000000000000000000000000"
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
for(let i = 0; i < accounts.length; i++) {
|
|
101
|
-
genesis.alloc[accounts[i]] = {
|
|
102
|
-
balance: config.defaultBalance || "0x56BC75E2D63100000"
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
fs.writeFileSync(genesisPath, JSON.stringify(genesis, null, ' '));
|
|
107
|
-
const initProcess = spawnGeth(
|
|
108
|
-
gethPath,
|
|
109
|
-
['--datadir', gethDataPath, 'init', genesisPath],
|
|
110
|
-
// true
|
|
111
|
-
);
|
|
112
|
-
await onExit(initProcess)
|
|
113
|
-
|
|
114
|
-
const passPath = path.join(gethDataPath, 'pass');
|
|
115
|
-
fs.writeFileSync(passPath,'sesame');
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
119
|
-
// sealer account is pregenerated :
|
|
120
|
-
|
|
121
|
-
// const privPath = path.join(gethDataPath, 'priv');
|
|
122
|
-
// fs.writeFileSync(privPath,'2bd8fd4e7c04075345677d3127842e737a62db1918beef4cbea6cbc95db0cbdb');
|
|
123
|
-
// console.log('Initialising account....');
|
|
124
|
-
// const accountCreationProcess = spawnGeth(
|
|
125
|
-
// gethPath,
|
|
126
|
-
// ['--datadir', gethDataPath, 'account', 'import', '--password', passPath, privPath],
|
|
127
|
-
// // true
|
|
128
|
-
// );
|
|
129
|
-
// await onExit(accountCreationProcess)
|
|
130
|
-
|
|
131
|
-
const keystorePath = path.join(gethDataPath, 'keystore');
|
|
132
|
-
keystoreFilepath = path.join(keystorePath, 'UTC--2019-02-26T12-51-20.735389900Z--30cb8ee8b1bfacdd5edf8ae9f82e59925263c966');
|
|
133
|
-
try { fs.mkdirSync(keystorePath); } catch(e) {}
|
|
134
|
-
fs.writeFileSync(keystoreFilepath, '{"address":"30cb8ee8b1bfacdd5edf8ae9f82e59925263c966","crypto":{"cipher":"aes-128-ctr","ciphertext":"e1140b6de3997af4605cc378f08bd58f6b2f1637dbc1bfcdbef93a31665fbedb","cipherparams":{"iv":"e9751ae14e68c9327b6aed03654c2eee"},"kdf":"scrypt","kdfparams":{"dklen":32,"n":262144,"p":1,"r":8,"salt":"d00a5afd0b8decca4a65d8da30fa20419bbacc663213b7368d268f4a0997f8bf"},"mac":"e9ba6a86129f9fbd02ea287fd6eea47e9543d5c3257a4440499b5bcb314251ce"},"id":"4ea8a249-40af-44db-ba7a-d56a239add7e","version":3}');
|
|
135
|
-
//////////////////////////////////////////////////////////////////////////////////////////////////////
|
|
136
|
-
|
|
137
|
-
const gethProcess = spawnGeth(
|
|
138
|
-
gethPath,
|
|
139
|
-
[
|
|
140
|
-
'--datadir', gethDataPath,
|
|
141
|
-
'--syncmode', 'full',
|
|
142
|
-
'--networkid', genesis.config.chainId,
|
|
143
|
-
'--password', passPath,
|
|
144
|
-
'--unlock', '30cb8ee8b1bfacdd5edf8ae9f82e59925263c966',
|
|
145
|
-
'--mine',
|
|
146
|
-
'--gasprice', '1', // 2000000000
|
|
147
|
-
'--targetgaslimit', '0x4c4b400000', // 6000000
|
|
148
|
-
'--rpc',
|
|
149
|
-
'--rpcaddr', 'localhost', // 0.0.0.0 for public
|
|
150
|
-
// '--rpcvhosts', '*',
|
|
151
|
-
'--rpcport', '' + port,
|
|
152
|
-
'--rpcapi', 'eth,net,web3,personal,db,txpool,miner,debug',
|
|
153
|
-
'--ws',
|
|
154
|
-
'--wsaddr', 'localhost', // 0.0.0.0 for public
|
|
155
|
-
'--wsport', '' + wsPort,
|
|
156
|
-
// '--wsorigins', '*',
|
|
157
|
-
'--wsapi', 'eth,net,web3,personal,db,txpool,miner,debug',
|
|
158
|
-
// '--vmdebug',
|
|
159
|
-
'--nat', 'none',
|
|
160
|
-
'--nodiscover',
|
|
161
|
-
'--port', '' + gethPort,
|
|
162
|
-
'--txpool.journal', "''",
|
|
163
|
-
],
|
|
164
|
-
// false,// true // TODO remove
|
|
165
|
-
// '.geth.log'
|
|
166
|
-
);
|
|
167
|
-
|
|
168
|
-
stop = () => {
|
|
169
|
-
return new Promise((resolve, reject) => {
|
|
170
|
-
try {
|
|
171
|
-
terminate(gethProcess.pid, (err) => {
|
|
172
|
-
if(err) {
|
|
173
|
-
reject(err);
|
|
174
|
-
} else {
|
|
175
|
-
setTimeout(() => {
|
|
176
|
-
try{rimraf.sync(gethDataPath);}catch(e){console.error(e);}
|
|
177
|
-
resolve();
|
|
178
|
-
}, 1000);
|
|
179
|
-
}
|
|
180
|
-
})
|
|
181
|
-
} catch(e) {
|
|
182
|
-
reject(e);
|
|
183
|
-
}
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
return {
|
|
188
|
-
stop
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
module.exports = {
|
|
193
|
-
serve
|
|
194
|
-
}
|
package/index.js
DELETED
|
@@ -1,424 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const {
|
|
4
|
-
attach,
|
|
5
|
-
compile,
|
|
6
|
-
runStages,
|
|
7
|
-
runNode,
|
|
8
|
-
rocketh,
|
|
9
|
-
cleanDeployments,
|
|
10
|
-
extractDeployments,
|
|
11
|
-
} = require('./run');
|
|
12
|
-
|
|
13
|
-
const {
|
|
14
|
-
log,
|
|
15
|
-
onExit,
|
|
16
|
-
mergeConfig
|
|
17
|
-
} = require('./utils');
|
|
18
|
-
|
|
19
|
-
const fs = require('fs');
|
|
20
|
-
const path = require('path');
|
|
21
|
-
const rimraf = require('rimraf');
|
|
22
|
-
|
|
23
|
-
if (!global._rocketh_session) {
|
|
24
|
-
global._rocketh_session = {};
|
|
25
|
-
}
|
|
26
|
-
const session = global._rocketh_session;
|
|
27
|
-
|
|
28
|
-
function pause(duration) {
|
|
29
|
-
return new Promise((res) => setTimeout(res, duration * 1000));
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
let configFromFile;
|
|
33
|
-
try {
|
|
34
|
-
configFromFile = require(path.resolve('./rocketh.config.js'));
|
|
35
|
-
} catch (e) {
|
|
36
|
-
// console.error(e); // TODO check existence and show error if exists
|
|
37
|
-
configFromFile = {};
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const config = mergeConfig({
|
|
41
|
-
silent: true,
|
|
42
|
-
node: 'ganache',
|
|
43
|
-
deploymentChainIds: [
|
|
44
|
-
'1', '3', '4', '5', '6', '30', '31', '42', '60', '61', '62', '77', '99', '100', '108',
|
|
45
|
-
],
|
|
46
|
-
showErrorsFromCache: false,
|
|
47
|
-
generateTruffleBuildFiles: false,
|
|
48
|
-
cacheCompilationResult: true,
|
|
49
|
-
accounts: {
|
|
50
|
-
"default": {
|
|
51
|
-
type: 'node'
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}, configFromFile);
|
|
55
|
-
|
|
56
|
-
function setupAnd(func) {
|
|
57
|
-
return (...args) => {
|
|
58
|
-
// const cmdObj = args[args.length-1];
|
|
59
|
-
config.silent = !program.verbose;
|
|
60
|
-
log.setSlient(config.silent);
|
|
61
|
-
log.log(JSON.stringify(config, null, ' '));
|
|
62
|
-
if (require.main === module) {
|
|
63
|
-
log.log('running...');
|
|
64
|
-
func(...args);
|
|
65
|
-
} else {
|
|
66
|
-
log.log('attaching ...');
|
|
67
|
-
const session = global._rocketh_session;
|
|
68
|
-
attach(config, { chainId: session.chainId, url: session.url, accounts: session.accounts });
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function executeOrAttach(execution, willRunStages) {
|
|
74
|
-
const spawn = require('cross-spawn');
|
|
75
|
-
let _stopNode;
|
|
76
|
-
let _cleaning = false;
|
|
77
|
-
async function execute(command, ...args) {
|
|
78
|
-
process.stdin.resume();//so the program will not close instantly
|
|
79
|
-
|
|
80
|
-
async function cleanup(exitCode) {
|
|
81
|
-
if (_cleaning) { return; }
|
|
82
|
-
_cleaning = true;
|
|
83
|
-
|
|
84
|
-
if (session.chainId && config.deploymentChainIds.indexOf(session.chainId) == -1) {
|
|
85
|
-
cleanDeployments();
|
|
86
|
-
}
|
|
87
|
-
// if (config.exportContracts) {
|
|
88
|
-
// try {
|
|
89
|
-
// rimraf.sync(config.exportContracts);
|
|
90
|
-
// } catch (e) {
|
|
91
|
-
|
|
92
|
-
// }
|
|
93
|
-
// }
|
|
94
|
-
if (_stopNode) {
|
|
95
|
-
await _stopNode();
|
|
96
|
-
}
|
|
97
|
-
process.exit(exitCode);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
//do something when app is closing
|
|
101
|
-
process.on('exit', cleanup);
|
|
102
|
-
//catches ctrl+c event
|
|
103
|
-
process.on('SIGINT', cleanup);
|
|
104
|
-
// catches "kill pid" (for example: nodemon restart)
|
|
105
|
-
process.on('SIGUSR1', cleanup);
|
|
106
|
-
process.on('SIGUSR2', cleanup);
|
|
107
|
-
//catches uncaught exceptions
|
|
108
|
-
process.on('uncaughtException', cleanup);
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
let compileResult;
|
|
112
|
-
try {
|
|
113
|
-
compileResult = await compile(config);
|
|
114
|
-
} catch (compileError) {
|
|
115
|
-
console.error(compileError); // TODO compile error shown by compile itself ?
|
|
116
|
-
process.exit(1);
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
const { contractInfos } = compileResult;
|
|
120
|
-
const { chainId, url, accounts, stop, exposedMnemonic } = await runNode(config);
|
|
121
|
-
|
|
122
|
-
session.chainId = chainId;
|
|
123
|
-
session.url = url;
|
|
124
|
-
session.accounts = accounts;
|
|
125
|
-
|
|
126
|
-
_stopNode = stop;
|
|
127
|
-
const result = attach(config, { chainId, url, accounts }, contractInfos);
|
|
128
|
-
|
|
129
|
-
let newDeployments = {};
|
|
130
|
-
if (willRunStages) {
|
|
131
|
-
|
|
132
|
-
try {
|
|
133
|
-
// console.log('running stages...');
|
|
134
|
-
newDeployments = await runStages(config, contractInfos, result.deployments, true);
|
|
135
|
-
} catch (stageError) {
|
|
136
|
-
console.error(stageError);
|
|
137
|
-
process.exit(1);
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
if (config.exportContracts) {
|
|
142
|
-
const savedDeploymentPath = path.join(config.rootPath || './', config.deploymentsPath || 'deployments');
|
|
143
|
-
const chainFolders = [];
|
|
144
|
-
try {
|
|
145
|
-
fs.readdirSync(savedDeploymentPath).forEach((name) => {
|
|
146
|
-
const fPath = path.resolve(savedDeploymentPath, name);
|
|
147
|
-
const stats = fs.statSync(fPath);
|
|
148
|
-
if (name != chainId && stats.isDirectory()) {
|
|
149
|
-
chainFolders.push({ path: fPath, chainId: name });
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
-
} catch (e) {
|
|
153
|
-
// console.error(e);
|
|
154
|
-
}
|
|
155
|
-
const chainDeployments = {};
|
|
156
|
-
for (let folder of chainFolders) {
|
|
157
|
-
chainDeployments[folder.chainId] = extractDeployments(folder.path);
|
|
158
|
-
}
|
|
159
|
-
chainDeployments[chainId] = newDeployments;
|
|
160
|
-
|
|
161
|
-
const content = JSON.stringify(chainDeployments, null, ' ');
|
|
162
|
-
fs.writeFileSync(config.exportContracts, content);
|
|
163
|
-
console.log('contracts info saved at ' + config.exportContracts);
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
let exitCode = 0;
|
|
168
|
-
if (command) {
|
|
169
|
-
const childProcess = spawn(
|
|
170
|
-
command,
|
|
171
|
-
args,
|
|
172
|
-
{
|
|
173
|
-
stdio: [process.stdin, process.stdout, process.stderr],
|
|
174
|
-
env: Object.assign(Object.assign({}, process.env), {
|
|
175
|
-
_ROCKETH_NODE_URL: url,
|
|
176
|
-
_ROCKETH_CHAIN_ID: chainId,
|
|
177
|
-
_ROCKETH_ACCOUNTS: accounts.join(','), // TODO get rif of accounts
|
|
178
|
-
_ROCKETH_MNEMONIC: exposedMnemonic ? exposedMnemonic.split(' ').join(',') : undefined,
|
|
179
|
-
_ROCKETH_DEPLOYMENTS: result.deploymentsPath,
|
|
180
|
-
_ROCKETH_ARGS: argv.join(','),
|
|
181
|
-
})
|
|
182
|
-
}
|
|
183
|
-
);
|
|
184
|
-
try {
|
|
185
|
-
exitCode = await onExit(childProcess);
|
|
186
|
-
} catch (e) {
|
|
187
|
-
if (e.code) {
|
|
188
|
-
exitCode = e.code;
|
|
189
|
-
} else {
|
|
190
|
-
console.error('ERROR onExit', e);
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
if (config.keepRunning) {
|
|
196
|
-
console.log('node running at ' + url + ' (chainId: ' + chainId + ' )');
|
|
197
|
-
} else {
|
|
198
|
-
cleanup(exitCode);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
if(execution && execution.length > 0) {
|
|
202
|
-
execute(execution[0], ...execution.slice(1));
|
|
203
|
-
} else {
|
|
204
|
-
execute();
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
function verify(contractNameOrUUID, willCheckUUID) {
|
|
210
|
-
let mythx_credentials;
|
|
211
|
-
try {
|
|
212
|
-
mythx_credentials = JSON.parse(fs.readFileSync('./.mythx_credentials').toString());
|
|
213
|
-
} catch (e) { console.error(e) }
|
|
214
|
-
|
|
215
|
-
if (!mythx_credentials) {
|
|
216
|
-
console.log(".mythx_credentials not found");
|
|
217
|
-
process.exit(1);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
const MythX = require('mythxjs');
|
|
221
|
-
const client = new MythX.Client(mythx_credentials.ethAddress, mythx_credentials.password, 'rocketh');
|
|
222
|
-
|
|
223
|
-
runVerify();
|
|
224
|
-
|
|
225
|
-
async function runVerify() {
|
|
226
|
-
let tokens;
|
|
227
|
-
try {
|
|
228
|
-
tokens = await client.login();
|
|
229
|
-
} catch (e) {
|
|
230
|
-
console.log('error logging in ', e);
|
|
231
|
-
process.exit(1);
|
|
232
|
-
}
|
|
233
|
-
if (willCheckUUID) {
|
|
234
|
-
await checkUUID(contractNameOrUUID);
|
|
235
|
-
} else {
|
|
236
|
-
if (contractNameOrUUID) {
|
|
237
|
-
verify(contractNameOrUUID); // TODO use option for main
|
|
238
|
-
} else {
|
|
239
|
-
console.log("need to specify contract name");
|
|
240
|
-
process.exit(1);
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
async function checkUUID(uuid) {
|
|
245
|
-
console.log('uuid : ' + uuid);
|
|
246
|
-
|
|
247
|
-
let status;
|
|
248
|
-
while (status !== 'Finished' && status !== 'Error') {
|
|
249
|
-
let statusResponse;
|
|
250
|
-
try {
|
|
251
|
-
statusResponse = await client.getAnalysisStatus(uuid);
|
|
252
|
-
} catch (e) {
|
|
253
|
-
console.error(e);
|
|
254
|
-
await client.login();
|
|
255
|
-
}
|
|
256
|
-
if (statusResponse) {
|
|
257
|
-
if (status !== statusResponse.status) {
|
|
258
|
-
status = statusResponse.status;
|
|
259
|
-
console.log(status);
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
if (status !== 'Finished' && status !== 'Error') {
|
|
263
|
-
await pause(60);
|
|
264
|
-
//TODO
|
|
265
|
-
// try{
|
|
266
|
-
// await client.refreshToken();
|
|
267
|
-
// } catch(e) {
|
|
268
|
-
// console.error(e);
|
|
269
|
-
// }
|
|
270
|
-
|
|
271
|
-
} else {
|
|
272
|
-
console.log(status);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
console.log('fetching issues...');
|
|
276
|
-
const issues = await client.getDetectedIssues(uuid);
|
|
277
|
-
console.log('issues', JSON.stringify(issues, null, ' '));
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
async function verify(contractName, pathToMain) {
|
|
282
|
-
const { contractInfos, solcConfig, solcVersion, contractSrcPaths } = await compile(config);
|
|
283
|
-
const sourceList = Object.keys(solcConfig.sources);
|
|
284
|
-
const sources = {};
|
|
285
|
-
for (let i = 0; i < sourceList.length; i++) {
|
|
286
|
-
const source = solcConfig.sources[sourceList[i]].content;
|
|
287
|
-
sources[sourceList[i]] = {
|
|
288
|
-
source
|
|
289
|
-
};
|
|
290
|
-
}
|
|
291
|
-
// const contractNames = Object.keys(contractInfos);
|
|
292
|
-
// for(let i = 0; i < contractNames.length; i++) {
|
|
293
|
-
// const contractName = contractNames[i];
|
|
294
|
-
const contractInfo = contractInfos[contractName];
|
|
295
|
-
if (!contractInfo) {
|
|
296
|
-
console.log('no contract with name : ' + contractName);
|
|
297
|
-
process.exit(1);
|
|
298
|
-
}
|
|
299
|
-
if (!contractInfo.evm || !contractInfo.evm.bytecode || !contractInfo.evm.bytecode.object || contractInfo.evm.bytecode.object == "") {
|
|
300
|
-
// continue;
|
|
301
|
-
console.log('no evm code for ' + contractName);
|
|
302
|
-
process.exit(1);
|
|
303
|
-
}
|
|
304
|
-
console.log('verifying ' + contractName + ' ...');
|
|
305
|
-
const data = {
|
|
306
|
-
toolName: 'rocketh',
|
|
307
|
-
mainSource: pathToMain || (contractSrcPaths[0] + '/' + contractName + '.sol'),
|
|
308
|
-
contractName,
|
|
309
|
-
abi: contractInfo.abi,
|
|
310
|
-
bytecode: '0x' + contractInfo.evm.bytecode.object,
|
|
311
|
-
deployedBytecode: '0x' + contractInfo.evm.deployedBytecode.object,
|
|
312
|
-
sourceMap: contractInfo.evm.bytecode.sourceMap,
|
|
313
|
-
deployedSourceMap: contractInfo.evm.deployedBytecode.sourceMap,
|
|
314
|
-
sourceList,
|
|
315
|
-
sources,
|
|
316
|
-
analysisMode: 'full',
|
|
317
|
-
// solcVersion, // TODO use package present
|
|
318
|
-
};
|
|
319
|
-
|
|
320
|
-
console.log({ solcVersion });
|
|
321
|
-
// console.log(JSON.stringify(data,null,' '));
|
|
322
|
-
// console.log(JSON.stringify(data.sources,null,' '));
|
|
323
|
-
// process.exit(0);
|
|
324
|
-
|
|
325
|
-
try {
|
|
326
|
-
const response = await client.analyze(data);
|
|
327
|
-
const uuid = response.uuid;
|
|
328
|
-
await checkUUID(uuid)
|
|
329
|
-
} catch (e) {
|
|
330
|
-
console.log('err', e)
|
|
331
|
-
}
|
|
332
|
-
// }
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
const program = require('commander');
|
|
338
|
-
const pkg = require('./package.json')
|
|
339
|
-
program.version(pkg.version);
|
|
340
|
-
let argv;
|
|
341
|
-
if (process.env._ROCKETH_ARGS && process.env._ROCKETH_ARGS != "") {
|
|
342
|
-
argv = process.env._ROCKETH_ARGS.split(',');
|
|
343
|
-
} else {
|
|
344
|
-
argv = process.argv;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
program.option("-v, --verbose", 'more verbose output');
|
|
348
|
-
// TODO program.option("--mnemonicFile", 'specify a specific mnemonic file path');
|
|
349
|
-
|
|
350
|
-
program.command('launch [cmd]')
|
|
351
|
-
.description('launch a node and execute cmd')
|
|
352
|
-
.option('-n, --node <node>', 'specify a node type (geth|ganache) or a url')
|
|
353
|
-
.option('-q, --export-contracts <path>', 'export contractsInfo in <path>')
|
|
354
|
-
.option('-k, --keep-running', 'do not stop the node once stages executed (not for url)')
|
|
355
|
-
.option('-b, --block-time <blockTime>', 'specify a block time at which the node launched (not for url) will be mining')
|
|
356
|
-
.option('-s, --skip-deployments', 'do not run deployments scripts')
|
|
357
|
-
.action(setupAnd(function(cmd, cmdObj){
|
|
358
|
-
// if(!cmdObj) {
|
|
359
|
-
// console.error('launch cmd argument missing ')
|
|
360
|
-
// process.exit(1);
|
|
361
|
-
// }
|
|
362
|
-
|
|
363
|
-
if(cmdObj.keepRunning) {
|
|
364
|
-
config.keepRunning = true;
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
if (cmdObj.skipDeployments) {
|
|
368
|
-
config.skipDeployments = true;
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
if(typeof cmdObj.node != 'undefined') {
|
|
372
|
-
if (['geth', 'ganache'].indexOf(cmdObj.node) != -1) {
|
|
373
|
-
config.node = cmdObj.node;
|
|
374
|
-
} else {
|
|
375
|
-
config.url = cmdObj.node;
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
if(config.url) {
|
|
380
|
-
config.keepRunning = false;
|
|
381
|
-
} else {
|
|
382
|
-
if(typeof cmdObj.blockTime != 'undefined') {
|
|
383
|
-
config.blockTime = parseInt(cmdObj.blockTime);
|
|
384
|
-
}
|
|
385
|
-
}
|
|
386
|
-
// console.log(JSON.stringify(config, null, ' '));
|
|
387
|
-
|
|
388
|
-
if(cmdObj.exportContracts) {
|
|
389
|
-
config.exportContracts = cmdObj.exportContracts;
|
|
390
|
-
}
|
|
391
|
-
|
|
392
|
-
executeOrAttach(cmd ? cmd.split(' ') : undefined, !config.skipDeployments); // TODO split even with more spaces
|
|
393
|
-
}));
|
|
394
|
-
|
|
395
|
-
program.command('attach <url> [cmd]')
|
|
396
|
-
.description('attach to a url and execute cmd')
|
|
397
|
-
.option('-q, --export-contracts <path>', 'export contractsInfo in <path>')
|
|
398
|
-
.action(setupAnd(function(url, cmd, cmdObj){
|
|
399
|
-
config.url = url;
|
|
400
|
-
if(cmdObj.exportContracts) {
|
|
401
|
-
config.exportContracts = cmdObj.exportContracts;
|
|
402
|
-
}
|
|
403
|
-
executeOrAttach(cmd ? cmd.split(' ') : undefined, false); // TODO split even with more spaces
|
|
404
|
-
}));
|
|
405
|
-
|
|
406
|
-
program.command('verify <contractName>')
|
|
407
|
-
.action(setupAnd(function(contractName, cmdObj){
|
|
408
|
-
verify(contractName, false);
|
|
409
|
-
}));
|
|
410
|
-
|
|
411
|
-
program.command('verifyStatus <uuid>')
|
|
412
|
-
.action(setupAnd(function(uuid, cmdObj){
|
|
413
|
-
verify(uuid, true);
|
|
414
|
-
}));
|
|
415
|
-
|
|
416
|
-
program.on('command:*', function () {
|
|
417
|
-
console.error('Invalid command: %s\nSee --help for a list of available commands.', program.args.join(' '));
|
|
418
|
-
process.exit(1);
|
|
419
|
-
});
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
program.parse(argv);
|
|
423
|
-
|
|
424
|
-
module.exports = rocketh;
|
package/provider.js
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
const ProviderEngine = require('./providerengine');
|
|
2
|
-
|
|
3
|
-
const Provider = function(fallbackURL, subproviders) {
|
|
4
|
-
|
|
5
|
-
// TODO : support sourcemap for source line debugging
|
|
6
|
-
// if(contractInfos && compilationInput && srcPath) {
|
|
7
|
-
// const { RevertTraceSubprovider, AbstractArtifactAdapter } = require('@0x/sol-trace');
|
|
8
|
-
|
|
9
|
-
// const sourceCodes = {};
|
|
10
|
-
// const sources = {};
|
|
11
|
-
|
|
12
|
-
// const path = require('path');
|
|
13
|
-
// const sourceFilepaths = Object.keys(compilationInput.sources);
|
|
14
|
-
// for(let i = 0; i < sourceFilepaths.length; i++) {
|
|
15
|
-
// const sourceFilepath = sourceFilepaths[i];
|
|
16
|
-
// const content = compilationInput.sources[sourceFilepath].content;
|
|
17
|
-
// sourceCodes[i] = content;
|
|
18
|
-
// sources[i] = path.resolve(srcPath, sourceFilepath);
|
|
19
|
-
// }
|
|
20
|
-
|
|
21
|
-
// const contractDatas = [];
|
|
22
|
-
// const contractNames = Object.keys(contractInfos);
|
|
23
|
-
// for(let i = 0; i < contractNames.length; i++){
|
|
24
|
-
// const contractName = contractNames[i];
|
|
25
|
-
// const contractInfo = contractInfos[contractName];
|
|
26
|
-
// if(contractInfo.evm.bytecode.object === '0x' && contractInfo.evm.deployedBytecode.object === '0x') {
|
|
27
|
-
// continue;
|
|
28
|
-
// }
|
|
29
|
-
// contractDatas.push({
|
|
30
|
-
// name: contractName,
|
|
31
|
-
// sourceCodes: compilationInput,
|
|
32
|
-
// sources: compilationInput,
|
|
33
|
-
// bytecode: contractInfo.evm.bytecode.object,
|
|
34
|
-
// sourceMap: contractInfo.evm.bytecode.sourceMap,
|
|
35
|
-
// runtimeBytecode: contractInfo.evm.deployedBytecode.object,
|
|
36
|
-
// sourceMapRuntime: contractInfo.evm.deployedBytecode.sourceMap
|
|
37
|
-
// });
|
|
38
|
-
// }
|
|
39
|
-
|
|
40
|
-
// const artifactAdapter = new AbstractArtifactAdapter();
|
|
41
|
-
// artifactAdapter.collectContractsDataAsync = () => {
|
|
42
|
-
// return contractDatas;
|
|
43
|
-
// };
|
|
44
|
-
|
|
45
|
-
// const ethers = require('ethers');
|
|
46
|
-
// const wallet = ethers.Wallet.fromMnemonic(mnemonic, "m/44'/60'/0'/0/"+0);
|
|
47
|
-
// const defaultFromAddress = wallet.address; // Some ethereum address with test funds
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
// const revertTraceSubprovider = new RevertTraceSubprovider(artifactAdapter, defaultFromAddress);
|
|
51
|
-
// subproviders.push(revertTraceSubprovider);
|
|
52
|
-
// }
|
|
53
|
-
ProviderEngine.call(this, fallbackURL, subproviders);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
Provider.prototype = ProviderEngine.prototype;
|
|
57
|
-
|
|
58
|
-
module.exports = Provider;
|