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