How to use the bitcore-lib.Block function in bitcore-lib

To help you get started, we’ve selected a few bitcore-lib 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 / bitcore-p2p / test / messages / commands / index.js View on Github external
it('should accept a block instance as an argument', function() {
      var block = new bitcore.Block({
        header: {},
        transactions: []
      });
      var message = messages.Block(block);
      message.block.should.be.instanceof(bitcore.Block);
    });
github bitpay / bitcore-node / test / services / header / index.unit.js View on Github external
describe('Header Service', function() {

  var headerService;
  var sandbox;
  var prevHeader = new Block(new Buffer('01000000b25c0849b469983b4a5b90a49e4c0e4ba3853122ed141b5bd92d14000000000021a8aaa4995e4ce3b885677730b153741feda66a08492287a45c6a131671ba5a72ff504c5a0c011c456e4d060201000000010000000000000000000000000000000000000000000000000000000000000000ffffffff08045a0c011c028208ffffffff0100f2052a010000004341041994d910507ec4b2135dd32a4723caf00f8567f356ffbd5e703786d856b49a89d6597c280d8981238fbde81fa3767161bc3e994c17be41b42235a61c24c73459ac0000000001000000013b517d1aebd89b4034e0cf9b25ecbe82ef162ce71284e92a1f1adebf44ea1409000000008b483045022100c7ebc62e89740ddab42a64435c996e1c91a063f9f2cc004b4f023f7a1be5234402207608837faebec16049461d4ef7de807ce217040fd2a823a29da16ec07e463d440141048f108c0da4b5be3308e2e0b521d02d341de85b36a29285b47f00bc33e57a89cf4b6e76aa4a48ddc9a5e882620779e0f1b19dc98d478052fbd544167c745be1d8ffffffff010026e85a050000001976a914f760ef90462b0a4bde26d597c1f29324f5cd0fc488ac00000000', 'hex')).header.toObject();
  var preObjectHeader = new Block(new Buffer('010000006a39821735ec18a366d95b391a7ff10dee181a198f1789b0550e0d00000000002b0c80fa52b669022c344c3e09e6bb9698ab90707bb4bb412af3fbf31cfd2163a601514c5a0c011c572aef0f0101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff08045a0c011c022003ffffffff0100f2052a01000000434104c5b694d72e601091fd733c6b18b94795c13e2db6b1474747e7be914b407854cad37cee3058f85373b9f9dbb0014e541c45851d5f85e83a1fd7c45e54423718f3ac00000000', 'hex')).header;
  var header = preObjectHeader.toObject();
  beforeEach(function() {
    sandbox = sinon.sandbox.create();
    headerService = new HeaderService({
      node: {
        services: []
      }
    });
    headerService._encoding = new Encoding(new Buffer('0000', 'hex'));
  });

  afterEach(function() {
    sandbox.restore();
  });
github bitpay / bitcore-node / lib / services / bitcoind / index.js View on Github external
Bitcoin.prototype._zmqRawBlockHandler = function(message) {

  var block = new bitcore.Block(message);
  this.tiphash = block.hash;
  this.height++;
  block.__height = this.height;
  block.height = this.height;

  for (var i = 0; i < this.subscriptions.rawblock.length; i++) {
    this.subscriptions.rawblock[i].emit('bitcoind/rawblock', block);
  }

};
github poetapp / poet-js / src / Insight.ts View on Github external
getBlock = async (hash: string): Promise => {
    const response = await fetch(`${this.url}/rawblock/${hash}`)

    if (!response.ok) throwError(await response.text())

    const json = await response.json()

    return new bitcore.Block(Buffer.from(json.rawblock, 'hex'))
  }
}
github poetapp / node / src / Helpers / Insight.ts View on Github external
getBlock = async (hash: string): Promise => {
    const response = await fetch(`${this.url}/rawblock/${hash}`)

    if (!response.ok)
      throwError(await response.text())

    const json = await response.json()

    return new bitcore.Block(Buffer.from(json.rawblock, 'hex'))
  }
}
github bitpay / bitcore-wallet-service / lib / blockchainmonitor.js View on Github external
BlockchainMonitor.prototype._processBlockData = function(network, data, cb) {
  var self = this;

  var block = new Bitcore.Block(new Buffer(data.rawblock, 'hex'));
  log.debug('Processing block ' + network + ' ' + block.hash);

  var txs = block.toObject().transactions;

  var allAddresses = {};
  _.each(txs, function(tx) {
    _.each(tx.outputs, function(o) {
      if (o.script) {
        var s = new Bitcore.Script(new Buffer(o.script, 'hex'));
        var a = s.toAddress(network);
        if (a) {
          allAddresses[a] = true;
        }
      }
    });
  });
github decentralized-identity / sidetree / lib / bitcoin / BitcoinClient.ts View on Github external
private static createBlockFromBuffer (buffer: Buffer): Block {
    return new Block(buffer);
  }