From d02cced4bd41e085ab86718bda27adc507c0faaa Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Mon, 27 Apr 2015 12:53:49 -0300 Subject: [PATCH] remove unused code, add config files --- api/config/default.yml | 12 ++++++++++-- api/lib/http.js | 1 + config/default.yml | 3 --- config/livenet.yml | 3 --- config/testnet.yml | 3 --- lib/networkmonitor.js | 1 - lib/node.js | 17 +++-------------- 7 files changed, 14 insertions(+), 26 deletions(-) diff --git a/api/config/default.yml b/api/config/default.yml index 1ba65a51..7d5332ac 100644 --- a/api/config/default.yml +++ b/api/config/default.yml @@ -2,7 +2,15 @@ BitcoreHTTP: port: 8080 logging: true BitcoreNode: + LevelUp: ./testnet-db + network: testnet NetworkMonitor: - network: livenet host: localhost - port: 8333 + port: 18333 + Reporter: none # none, simple, matrix + RPC: + user: user + pass: password + protocol: http + host: 127.0.0.1 + port: 18332 diff --git a/api/lib/http.js b/api/lib/http.js index 686acdb6..e56b61f8 100644 --- a/api/lib/http.js +++ b/api/lib/http.js @@ -98,6 +98,7 @@ BitcoreHTTP.prototype.onListening = function() { BitcoreHTTP.prototype.start = function() { + this.node.start(); this.server.listen(this.port); }; diff --git a/config/default.yml b/config/default.yml index 48ddb954..564f1073 100644 --- a/config/default.yml +++ b/config/default.yml @@ -5,9 +5,6 @@ BitcoreNode: host: localhost port: 8333 Reporter: none # none, simple, matrix -BitcoreHTTP: - host: localhost - port: 8080 RPC: user: user pass: password diff --git a/config/livenet.yml b/config/livenet.yml index 48ddb954..564f1073 100644 --- a/config/livenet.yml +++ b/config/livenet.yml @@ -5,9 +5,6 @@ BitcoreNode: host: localhost port: 8333 Reporter: none # none, simple, matrix -BitcoreHTTP: - host: localhost - port: 8080 RPC: user: user pass: password diff --git a/config/testnet.yml b/config/testnet.yml index 313e99cd..29a08192 100644 --- a/config/testnet.yml +++ b/config/testnet.yml @@ -5,9 +5,6 @@ BitcoreNode: host: localhost port: 18333 Reporter: none # none, simple, matrix -BitcoreHTTP: - host: localhost - port: 8080 RPC: user: user pass: password diff --git a/lib/networkmonitor.js b/lib/networkmonitor.js index 6d792b9c..2bc57d87 100644 --- a/lib/networkmonitor.js +++ b/lib/networkmonitor.js @@ -73,7 +73,6 @@ NetworkMonitor.prototype.requestBlocks = function(locator) { _.isString(locator[0]), 'start must be a block hash string array'); this.peer.sendMessage(this.messages.GetBlocks({ starts: locator, - //stop: '000000002c05cc2e78923c34df87fd108b22221ac6076c18f3ade378a4d915e9' // TODO: remove this!!! })); }; diff --git a/lib/node.js b/lib/node.js index ca19bca6..e97c8964 100644 --- a/lib/node.js +++ b/lib/node.js @@ -36,7 +36,6 @@ var BitcoreNode = function(bus, networkMonitor, blockService, transactionService this.blockService = blockService; this.blockCache = {}; - this.inventory = {}; // blockHash -> bool (has data) this.initialize(); }; util.inherits(BitcoreNode, EventEmitter); @@ -100,9 +99,8 @@ BitcoreNode.prototype.initialize = function() { var prevHash = bitcore.util.buffer.reverse(block.header.prevHash).toString('hex'); self.blockCache[block.hash] = block; - self.inventory[block.hash] = true; if (!self.blockchain.hasData(prevHash)) { - self.requestFromTip(); + self._requestFromTip(); return; } var blockchainChanges = self.blockchain.proposeNewBlock(block); @@ -111,8 +109,6 @@ BitcoreNode.prototype.initialize = function() { block.height = self.blockchain.height[block.id]; block.work = self.blockchain.work[block.id]; - //console.log('block', block.id, block.height); - return Promise.each(blockchainChanges.unconfirmed, function(hash) { return self.blockService.unconfirm(self.blockCache[hash]); }) @@ -128,13 +124,6 @@ BitcoreNode.prototype.initialize = function() { delete self.blockCache[deleteHash]; } }) - .then(function() { - // TODO: include this - if (false && _.size(self.inventory) && _.all(_.values(self.inventory))) { - self.inventory = {}; - self.requestFromTip(); - } - }) .catch(function(error) { self.stop(error); }); @@ -171,7 +160,7 @@ BitcoreNode.prototype.stop = function(reason) { this.networkMonitor.abort(reason); }; -BitcoreNode.prototype.requestFromTip = function() { +BitcoreNode.prototype._requestFromTip = function() { var locator = this.blockchain.getBlockLocator(); //console.log('requesting blocks, locator size:', locator.length); this.networkMonitor.requestBlocks(locator); @@ -180,7 +169,7 @@ BitcoreNode.prototype.requestFromTip = function() { BitcoreNode.prototype.sync = function() { var self = this; this.networkMonitor.on('ready', function() { - self.requestFromTip(); + self._requestFromTip(); }); };