mirror of
https://github.com/jwinterm/nodejs-pool.git
synced 2026-10-17 05:21:27 +02:00
Update with function for getOldestLockBlock
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user