diff --git a/lib/bcoin/chain.js b/lib/bcoin/chain.js index 528c2fd7..d2e6b0d6 100644 --- a/lib/bcoin/chain.js +++ b/lib/bcoin/chain.js @@ -865,6 +865,8 @@ Chain.prototype._checkInputs = function _checkInputs(block, prev, flags, callbac bcoin.debug(tx); bcoin.debug('Input:'); bcoin.debug(tx.inputs[j]); + bcoin.debug('TX with coins:'); + bcoin.debug(tx.toExtended('hex', true)); assert(!historical, 'BUG: Invalid inputs in historical data!'); return callback(new VerifyError(block, 'invalid', diff --git a/lib/bcoin/pool.js b/lib/bcoin/pool.js index c11e28cf..81786731 100644 --- a/lib/bcoin/pool.js +++ b/lib/bcoin/pool.js @@ -2216,7 +2216,7 @@ Pool.prototype.isMisbehaving = function isMisbehaving(host) { Pool.prototype.reject = function reject(peer, obj, code, reason, score) { if (obj) { bcoin.debug('Rejecting %s %s from %s: ccode=%s reason=%s', - obj.type, obj.hash('hex'), peer.host, code, reason); + obj.type || 'block', obj.hash('hex'), peer.host, code, reason); peer.reject({ ccode: code, @@ -2256,6 +2256,7 @@ function LoadRequest(pool, peer, type, hash, callback) { this.type = type; this.hash = hash; this.callback = []; + this.active = false; if (callback) this.callback.push(callback); @@ -2274,6 +2275,7 @@ LoadRequest.prototype.start = function start() { this.timeout = setTimeout(this._finish, this.pool.requestTimeout); this.peer.on('close', this._finish); + this.active = true; this.pool.request.active++; if (this.type === this.pool.tx.type) this.pool.request.activeTX++; @@ -2291,6 +2293,9 @@ LoadRequest.prototype.start = function start() { LoadRequest.prototype.finish = function finish() { var index; + if (!this.active) + return; + if (this.pool.request.map[this.hash]) { delete this.pool.request.map[this.hash]; this.pool.request.active--; diff --git a/lib/bcoin/tx.js b/lib/bcoin/tx.js index 3285b897..77f335cb 100644 --- a/lib/bcoin/tx.js +++ b/lib/bcoin/tx.js @@ -1696,15 +1696,22 @@ TX.fromRaw = function fromRaw(data, enc) { * timestamp, pending-since time, and optionally a vector * for the serialized coins. * @param {Boolean?} saveCoins - Whether to serialize the coins. + * @param {String?} enc - One of `"hex"` or `null`. * @returns {Buffer} */ -TX.prototype.toExtended = function toExtended(saveCoins) { +TX.prototype.toExtended = function toExtended(saveCoins, enc) { var height = this.height; var index = this.index; var changeIndex = this.changeIndex != null ? this.changeIndex : -1; var p = new BufferWriter(); - var i, input; + var i, input, tmp; + + if (typeof saveCoins === 'string') { + tmp = saveCoins; + saveCoins = enc; + enc = tmp; + } if (height === -1) height = 0x7fffffff; @@ -1737,7 +1744,12 @@ TX.prototype.toExtended = function toExtended(saveCoins) { } } - return p.render(); + p = p.render(); + + if (enc === 'hex') + p = p.toString('hex'); + + return p; }; /** @@ -1745,13 +1757,23 @@ TX.prototype.toExtended = function toExtended(saveCoins) { * @param {Buffer} buf * @param {Boolean?} saveCoins - If true, the function will * attempt to parse the coins. + * @param {String?} enc - One of `"hex"` or `null`. * @returns {NakedTX} - A "naked" transaction object. */ -TX.parseExtended = function parseExtended(buf, saveCoins) { - var p = new BufferReader(buf); - var tx, coinCount, coin, i; +TX.parseExtended = function parseExtended(buf, saveCoins, enc) { + var p, tx, coinCount, coin, i, tmp; + if (typeof saveCoins === 'string') { + tmp = saveCoins; + saveCoins = enc; + enc = tmp; + } + + if (enc === 'hex') + buf = new Buffer(buf, 'hex'); + + p = new BufferReader(buf); p.start(); tx = bcoin.protocol.parser.parseTX(p); @@ -1799,11 +1821,12 @@ TX.parseExtended = function parseExtended(buf, saveCoins) { * @param {Buffer} buf * @param {Boolean?} saveCoins - If true, the function will * attempt to parse the coins. + * @param {String?} enc - One of `"hex"` or `null`. * @returns {TX} */ -TX.fromExtended = function fromExtended(buf, saveCoins) { - return new TX(TX.parseExtended(buf, saveCoins)); +TX.fromExtended = function fromExtended(buf, saveCoins, enc) { + return new TX(TX.parseExtended(buf, saveCoins, enc)); }; /**