coins: refactor. lint.
This commit is contained in:
parent
dcb376f26d
commit
cc252b949d
@ -1677,11 +1677,11 @@ ChainDB.prototype.connectBlock = co(function* connectBlock(block, view) {
|
|||||||
|
|
||||||
for (i = 0; i < view.length; i++) {
|
for (i = 0; i < view.length; i++) {
|
||||||
coins = view[i];
|
coins = view[i];
|
||||||
raw = coins.toRaw();
|
if (coins.isFullySpent()) {
|
||||||
if (!raw) {
|
|
||||||
this.del(layout.c(coins.hash));
|
this.del(layout.c(coins.hash));
|
||||||
this.coinCache.unpush(coins.hash);
|
this.coinCache.unpush(coins.hash);
|
||||||
} else {
|
} else {
|
||||||
|
raw = coins.toRaw();
|
||||||
this.put(layout.c(coins.hash), raw);
|
this.put(layout.c(coins.hash), raw);
|
||||||
this.coinCache.push(coins.hash, raw);
|
this.coinCache.push(coins.hash, raw);
|
||||||
}
|
}
|
||||||
@ -1773,11 +1773,11 @@ ChainDB.prototype.disconnectBlock = co(function* disconnectBlock(block) {
|
|||||||
|
|
||||||
for (i = 0; i < view.length; i++) {
|
for (i = 0; i < view.length; i++) {
|
||||||
coins = view[i];
|
coins = view[i];
|
||||||
raw = coins.toRaw();
|
if (coins.isFullySpent()) {
|
||||||
if (!raw) {
|
|
||||||
this.del(layout.c(coins.hash));
|
this.del(layout.c(coins.hash));
|
||||||
this.coinCache.unpush(coins.hash);
|
this.coinCache.unpush(coins.hash);
|
||||||
} else {
|
} else {
|
||||||
|
raw = coins.toRaw();
|
||||||
this.put(layout.c(coins.hash), raw);
|
this.put(layout.c(coins.hash), raw);
|
||||||
this.coinCache.push(coins.hash, raw);
|
this.coinCache.push(coins.hash, raw);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -183,6 +183,15 @@ Coins.prototype.size = function size() {
|
|||||||
return index + 1;
|
return index + 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test whether the coins are fully spent.
|
||||||
|
* @returns {Boolean}
|
||||||
|
*/
|
||||||
|
|
||||||
|
Coins.prototype.isFullySpent = function isFullySpent() {
|
||||||
|
return this.size() === 0;
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Coins serialization:
|
* Coins serialization:
|
||||||
* version: varint
|
* version: varint
|
||||||
|
|||||||
@ -175,6 +175,15 @@ Coins.prototype.cleanup = function cleanup() {
|
|||||||
this.outputs.length = len;
|
this.outputs.length = len;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test whether the coins are fully spent.
|
||||||
|
* @returns {Boolean}
|
||||||
|
*/
|
||||||
|
|
||||||
|
Coins.prototype.isFullySpent = function isFullySpent() {
|
||||||
|
return this.outputs.length === 0;
|
||||||
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Coins serialization:
|
* Coins serialization:
|
||||||
* version: varint
|
* version: varint
|
||||||
@ -215,9 +224,8 @@ Coins.prototype.toRaw = function toRaw() {
|
|||||||
var nonzero = 0;
|
var nonzero = 0;
|
||||||
var i, j, code, ch, output;
|
var i, j, code, ch, output;
|
||||||
|
|
||||||
// Return nothing if we're fully spent.
|
// Throw if we're fully spent.
|
||||||
if (len === 0)
|
assert(len !== 0, 'Cannot serialize fully-spent coins.');
|
||||||
return;
|
|
||||||
|
|
||||||
// Calculate number of unspents and spent field size.
|
// Calculate number of unspents and spent field size.
|
||||||
// size = number of bytes required for the bit field.
|
// size = number of bytes required for the bit field.
|
||||||
@ -537,7 +545,7 @@ CoinEntry.prototype.toWriter = function toWriter(bw) {
|
|||||||
|
|
||||||
if (this.output) {
|
if (this.output) {
|
||||||
compress.output(this.output, bw);
|
compress.output(this.output, bw);
|
||||||
return;
|
return bw;
|
||||||
}
|
}
|
||||||
|
|
||||||
assert(this.raw);
|
assert(this.raw);
|
||||||
@ -549,6 +557,8 @@ CoinEntry.prototype.toWriter = function toWriter(bw) {
|
|||||||
raw = this.raw.slice(this.offset, this.offset + this.size);
|
raw = this.raw.slice(this.offset, this.offset + this.size);
|
||||||
|
|
||||||
bw.writeBytes(raw);
|
bw.writeBytes(raw);
|
||||||
|
|
||||||
|
return bw;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -104,7 +104,7 @@ function decompressScript(script, br) {
|
|||||||
// This violates consensus rules.
|
// This violates consensus rules.
|
||||||
// We don't need to read it.
|
// We don't need to read it.
|
||||||
script.fromNulldata(new Buffer(0));
|
script.fromNulldata(new Buffer(0));
|
||||||
p.seek(size);
|
br.seek(size);
|
||||||
} else {
|
} else {
|
||||||
data = br.readBytes(size);
|
data = br.readBytes(size);
|
||||||
script.fromRaw(data);
|
script.fromRaw(data);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user