2015-06-28 13:59:17 +00:00
|
|
|
var readYaml = require('read-yaml');
|
|
|
|
|
|
|
|
BlockchainConfig = function() {};
|
|
|
|
|
|
|
|
BlockchainConfig.prototype.loadConfigFile = function(filename) {
|
|
|
|
try {
|
|
|
|
this.blockchainConfig = readYaml.sync(filename);
|
|
|
|
} catch (e) {
|
|
|
|
throw new Error("error reading " + filename);
|
|
|
|
}
|
|
|
|
return this;
|
2015-07-04 02:41:39 +00:00
|
|
|
};
|
2015-06-28 13:59:17 +00:00
|
|
|
|
|
|
|
BlockchainConfig.prototype.loadConfig = function(config) {
|
|
|
|
this.blockchainConfig = config;
|
|
|
|
return this;
|
2015-07-04 02:41:39 +00:00
|
|
|
};
|
2015-06-28 13:59:17 +00:00
|
|
|
|
|
|
|
BlockchainConfig.prototype.config = function(env) {
|
|
|
|
if (this.blockchainConfig === null) {
|
|
|
|
throw new Error("no blockchain config found");
|
|
|
|
}
|
|
|
|
|
|
|
|
var config = this.blockchainConfig[env || "development"];
|
|
|
|
|
|
|
|
var networkId;
|
|
|
|
if (config.network_id === undefined) {
|
2015-07-04 02:41:39 +00:00
|
|
|
networkId = Math.floor((Math.random() * 100000) + 1000);
|
2015-06-28 13:59:17 +00:00
|
|
|
}
|
|
|
|
else {
|
2015-07-04 02:41:39 +00:00
|
|
|
networkId = config.network_id;
|
2015-06-28 13:59:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
config = {
|
|
|
|
rpcHost: config.rpc_host,
|
|
|
|
rpcPort: config.rpc_port,
|
|
|
|
gasLimit: config.gas_limit || 500000,
|
|
|
|
gasPrice: config.gas_price || 10000000000000,
|
|
|
|
rpcWhitelist: config.rpc_whitelist,
|
|
|
|
minerthreads: config.minerthreads,
|
2015-07-29 13:49:02 +00:00
|
|
|
genesisBlock: config.genesis_block,
|
2015-06-28 13:59:17 +00:00
|
|
|
datadir: config.datadir,
|
2015-09-04 08:55:19 +00:00
|
|
|
chains: config.chains,
|
2015-06-28 13:59:17 +00:00
|
|
|
networkId: networkId,
|
2015-07-30 01:40:49 +00:00
|
|
|
maxPeers: 4,
|
2015-06-28 13:59:17 +00:00
|
|
|
port: config.port || "30303",
|
|
|
|
console_toggle: config.console || false,
|
|
|
|
mine_when_needed: config.mine_when_needed || false,
|
2015-08-09 20:41:42 +00:00
|
|
|
whisper: config.whisper || false,
|
2015-06-28 13:59:17 +00:00
|
|
|
account: config.account
|
|
|
|
}
|
|
|
|
|
|
|
|
return config;
|
2015-07-04 02:41:39 +00:00
|
|
|
};
|
2015-06-28 13:59:17 +00:00
|
|
|
|
2015-09-15 00:58:52 +00:00
|
|
|
module.exports = BlockchainConfig;
|