How to use the node-lmdb.Cursor function in node-lmdb

To help you get started, we’ve selected a few node-lmdb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bitpay / bwdb / lib / writer-worker.js View on Github external
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);
github bitpay / bwdb / lib / web-workers.js View on Github external
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 = {
github bitpay / bwdb / lib / writer-worker.js View on Github external
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();
github peeriodproject / core / src / core / topology / BucketStore.js View on Github external
BucketStore.prototype._getCursor = function (txn) {
        return new lmdb.Cursor(txn, this._databaseInstance);
    };
github bitpay / bwdb / lib / web-workers.js View on Github external
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');
  }
};
github bitpay / bwdb / lib / web-workers.js View on Github external
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
      }
    });
  }

node-lmdb

Node binding for LMDB, the Lightning Memory-Mapped Database

MIT
Latest version published 9 months ago

Package Health Score

62 / 100
Full package analysis

Popular node-lmdb functions