All files / src/api/methods getTransactionReceipt.js

100% Statements 15/15
75% Branches 3/4
100% Functions 3/3
100% Lines 13/13

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 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51            3x 3x 3x   3x 2x 2x   1x   1x   1x   1x   1x           3x           1x                                
/**
 * Copyright (c) 2019-present, Leap DAO (leapdao.org)
 *
 * This source code is licensed under the Mozilla Public License Version 2.0
 * found in the LICENSE file in the root directory of this source tree.
 */
const { bufferToHex } = require('ethereumjs-util');
const { Tx } = require('leap-core');
const getPrevTx = require('./utils/getPrevTx');
 
module.exports = async (db, hash) => {
  const txDoc = await db.getTransaction(hash);
  if (!txDoc) return null;
 
  const { txData, blockHash, height, txPos, logs } = txDoc;
 
  const tx = Tx.fromJSON(txData);
 
  const prevTx = await getPrevTx(db, tx);
 
  const blockNumber = `0x${height.toString(16)}`;
 
  const txLogs = (logs || []).map((log, i) => ({
    transactionLogIndex: i,
    transactionIndex: txPos,
    blockNumber,
    transactionHash: hash,
    address: bufferToHex(Buffer.from(log[0])),
    topics: log[1].map(e => bufferToHex(Buffer.from(e))),
    data: bufferToHex(Buffer.from(log[2])),
    logIndex: 0,
    blockHash,
  }));
 
  return {
    transactionHash: hash,
    transactionIndex: txPos,
    blockHash,
    blockNumber,
    from: tx.from(prevTx),
    to: tx.to(),
    raw: tx.hex(),
    cumulativeGasUsed: '0x0',
    gasUsed: '0x0',
    contractAddress: null,
    logs: txLogs,
    logsBloom: '0x',
    status: '0x1',
  };
};