coins: optimize.
This commit is contained in:
parent
578ff8f684
commit
b0aebb9c84
@ -1071,11 +1071,11 @@ ChainDB.prototype.connectBlock = function connectBlock(block, view, callback) {
|
||||
|
||||
for (i = 0; i < view.length; i++) {
|
||||
coins = view[i];
|
||||
if (coins.size() === 0) {
|
||||
raw = coins.toRaw();
|
||||
if (!raw) {
|
||||
this.del(layout.c(coins.hash));
|
||||
this.coinCache.remove(coins.hash);
|
||||
} else {
|
||||
raw = coins.toRaw();
|
||||
this.put(layout.c(coins.hash), raw);
|
||||
this.coinCache.set(coins.hash, raw);
|
||||
}
|
||||
@ -1172,11 +1172,11 @@ ChainDB.prototype.disconnectBlock = function disconnectBlock(block, callback) {
|
||||
|
||||
for (i = 0; i < view.length; i++) {
|
||||
coins = view[i];
|
||||
if (coins.size() === 0) {
|
||||
raw = coins.toRaw();
|
||||
if (!raw) {
|
||||
self.del(layout.c(coins.hash));
|
||||
self.coinCache.remove(coins.hash);
|
||||
} else {
|
||||
raw = coins.toRaw();
|
||||
self.put(layout.c(coins.hash), raw);
|
||||
self.coinCache.set(coins.hash, raw);
|
||||
}
|
||||
|
||||
@ -224,6 +224,10 @@ Coins.prototype.toRaw = function toRaw(writer) {
|
||||
var length = this.size();
|
||||
var i, output, bits, fstart, flen, bit, oct;
|
||||
|
||||
// Return nothing if we're fully spent.
|
||||
if (length === 0)
|
||||
return writer;
|
||||
|
||||
// Varint version: hopefully some smartass
|
||||
// miner doesn't start mining `-1` versions.
|
||||
p.writeVarint(this.version);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user