diff --git a/lib/blockchain/coins.js b/lib/blockchain/coins.js index 4712c701..f129f6ff 100644 --- a/lib/blockchain/coins.js +++ b/lib/blockchain/coins.js @@ -304,7 +304,7 @@ Coins.prototype.fromRaw = function fromRaw(data, hash) { code = br.readVarint(); this.coinbase = (code & 1) !== 0; - // Recalculate number of non-zero bytes. + // Recalculate size. size = code / 8 | 0; if ((code & 6) === 0) @@ -364,7 +364,7 @@ Coins.parseCoin = function parseCoin(data, hash, index) { code = br.readVarint(); coin.coinbase = (code & 1) !== 0; - // Recalculate number of non-zero bytes. + // Recalculate size. size = code / 8 | 0; if ((code & 6) === 0) @@ -373,12 +373,13 @@ Coins.parseCoin = function parseCoin(data, hash, index) { if (index >= 2 + size * 8) return; - // Read spent field. + // Setup spent field. offset = br.offset; br.seek(size); - for (i = 2; i <= 4; i += 2) { - if ((code & i) !== 0) { + // Read first two outputs. + for (i = 0; i < 2; i++) { + if ((code & (2 << i)) !== 0) { if (index === 0) { decompress.coin(coin, br); return coin; @@ -391,6 +392,7 @@ Coins.parseCoin = function parseCoin(data, hash, index) { index -= 1; } + // Read outputs. for (i = 0; i < size; i++) { ch = br.data[offset++]; for (j = 0; j < 8; j++) { diff --git a/lib/blockchain/undocoins.js b/lib/blockchain/undocoins.js index 98d607ea..8ee754e8 100644 --- a/lib/blockchain/undocoins.js +++ b/lib/blockchain/undocoins.js @@ -195,6 +195,8 @@ UndoCoin.prototype.toRaw = function toRaw(writer) { var bw = new BufferWriter(writer); var height = this.height; + assert(height !== 0); + if (height === -1) height = 0;