diff --git a/lib/local_comms.js b/lib/local_comms.js index 8b4c8f6..ef379c5 100644 --- a/lib/local_comms.js +++ b/lib/local_comms.js @@ -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,