Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
WriterWorker.prototype._pruneWalletBlocks = function(callback) {
/* jshint maxstatements: 30 */
var txn = this.db.env.beginTxn();
var self = this;
var cursor = new lmdb.Cursor(txn, this.db.blocks);
var found = cursor.goToLast();
if (found === null) {
return abort();
}
var currentHeight;
var pruneHeight = 0;
cursor.getCurrentBinary(function(key, value) {
var walletBlock = models.WalletBlock.fromBuffer(key, value);
pruneHeight = Math.max(0, walletBlock.height - self.pruneDepth);
log.info('Pruning wallet blocks from height', pruneHeight);
});
var pruneKey = models.WalletBlock.getKey(pruneHeight);
found = cursor.goToKey(pruneKey);
WebWorker.prototype.getWalletUTXOs = function(walletId, options, callback) {
assert(Buffer.isBuffer(walletId), '"walletId" is expected to be a buffer');
var self = this;
var txn = this.db.env.beginTxn({readOnly: true});
var utxos = [];
var cursor = new lmdb.Cursor(txn, this.db.utxos);
var start = models.WalletUTXO.getKey(walletId, NULL_TXID, 0);
var found = cursor.goToRange(start);
function iterator() {
cursor.getCurrentBinary(function(key, value) {
var utxo = models.WalletUTXO.fromBuffer(key, value, self.network);
utxos.push(utxo);
var nextFound = cursor.goToNext();
if (nextFound && utxos.length < options.limit) {
// TODO make sure maximum call stack is not reached
iterator();
} else {
cursor.close();
var result = {
WriterWorker.prototype._loadLatestWalletBlock = function(callback) {
var self = this;
var txn = this.db.env.beginTxn({readOnly: true});
var cursor = new lmdb.Cursor(txn, this.db.blocks);
var found = cursor.goToLast();
if (found === null) {
// we will create the wallet later
callback();
} else {
cursor.getCurrentBinary(function(key, value) {
self.walletBlock = models.WalletBlock.fromBuffer(key, value);
self.blockFilter = new BlockFilter({
network: self.network,
addressFilter: self.walletBlock.addressFilter
});
cursor.close();
txn.abort();
BucketStore.prototype._getCursor = function (txn) {
return new lmdb.Cursor(txn, this._databaseInstance);
};
WebWorker.prototype._updateLatestTip = function() {
var self = this;
var txn = this.db.env.beginTxn({readOnly: true});
var cursor = new lmdb.Cursor(txn, this.db.blocks);
var found = cursor.goToLast();
if (found !== null) {
cursor.getCurrentBinary(function(key, value) {
var walletBlock = models.WalletBlock.fromBuffer(key, value);
self.bitcoinHeight = walletBlock.height;
self.bitcoinHash = walletBlock.blockHash.toString('hex');
cursor.close();
txn.abort();
});
} else {
cursor.close();
txn.abort();
log.info('Active syncing is idle, there are currently no wallets');
}
};
WebWorker.prototype._getLatestTxids = function(txn, walletId, options, callback) {
assert(Buffer.isBuffer(walletId), '"walletId" is expected to be a buffer');
var txids = [];
try {
options = validators.sanitizeRangeOptions(options);
} catch(err) {
return callback(err);
}
var cursor = new lmdb.Cursor(txn, this.db.txids);
var start = models.WalletTxid.create(walletId, options.height, options.index);
var found = cursor.goToRange(start.getKey());
if (found) {
iterate();
} else {
cursor.close();
callback(null, {
txids: txids,
start: {
height: options.height,
index: options.index
}
});
}