diff --git a/lib/blockchain.js b/lib/blockchain.js index 50b46275..6498491b 100644 --- a/lib/blockchain.js +++ b/lib/blockchain.js @@ -63,7 +63,7 @@ BlockChain.prototype.proposeNewBlock = function(block) { commonAncestor = pointer; pointer = this.tip; - while (pointer != commonAncestor) { + while (pointer !== commonAncestor) { toUnconfirm.push(pointer); pointer = this.prev[pointer]; } @@ -105,9 +105,9 @@ BlockChain.prototype.unconfirm = function(hash) { this.tip = prevHash; var height = this.height[hash]; - this.next[prevHash] = undefined; - this.hashByHeight[height] = undefined; - this.height[hash] = undefined; + delete this.next[prevHash]; + delete this.hashByHeight[height]; + delete this.height[hash]; }; BlockChain.prototype.getBlockLocator = function() { @@ -132,6 +132,16 @@ BlockChain.prototype.hasData = function(hash) { return !!this.prev[hash]; }; +BlockChain.prototype.prune = function() { + var self = this; + _.each(this.prev, function(key, value) { + if (!self.height[key]) { + delete this.prev[key]; + delete this.work[key]; + } + }); +}; + BlockChain.prototype.toObject = function() { return { tip: this.tip,