coins: minor.

This commit is contained in:
Christopher Jeffrey 2016-12-02 01:50:43 -08:00
parent b37b99a86e
commit dbed720d20
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 9 additions and 5 deletions

View File

@ -304,7 +304,7 @@ Coins.prototype.fromRaw = function fromRaw(data, hash) {
code = br.readVarint(); code = br.readVarint();
this.coinbase = (code & 1) !== 0; this.coinbase = (code & 1) !== 0;
// Recalculate number of non-zero bytes. // Recalculate size.
size = code / 8 | 0; size = code / 8 | 0;
if ((code & 6) === 0) if ((code & 6) === 0)
@ -364,7 +364,7 @@ Coins.parseCoin = function parseCoin(data, hash, index) {
code = br.readVarint(); code = br.readVarint();
coin.coinbase = (code & 1) !== 0; coin.coinbase = (code & 1) !== 0;
// Recalculate number of non-zero bytes. // Recalculate size.
size = code / 8 | 0; size = code / 8 | 0;
if ((code & 6) === 0) if ((code & 6) === 0)
@ -373,12 +373,13 @@ Coins.parseCoin = function parseCoin(data, hash, index) {
if (index >= 2 + size * 8) if (index >= 2 + size * 8)
return; return;
// Read spent field. // Setup spent field.
offset = br.offset; offset = br.offset;
br.seek(size); br.seek(size);
for (i = 2; i <= 4; i += 2) { // Read first two outputs.
if ((code & i) !== 0) { for (i = 0; i < 2; i++) {
if ((code & (2 << i)) !== 0) {
if (index === 0) { if (index === 0) {
decompress.coin(coin, br); decompress.coin(coin, br);
return coin; return coin;
@ -391,6 +392,7 @@ Coins.parseCoin = function parseCoin(data, hash, index) {
index -= 1; index -= 1;
} }
// Read outputs.
for (i = 0; i < size; i++) { for (i = 0; i < size; i++) {
ch = br.data[offset++]; ch = br.data[offset++];
for (j = 0; j < 8; j++) { for (j = 0; j < 8; j++) {

View File

@ -195,6 +195,8 @@ UndoCoin.prototype.toRaw = function toRaw(writer) {
var bw = new BufferWriter(writer); var bw = new BufferWriter(writer);
var height = this.height; var height = this.height;
assert(height !== 0);
if (height === -1) if (height === -1)
height = 0; height = 0;