2015-06-28 02:20:07 +00:00
|
|
|
|
2015-07-03 12:53:42 +00:00
|
|
|
Blockchain = function(blockchainConfig) {
|
|
|
|
this.config = blockchainConfig;
|
|
|
|
}
|
2015-06-28 02:20:07 +00:00
|
|
|
|
2015-07-03 12:53:42 +00:00
|
|
|
Blockchain.prototype.generate_basic_command = function() {
|
|
|
|
var config = this.config;
|
|
|
|
var address = config.account.address;
|
2015-06-28 02:20:07 +00:00
|
|
|
|
2015-07-03 12:53:42 +00:00
|
|
|
var cmd = "geth ";
|
2015-06-28 02:20:07 +00:00
|
|
|
|
2015-06-28 13:51:58 +00:00
|
|
|
if (config.datadir !== "default") {
|
|
|
|
cmd += "--datadir=\"" + config.datadir + "\" ";
|
|
|
|
cmd += "--logfile=\"" + config.datadir + ".log\" ";
|
2015-06-28 02:20:07 +00:00
|
|
|
}
|
|
|
|
|
2015-06-28 13:51:58 +00:00
|
|
|
cmd += "--port " + config.port + " ";
|
2015-06-28 02:20:07 +00:00
|
|
|
cmd += "--rpc ";
|
2015-06-28 13:51:58 +00:00
|
|
|
cmd += "--rpcport " + config.rpcPort + " ";
|
|
|
|
cmd += "--networkid " + config.networkId + " ";
|
|
|
|
cmd += "--rpccorsdomain \"" + config.rpcWhitelist + "\" ";
|
2015-06-28 02:20:07 +00:00
|
|
|
|
2015-06-28 13:51:58 +00:00
|
|
|
if (config.minerthreads !== void 0) {
|
|
|
|
cmd += "--minerthreads \"" + config.minerthreads + "\" ";
|
2015-06-28 02:20:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cmd += "--mine ";
|
2015-06-28 02:20:07 +00:00
|
|
|
|
|
|
|
//TODO: this should be configurable
|
2015-07-01 18:00:17 +00:00
|
|
|
cmd += "--maxpeers 0 ";
|
2015-06-28 02:20:07 +00:00
|
|
|
|
2015-06-28 13:51:58 +00:00
|
|
|
if (config.account.password !== void 0) {
|
|
|
|
cmd += "--password " + config.account.password + " ";
|
2015-06-28 02:20:07 +00:00
|
|
|
}
|
|
|
|
|
2015-07-03 12:53:42 +00:00
|
|
|
return cmd;
|
|
|
|
}
|
|
|
|
|
|
|
|
Blockchain.prototype.list_command = function() {
|
|
|
|
return this.generate_basic_command() + "account list ";
|
|
|
|
}
|
|
|
|
|
|
|
|
Blockchain.prototype.init_command = function() {
|
|
|
|
return this.generate_basic_command() + "account new ";
|
|
|
|
}
|
|
|
|
|
2015-07-13 01:33:36 +00:00
|
|
|
Blockchain.prototype.run_command = function(address, use_tmp) {
|
2015-07-03 12:53:42 +00:00
|
|
|
var cmd = this.generate_basic_command();
|
|
|
|
var config = this.config;
|
2015-06-28 02:20:07 +00:00
|
|
|
|
|
|
|
if (address !== void 0) {
|
|
|
|
cmd += "--unlock " + address + " ";
|
|
|
|
}
|
|
|
|
|
2015-06-28 13:51:58 +00:00
|
|
|
if (config.console_toggle) {
|
2015-06-28 02:20:07 +00:00
|
|
|
cmd += "console";
|
|
|
|
}
|
|
|
|
|
2015-06-28 13:51:58 +00:00
|
|
|
if (config.mine_when_needed) {
|
2015-07-13 01:33:36 +00:00
|
|
|
if (use_tmp) {
|
2015-07-22 12:30:04 +00:00
|
|
|
cmd += "js /tmp/js/mine.js";
|
2015-07-13 01:33:36 +00:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
cmd += "js node_modules/embark-framework/js/mine.js";
|
|
|
|
}
|
2015-06-28 02:20:07 +00:00
|
|
|
}
|
|
|
|
|
2015-07-03 12:53:42 +00:00
|
|
|
return cmd;
|
|
|
|
}
|
|
|
|
|
|
|
|
Blockchain.prototype.get_address = function() {
|
|
|
|
var config = this.config;
|
|
|
|
var address = null;
|
2015-06-28 02:20:07 +00:00
|
|
|
|
2015-07-03 12:53:42 +00:00
|
|
|
if (config.account.init) {
|
|
|
|
console.log("running: " + this.list_command());
|
|
|
|
result = exec(this.list_command());
|
|
|
|
|
|
|
|
if (result.output.indexOf("Fatal") < 0) {
|
|
|
|
console.log("=== already initialized");
|
|
|
|
address = result.output.match(/{(\w+)}/)[1];
|
|
|
|
} else {
|
|
|
|
console.log("running: " + this.init_command());
|
|
|
|
result = exec(this.init_command());
|
2015-07-09 11:43:53 +00:00
|
|
|
address = result.output.match(/{(\w+)}/)[1];
|
2015-07-03 12:53:42 +00:00
|
|
|
}
|
|
|
|
}
|
2015-06-28 02:20:07 +00:00
|
|
|
|
2015-07-03 12:53:42 +00:00
|
|
|
return address;
|
2015-06-28 02:20:07 +00:00
|
|
|
}
|
|
|
|
|
2015-07-13 01:33:36 +00:00
|
|
|
Blockchain.prototype.startChain = function(use_tmp) {
|
2015-07-03 12:53:42 +00:00
|
|
|
var address = this.get_address();
|
2015-07-13 01:33:36 +00:00
|
|
|
console.log("running: " + this.run_command(address, use_tmp));
|
|
|
|
exec(this.run_command(address, use_tmp));
|
2015-06-28 02:20:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = Blockchain
|
|
|
|
|