diff --git a/lib/bcoin/block.js b/lib/bcoin/block.js index 72ef3373..4799552c 100644 --- a/lib/bcoin/block.js +++ b/lib/bcoin/block.js @@ -80,9 +80,8 @@ Block.prototype.hasTX = function hasTX(hash) { Block.prototype._verifyMerkle = function verifyMerkle() { var height = 0; - if (this.subtype === 'block') { + if (this.subtype === 'block') return; - } // Count leafs for (var i = this.totalTX; i > 0; i >>= 1) @@ -180,32 +179,28 @@ Block.prototype._buildMerkle = function buildMerkle() { // and CheckBlock() in bitcoin/src/main.cpp. Block.prototype._checkBlock = function checkBlock() { // Check proof of work matches claimed amount - if (!utils.testTarget(this.bits, this.hash())) { + if (!utils.testTarget(this.bits, this.hash())) return false; - } // Check timestamp - if (this.ts > (Date.now() / 1000) + 2 * 60 * 60) { + if (this.ts > (Date.now() / 1000) + 2 * 60 * 60) return false; - } // Size of all txs cant be bigger than MAX_BLOCK_SIZE - if (this.txs.length > bcoin.protocol.constants.block.maxSize) { + if (this.txs.length > bcoin.protocol.constants.block.maxSize) return false; - } // First TX must be a coinbase if (!this.txs.length || this.txs[0].inputs.length !== 1 || - +this.txs[0].inputs[0].out.hash !== 0) { + +this.txs[0].inputs[0].out.hash !== 0) return false; - } // The rest of the txs must not be coinbases for (var i = 1; i < this.txs.length; i++) { - if (this.txs[i].inputs.length === 1 && +this.txs[i].inputs[0].out.hash === 0) { + if (this.txs[i].inputs.length === 1 && + +this.txs[i].inputs[0].out.hash === 0) return false; - } } // Build MerkleTree @@ -215,10 +210,11 @@ Block.prototype._checkBlock = function checkBlock() { var unique = {}; for (var i = 0; i < this.txs.length; i++) { var hash = this.txs[i].hash('hex'); - if (unique[hash]) return false; + if (unique[hash]) + return false; unique[hash] = true; } // Check merkle root - return this.merkleTree[this.merkleTree.length-1] === this.merkleRoot; + return this.merkleTree[this.merkleTree.length - 1] === this.merkleRoot; }; diff --git a/lib/bcoin/protocol/parser.js b/lib/bcoin/protocol/parser.js index 28bdb968..43052331 100644 --- a/lib/bcoin/protocol/parser.js +++ b/lib/bcoin/protocol/parser.js @@ -383,34 +383,34 @@ Parser.prototype.parseAddr = function parseAddr(p) { return this._error('Invalid addr size'); var addrs = []; - var len, off, count, ts, service, ipv4, ipv6, port, i; // count - len = readIntv(p, 0); - off = len.off; - count = len.r; + var len = readIntv(p, 0); + var off = len.off; + var count = len.r; + p = p.slice(off); - for (i = 0; i < count; i++) { + for (var i = 0; i < count; i++) { // timestamp - LE - ts = utils.readU32(p, 0); + var ts = utils.readU32(p, 0); // NODE_NETWORK service - LE - service = utils.readU64(p, 4); + var service = utils.readU64(p, 4); // ipv6 - BE - ipv6 = utils.toHex(p.slice(12, 24)); + var ipv6 = utils.toHex(p.slice(12, 24)); ipv6 = '::' + ipv6.replace(/(.{4})/g, '$1:').slice(0, -1); // ipv4 - BE - ipv4 = utils.readU32BE(p, 24); + var ipv4 = utils.readU32BE(p, 24); ipv4 = ((ipv4 >> 24) & 0xff) + '.' + ((ipv4 >> 16) & 0xff) + '.' + ((ipv4 >> 8) & 0xff) + '.' + ((ipv4 >> 0) & 0xff); // port - BE - port = utils.readU16BE(p, 28); + var port = utils.readU16BE(p, 28); addrs.push({ ts: ts,