From f1a02711bd188a510074cc519fbb342c5a9150e0 Mon Sep 17 00:00:00 2001 From: Joris Bontje Date: Wed, 29 Jul 2015 15:49:02 +0200 Subject: [PATCH] make genesis block configurable. fixes #41 --- .gitignore | 1 + boilerplate/config/blockchain.yml | 5 +++-- boilerplate/config/genesis.json | 12 ++++++++++++ demo/config/blockchain.yml | 5 +++-- demo/config/genesis.json | 12 ++++++++++++ demo_meteor/config/blockchain.yml | 3 ++- demo_meteor/config/genesis.json | 12 ++++++++++++ lib/blockchain.js | 4 +++- lib/config/blockchain.js | 2 +- test/blockchain.js | 2 +- test/config.blockchain.js | 4 +++- test/support/blockchain.yml | 3 ++- 12 files changed, 55 insertions(+), 10 deletions(-) create mode 100644 boilerplate/config/genesis.json create mode 100644 demo/config/genesis.json create mode 100644 demo_meteor/config/genesis.json diff --git a/.gitignore b/.gitignore index 73a1bfee1..cd7162c95 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ node_modules TODO +.node-xmlhttprequest-sync-* diff --git a/boilerplate/config/blockchain.yml b/boilerplate/config/blockchain.yml index cf9f329aa..0457f5107 100644 --- a/boilerplate/config/blockchain.yml +++ b/boilerplate/config/blockchain.yml @@ -3,6 +3,7 @@ development: rpc_port: 8101 rpc_whitelist: "*" minerthreads: 1 + genesis_block: config/genesis.json datadir: /tmp/embark mine_when_needed: true gas_limit: 500000 @@ -20,7 +21,7 @@ staging: console: true account: init: false - address: + address: production: rpc_host: localhost rpc_port: 8101 @@ -30,4 +31,4 @@ production: console: true account: init: false - address: + address: diff --git a/boilerplate/config/genesis.json b/boilerplate/config/genesis.json new file mode 100644 index 000000000..9f60d776e --- /dev/null +++ b/boilerplate/config/genesis.json @@ -0,0 +1,12 @@ +{ + "nonce": "0x0000000000000042", + "difficulty": "0x40000", + "alloc": { + }, + "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "coinbase": "0x0000000000000000000000000000000000000000", + "timestamp": "0x00", + "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "extraData": "0x", + "gasLimit": "0x4c4b40" +} diff --git a/demo/config/blockchain.yml b/demo/config/blockchain.yml index cf9f329aa..0457f5107 100644 --- a/demo/config/blockchain.yml +++ b/demo/config/blockchain.yml @@ -3,6 +3,7 @@ development: rpc_port: 8101 rpc_whitelist: "*" minerthreads: 1 + genesis_block: config/genesis.json datadir: /tmp/embark mine_when_needed: true gas_limit: 500000 @@ -20,7 +21,7 @@ staging: console: true account: init: false - address: + address: production: rpc_host: localhost rpc_port: 8101 @@ -30,4 +31,4 @@ production: console: true account: init: false - address: + address: diff --git a/demo/config/genesis.json b/demo/config/genesis.json new file mode 100644 index 000000000..9f60d776e --- /dev/null +++ b/demo/config/genesis.json @@ -0,0 +1,12 @@ +{ + "nonce": "0x0000000000000042", + "difficulty": "0x40000", + "alloc": { + }, + "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "coinbase": "0x0000000000000000000000000000000000000000", + "timestamp": "0x00", + "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "extraData": "0x", + "gasLimit": "0x4c4b40" +} diff --git a/demo_meteor/config/blockchain.yml b/demo_meteor/config/blockchain.yml index e1a4936be..3bfb3fd23 100644 --- a/demo_meteor/config/blockchain.yml +++ b/demo_meteor/config/blockchain.yml @@ -3,6 +3,7 @@ development: rpc_port: 8101 rpc_whitelist: "*" minerthreads: 1 + genesis_block: config/genesis.json datadir: /tmp/embark mine_when_needed: true gas_limit: 500000 @@ -20,4 +21,4 @@ staging: console: true account: init: false - address: + address: diff --git a/demo_meteor/config/genesis.json b/demo_meteor/config/genesis.json new file mode 100644 index 000000000..9f60d776e --- /dev/null +++ b/demo_meteor/config/genesis.json @@ -0,0 +1,12 @@ +{ + "nonce": "0x0000000000000042", + "difficulty": "0x40000", + "alloc": { + }, + "mixhash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "coinbase": "0x0000000000000000000000000000000000000000", + "timestamp": "0x00", + "parentHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "extraData": "0x", + "gasLimit": "0x4c4b40" +} diff --git a/lib/blockchain.js b/lib/blockchain.js index d089ae1bf..a93d00ffc 100644 --- a/lib/blockchain.js +++ b/lib/blockchain.js @@ -25,6 +25,9 @@ Blockchain.prototype.generate_basic_command = function() { } cmd += "--mine "; + if (config.genesisBlock !== void 0) { + cmd += "--genesis=\"" + config.genesisBlock + "\" "; + } //TODO: this should be configurable cmd += "--maxpeers 0 "; @@ -96,4 +99,3 @@ Blockchain.prototype.startChain = function(use_tmp) { } module.exports = Blockchain - diff --git a/lib/config/blockchain.js b/lib/config/blockchain.js index ca2e0f080..ec20cee6d 100644 --- a/lib/config/blockchain.js +++ b/lib/config/blockchain.js @@ -38,6 +38,7 @@ BlockchainConfig.prototype.config = function(env) { gasPrice: config.gas_price || 10000000000000, rpcWhitelist: config.rpc_whitelist, minerthreads: config.minerthreads, + genesisBlock: config.genesis_block, datadir: config.datadir, networkId: networkId, port: config.port || "30303", @@ -50,4 +51,3 @@ BlockchainConfig.prototype.config = function(env) { }; module.exports = BlockchainConfig; - diff --git a/test/blockchain.js b/test/blockchain.js index 4f94ca823..527ccf710 100644 --- a/test/blockchain.js +++ b/test/blockchain.js @@ -10,7 +10,7 @@ describe('embark.blockchain', function() { var blockchain = new Blockchain(blockchainConfig); it('should return correct cmd', function() { - assert.strictEqual(blockchain.generate_basic_command(), "geth --datadir=\"/tmp/embark\" --logfile=\"/tmp/embark.log\" --port 30303 --rpc --rpcport 8101 --networkid "+blockchainConfig.networkId+" --rpccorsdomain \"*\" --minerthreads \"1\" --mine --maxpeers 0 --password config/password "); + assert.strictEqual(blockchain.generate_basic_command(), "geth --datadir=\"/tmp/embark\" --logfile=\"/tmp/embark.log\" --port 30303 --rpc --rpcport 8101 --networkid "+blockchainConfig.networkId+" --rpccorsdomain \"*\" --minerthreads \"1\" --mine --genesis=\"config/genesis.json\" --maxpeers 0 --password config/password "); }); }); diff --git a/test/config.blockchain.js b/test/config.blockchain.js index 80509835f..7930ce67a 100644 --- a/test/config.blockchain.js +++ b/test/config.blockchain.js @@ -41,6 +41,7 @@ describe('embark.config.blockchain', function() { rpc_whitelist: "*", network_id: 0, minerthreads: 1, + genesis_block: 'config/genesis.json', datadir: '/tmp/embark', mine_when_needed: true, gas_limit: 123, @@ -63,6 +64,7 @@ describe('embark.config.blockchain', function() { gasPrice: 100, rpcWhitelist: "*", minerthreads: 1, + genesisBlock: 'config/genesis.json', datadir: '/tmp/embark', networkId: 0, port: "30303", @@ -103,6 +105,7 @@ describe('embark.config.blockchain', function() { gasPrice: 10000000000000, rpcWhitelist: "*", minerthreads: 1, + genesisBlock: undefined, datadir: '/tmp/embark', networkId: 0, port: "30303", @@ -122,4 +125,3 @@ describe('embark.config.blockchain', function() { }); }); - diff --git a/test/support/blockchain.yml b/test/support/blockchain.yml index e1a4936be..3bfb3fd23 100644 --- a/test/support/blockchain.yml +++ b/test/support/blockchain.yml @@ -3,6 +3,7 @@ development: rpc_port: 8101 rpc_whitelist: "*" minerthreads: 1 + genesis_block: config/genesis.json datadir: /tmp/embark mine_when_needed: true gas_limit: 500000 @@ -20,4 +21,4 @@ staging: console: true account: init: false - address: + address: