embark-area-51/lib/blockchain.js

74 lines
1.8 KiB
JavaScript
Raw Normal View History

var Deploy;
2015-06-28 13:51:58 +00:00
var Config = require('./config/config.js');
startChain = function(env) {
2015-06-28 13:51:58 +00:00
config = (new Config.Blockchain()).loadConfigFile('config/blockchain.yml').config(env);
2015-06-28 13:51:58 +00:00
address = config.account.address;
cmd = "geth ";
2015-06-28 13:51:58 +00:00
if (config.datadir !== "default") {
cmd += "--datadir=\"" + config.datadir + "\" ";
cmd += "--logfile=\"" + config.datadir + ".log\" ";
}
2015-06-28 13:51:58 +00:00
cmd += "--port " + config.port + " ";
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 13:51:58 +00:00
if (config.minerthreads !== void 0) {
cmd += "--minerthreads \"" + config.minerthreads + "\" ";
}
cmd += "--mine ";
cmd += "--maxpeers 0 ";
2015-06-28 13:51:58 +00:00
if (config.account.password !== void 0) {
cmd += "--password " + config.account.password + " ";
}
2015-06-28 13:51:58 +00:00
if (config.account.init) {
console.log("=== initializating account");
console.log("running: " + cmd + " account list");
result = exec(cmd + "account list");
console.log("finished");
console.log("=== output is " + result.output);
if (result.output.indexOf("Fatal") < 0) {
console.log("=== already initialized");
address = result.output.match(/{(\w+)}/)[1];
} else {
console.log("running: " + cmd + " account new");
output = exec(cmd + " account new");
address = output.output.match(/{(\w+)}/)[1];
}
}
if (address !== void 0) {
cmd += "--unlock " + address + " ";
}
2015-06-28 13:51:58 +00:00
if (config.console_toggle) {
cmd += "console";
}
2015-06-28 13:51:58 +00:00
if (config.mine_when_needed) {
cmd += "js node_modules/embark-framework/js/mine.js";
}
console.log("running: " + cmd);
console.log("=== running geth");
exec(cmd);
}
Blockchain = {
startChain: startChain
}
module.exports = Blockchain