-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.js
More file actions
93 lines (78 loc) · 3.62 KB
/
index.js
File metadata and controls
93 lines (78 loc) · 3.62 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
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
#!/usr/bin/env node
const repl = require("repl");
const Web3 = require("web3");
const utils = require("ethereumjs-util");
const program = require("commander");
const chalk = require("chalk");
const web3Admin = require("./web3Admin");
const os = require("os");
const path = require("path");
const package = require("./package.json");
const defaultProvider = "http://localhost:8545";
const isETCFork = function(web3) {
const forkBlock = web3.eth.getBlock(1920000);
if (forkBlock) {
if (
forkBlock.hash ===
"0x94365e3a8c0b35089c1d1195081fe7489b528a84b22199c916180db8b28ade7f"
)
return "true";
else return "false";
} else {
return "?";
}
};
const printHeader = function() {
console.log(`
██╗ ██╗███████╗██████╗ ██████╗ ██╗███████╗ ██████╗ ███████╗██████╗ ██╗
██║ ██║██╔════╝██╔══██╗╚════██╗ ██║██╔════╝ ██╔══██╗██╔════╝██╔══██╗██║
██║ █╗ ██║█████╗ ██████╔╝ █████╔╝ ██║███████╗ ██████╔╝█████╗ ██████╔╝██║
██║███╗██║██╔══╝ ██╔══██╗ ╚═══██╗ ██ ██║╚════██║ ██╔══██╗██╔══╝ ██╔═══╝ ██║
╚███╔███╔╝███████╗██████╔╝██████╔╝██╗╚█████╔╝███████║ ██║ ██║███████╗██║ ███████╗
╚══╝╚══╝ ╚══════╝╚═════╝ ╚═════╝ ╚═╝ ╚════╝ ╚══════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚══════╝
`);
};
const printStatus = web3 => () => {
try {
const lastBlockNumber = web3.eth.blockNumber;
const lastBlock = web3.eth.getBlock(lastBlockNumber);
console.log(`
${chalk.green("Provider : " + web3.currentProvider.host)}
${chalk.green("Last Block # : " + lastBlockNumber)}
${chalk.green("Last Block : " + (!lastBlock ? "N/A" : lastBlock.hash))}
${chalk.green("Mining? : " + web3.eth.mining)}
${chalk.green("Peer Count : " + web3.net.peerCount)}
${chalk.green("Web3 api version : " + web3.version.api)}
${chalk.green("ETC fork? : " + isETCFork(web3))}
${chalk.green("Coinbase : " + web3.eth.coinbase)}
`);
} catch (err) {
console.error(chalk.red(err));
}
};
program
.version(package.version)
.option("-p, --provider [url]", "Web3JS RPC provider")
.option("-s, --skip-status", "Does not show status after bootstrap")
.option(
"-hf, --history-file [path]",
"File path of commands history file (defaults to $HOME/.web3_repl_history)"
)
.parse(process.argv);
printHeader();
const web3 = new Web3(
new Web3.providers.HttpProvider(program.provider || defaultProvider)
);
if (!program.skipStatus) printStatus(web3)();
var replServer = repl.start({
prompt: "> ",
ignoreUndefined: true
});
const historyFile = program.historyFile
? program.historyFile
: path.join(os.homedir(), ".web3_repl_history");
require("repl.history")(replServer, historyFile);
web3Admin.extend(web3);
replServer.context.web3 = web3;
replServer.context.utils = utils;
replServer.context.status = printStatus(web3);