This commit is contained in:
eordano 2015-04-07 15:28:12 -03:00
parent 1907e5f92b
commit 7d2b759f2b

View File

@ -63,7 +63,7 @@ BlockChain.prototype.proposeNewBlock = function(block) {
commonAncestor = pointer; commonAncestor = pointer;
pointer = this.tip; pointer = this.tip;
while (pointer != commonAncestor) { while (pointer !== commonAncestor) {
toUnconfirm.push(pointer); toUnconfirm.push(pointer);
pointer = this.prev[pointer]; pointer = this.prev[pointer];
} }
@ -105,9 +105,9 @@ BlockChain.prototype.unconfirm = function(hash) {
this.tip = prevHash; this.tip = prevHash;
var height = this.height[hash]; var height = this.height[hash];
this.next[prevHash] = undefined; delete this.next[prevHash];
this.hashByHeight[height] = undefined; delete this.hashByHeight[height];
this.height[hash] = undefined; delete this.height[hash];
}; };
BlockChain.prototype.getBlockLocator = function() { BlockChain.prototype.getBlockLocator = function() {
@ -132,6 +132,16 @@ BlockChain.prototype.hasData = function(hash) {
return !!this.prev[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() { BlockChain.prototype.toObject = function() {
return { return {
tip: this.tip, tip: this.tip,