# All files / src/api/methods/utils getPrevTx.js

100% Statements 9/9
100% Branches 7/7
100% Functions 1/1
100% Lines 9/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    157x
    7x

    7x
    13x
    8x
    8x
    8x
    7x

    6x

     const { Tx } = require('leap-core');
    const { bufferToHex } = require('ethereumjs-util');

    module.exports = async (db, tx) => {
      if (tx.inputs && tx.inputs.length > 0 && tx.inputs[0].prevout) {
        const prevTxHash = bufferToHex(tx.inputs[0].prevout.hash);
        const txDoc = await db.getTransaction(prevTxHash);
        if (txDoc) {
          return Tx.fromJSON(txDoc.txData);
        }
      }

      return null;
    };