simplify blockchain constructor

This commit is contained in:
Iuri Matias 2017-02-21 20:54:07 -05:00
parent 0e03d8f435
commit b5ff1add40
1 changed files with 6 additions and 5 deletions

View File

@ -5,9 +5,10 @@ var fs = require('../../core/fs.js');
var GethCommands = require('./geth_commands.js'); var GethCommands = require('./geth_commands.js');
var Blockchain = function(blockchainConfig, Client, env) { var Blockchain = function(options) {
this.blockchainConfig = blockchainConfig; this.blockchainConfig = options.blockchainConfig;
this.env = env || 'development'; this.env = options.env || 'development';
this.client = options.client;
this.config = { this.config = {
geth_bin: this.blockchainConfig.geth_bin || 'geth', geth_bin: this.blockchainConfig.geth_bin || 'geth',
@ -30,7 +31,7 @@ var Blockchain = function(blockchainConfig, Client, env) {
vmdebug: this.blockchainConfig.vmdebug || false vmdebug: this.blockchainConfig.vmdebug || false
}; };
this.client = new Client({config: this.config, env: this.env}); this.client = new options.client({config: this.config, env: this.env});
}; };
Blockchain.prototype.runCommand = function(cmd) { Blockchain.prototype.runCommand = function(cmd) {
@ -80,7 +81,7 @@ Blockchain.prototype.initChainAndGetAddress = function() {
var BlockchainClient = function(blockchainConfig, client, env) { var BlockchainClient = function(blockchainConfig, client, env) {
if (client === 'geth') { if (client === 'geth') {
return new Blockchain(blockchainConfig, GethCommands, env); return new Blockchain({blockchainConfig: blockchainConfig, client: GethCommands, env: env});
} else { } else {
throw new Error('unknown client'); throw new Error('unknown client');
} }