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

To help you get started, we’ve selected a few bitcoinjs-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 mappum / blockchain-spv / test / blockStore.js View on Github external
function blockFromObject (obj) {
  var block = new bitcoinjs.Block()
  for (var k in obj) block[k] = obj[k]
  return block
}
github ipld / js-ipld / test / ipld-bitcoin.js View on Github external
const buildBitcoinBlock = (header) => {
  const block = new BitcoinBlock()
  block.version = header.version || 0
  block.prevHash = header.prevHash || Buffer.alloc(32)
  block.merkleRoot = header.merkleRoot || Buffer.alloc(32)
  block.timestamp = header.timestamp || 0
  block.bits = header.bits || 0
  block.nonce = header.nonce || 0
  return block
}
github etherex / btc-swap / src / btc-swap.js View on Github external
if (this.debug)
            console.error(errorMsg, json);
          failure(errorMsg);
          return;
        }

        data = json.data;
        if (!data || !data.tx) {
          errorMsg = "Not enough data in BTC block.";
          if (this.debug)
            console.error(errorMsg, data);
          failure(errorMsg);
          return;
        }

        var block = new bitcoin.Block();
        block.version = data.version;
        block.prevHash = bitcoin.bufferutils.reverse(new Buffer(data.previousblockhash, 'hex'));
        block.merkleRoot = bitcoin.bufferutils.reverse(new Buffer(data.merkleroot, 'hex'));
        block.timestamp = data.time;
        block.bits = parseInt(data.bits, 16);
        block.nonce = data.nonce;

        var blockHeader = web3.toAscii(block.toHex(true));

        if (this.debug) {
          console.log("BTC_BLOCK", block, block.toHex(true));
          console.log("BTC_BLOCK_BYTES", blockHeader, web3.toHex(blockHeader));
        }

        errorMsg = "Block header is invalid.";