Prune
This commit is contained in:
parent
1907e5f92b
commit
7d2b759f2b
@ -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,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user