# All files / src/api/methods getBlockByHash.js

100% Statements 13/13
100% Branches 7/7
100% Functions 2/2
100% Lines 11/11

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    281x
    1x

    1x
    4x
    3x
    3x

    2x
    2x
    2x

    2x

    2x

     const { Block } = require('leap-core');
    const txResponse = require('./txResponse');

    module.exports = async (db, hash, showFullTxs = false) => {
      if (!hash) return null;
      const blockDoc = await db.getBlock(hash);
      if (!blockDoc) return null;

      const { blockData } = blockDoc;
      const block = Block.fromJSON(blockData);
      const txs = !showFullTxs
        ? block.txHashList
        : await Promise.all(
            block.txList.map((tx, pos) =>
              txResponse(db, tx, block.hash(), block.height, pos)
            )
          );
      return {
        number: `0x${block.height.toString(16)}`,
        hash: block.hash(),
        parentHash: block.parent,
        size: `0x${block.hex().length.toString(16)}`,
        timestamp: `0x${block.timestamp.toString(16)}`,
        transactions: txs,
        uncles: [],
      };
    };