Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"use strict";

const program = require("commander");
const {version} = require("../package.json");

program
.version(version)
// .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)")
.command("repl", "Starts REPL mode", {isDefault: true}).alias("r")
.command("eval [expression]", "Executes a single command and quits").alias('e')
.parse(process.argv);
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 21 additions & 0 deletions components/repl.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const repl = require("repl.js");
const instarun = require('repl.js/src/evaler/instarun');
const Console = require('repl.js/src/utilrepl/console');

module.exports = (extensions, historyFile) => {
const replServer = repl.start({prompt: "> ", ignoreUndefined: true});

Object
.entries(extensions)
.forEach(([key, extension]) => {
replServer.context[key] = extension;
});

if (historyFile)
require("repl.history")(replServer, historyFile);

return {
replServer,
instarun: (opts) => instarun(replServer, Console.Console({}), opts)
};
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const chalk = require("chalk");
const { isETCFork } = require("./network");
const { isETCFork } = require("../network");

const printStatus = web3 => () => {
try {
Expand Down
File renamed without changes.
25 changes: 25 additions & 0 deletions components/web3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"use strict";

const Web3 = require("web3");
const utils = require("ethereumjs-util");
const contracts = require("./contracts");
const printStatus = require("./ui-helpers/printStatus");
const web3Admin = require("./web3-admin");

const defaultProvider = "http://localhost:8545";

module.exports = (provider) => {
const web3 = new Web3(new Web3.providers.HttpProvider(provider || defaultProvider));

web3Admin.extend(web3);

const {contract, predefinedContracts} = contracts(web3);

return {
web3,
utils,
contract,
predefinedContracts,
status: printStatus(web3)
};
}
32 changes: 32 additions & 0 deletions index-eval.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"use strict";

const program = require("commander");
const fs = require("fs");
const web3 = require("./components/web3");
const repl = require("./components/repl");
const printHeader = require("./components/ui-helpers/printHeader");

function runEval(expression, options) {}

program
.option("-T, --pipe", "Does not print any status information and quit")
.option("-p, --provider [url]", "Web3JS RPC provider")
.parse(process.argv);

if (!program.args || program.args.length !== 1) {
console.error('Expression required!');
process.exit(1);
}

if (!program.pipe)
printHeader(web3);

const toEval = program.args[0];

const opts = fs.existsSync(toEval)
? { file: toEval, print: true, quit: program.pipe }
: { eval: toEval, print: true, quit: program.pipe };

const components = web3(program.provider);
const {replServer, instarun} = repl(components);
instarun(opts);
28 changes: 7 additions & 21 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,17 @@
#!/usr/bin/env node

const Web3 = require("web3");
const utils = require("ethereumjs-util");
const program = require("commander");
const chalk = require("chalk");
const os = require("os");
const path = require("path");

const repl = require("./repl");
const contracts = require("./contracts");
require("./commands");
return;

const printStatus = require("./helpers/printStatus");
const printHeader = require("./helpers/printHeader");
const web3Admin = require("./web3Admin");
//printHeader();
//const repl = require("./components/repl");

const package = require("./package.json");

const defaultProvider = "http://localhost:8545";

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)();

Expand All @@ -39,10 +23,12 @@ web3Admin.extend(web3);

const {contract, predefinedContracts} = contracts(web3);

repl({
const {instarun} = repl({
web3,
utils,
contract,
predefinedContracts,
status: printStatus(web3)
}, historyFile);

instarun({eval: "web3.eth.blockNumber", print: true, quit: true});
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"dependencies": {
"chalk": "1.1.3",
"commander": "2.9.0",
"console-ultimate": "2.9.0",
"ethereumjs-util": "5.1.2",
"repl.history": "0.1.4",
"repl.js": "2.3.7",
Expand Down
14 changes: 0 additions & 14 deletions repl.js
Original file line number Diff line number Diff line change
@@ -1,14 +0,0 @@
const repl = require("repl.js");

module.exports = (extensions, historyFile) => {
const replServer = repl.start({prompt: "> ", ignoreUndefined: true});

Object
.entries(extensions)
.forEach(([key, extension]) => {
replServer.context[key] = extension;
});
require("repl.history")(replServer, historyFile);

return replServer;
}
Loading