Update with function for getOldestLockBlock

This commit is contained in:
Alexander Blair
2017-11-01 10:18:28 -07:00
parent 51b4a98026
commit 81d6207d71
+32
View File
@@ -618,6 +618,38 @@ function Database(){
});
};
this.getOldestLockedBlock = function(){
/*
6-29-2017 - Snipa -
This function returns a decompressed block proto for the first locked block in the system as part of the
share depth functions. DO NOT BLINDLY REPLACE getLastBlock WITH THIS FUNCTION.
*/
this.refreshEnv();
debug("Getting the oldest locked block in the system");
let txn = this.env.beginTxn({readOnly: true});
let cursor = new this.lmdb.Cursor(txn, this.blockDB);
let highestBlock = null;
for (let found = cursor.goToFirst(); found; found = cursor.goToNext()) {
if (highestBlock !== null){
break;
}
cursor.getCurrentBinary(function(key, data){ // jshint ignore:line
let blockData = global.protos.Block.decode(data);
if (blockData.unlocked === false){
highestBlock = blockData;
}
});
}
cursor.close();
txn.commit();
if (highestBlock !== null) {
debug("Got the oldest locked block in the system at height: " + highestBlock);
} else {
debug("There are no unlocked blocks in the system. Woohoo!");
}
return highestBlock;
};
this.cleanShareDBNew = function() {
/*
This function takes the difficulty of the current block, and the last PPS block. If it's 0, save everything,