From dcfc19408f3c691ed50608be25fa169f8e747fa3 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sat, 17 Dec 2016 00:13:51 -0800 Subject: [PATCH] node: minor fixes. --- lib/blockchain/chain.js | 12 +++++------- lib/net/packets.js | 13 +++++++++---- lib/node/fullnode.js | 10 ++++------ 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/lib/blockchain/chain.js b/lib/blockchain/chain.js index 3387d77d..5986c874 100644 --- a/lib/blockchain/chain.js +++ b/lib/blockchain/chain.js @@ -1725,7 +1725,7 @@ Chain.prototype.hasPending = function hasPending(hash) { * @returns {Promise} - Returns {@link ChainEntry}. */ -Chain.prototype.getEntry = function getEntry(hash, callback) { +Chain.prototype.getEntry = function getEntry(hash) { return this.db.getEntry(hash); }; @@ -2017,13 +2017,11 @@ Chain.prototype.retarget = function retarget(prev, first) { */ Chain.prototype.findLocator = co(function* findLocator(locator) { - var i, hash, main; + var i, hash; for (i = 0; i < locator.length; i++) { hash = locator[i]; - main = yield this.db.isMainChain(hash); - - if (main) + if (yield this.db.isMainChain(hash)) return hash; } @@ -2033,7 +2031,7 @@ Chain.prototype.findLocator = co(function* findLocator(locator) { /** * Check whether a versionbits deployment is active (BIP9: versionbits). * @example - * chain.isActive(entry, 'witness', callback); + * yield chain.isActive(tip, deployments.segwit); * @see https://github.com/bitcoin/bips/blob/master/bip-0009.mediawiki * @param {ChainEntry} prev - Previous chain entry. * @param {String} id - Deployment id. @@ -2056,7 +2054,7 @@ Chain.prototype.isActive = co(function* isActive(prev, deployment) { /** * Get chain entry state for a deployment (BIP9: versionbits). * @example - * chain.getState(entry, 'witness', callback); + * yield chain.getState(tip, deployments.segwit); * @see https://github.com/bitcoin/bips/blob/master/bip-0009.mediawiki * @param {ChainEntry} prev - Previous chain entry. * @param {String} id - Deployment id. diff --git a/lib/net/packets.js b/lib/net/packets.js index ffadc3c9..645a1bbb 100644 --- a/lib/net/packets.js +++ b/lib/net/packets.js @@ -1952,10 +1952,15 @@ RejectPacket.prototype.fromReader = function fromReader(br) { this.code = br.readU8(); this.reason = br.readVarString('ascii', 111); - if (this.message === 'block' || this.message === 'tx') - this.hash = br.readHash('hex'); - else - this.hash = null; + switch (this.message) { + case 'block': + case 'tx': + this.hash = br.readHash('hex'); + break; + default: + this.hash = null; + break; + } return this; }; diff --git a/lib/node/fullnode.js b/lib/node/fullnode.js index 3f6e0ecb..049cd156 100644 --- a/lib/node/fullnode.js +++ b/lib/node/fullnode.js @@ -307,8 +307,8 @@ FullNode.prototype.scan = function scan(start, filter, iter) { * @returns {Promise} */ -FullNode.prototype.broadcast = function broadcast(item, callback) { - return this.pool.broadcast(item, callback); +FullNode.prototype.broadcast = function broadcast(item) { + return this.pool.broadcast(item); }; /** @@ -334,10 +334,8 @@ FullNode.prototype.sendTX = co(function* sendTX(tx) { throw err; } - if (!this.options.selfish) - tx = tx.toInv(); - - yield this.pool.broadcast(tx); + if (this.options.selfish) + this.pool.announceTX(tx); }); /**