import { tinyBig, toChecksumAddress } from "../.."; import type { Log, RPCLog, RPCTransactionReceipt, TransactionReceipt, } from "../../types/Transaction.types"; import { cleanLog } from "./cleanLog"; import { cleanTransaction } from "./cleanTransaction"; import { hexToDecimal } from "./hexToDecimal"; /** * Converts RPC transaction receipt response to more JS-friendly format */ export function cleanTransactionReceipt( transactionReceipt: RPCTransactionReceipt ): TransactionReceipt { const cleanedTransaction = cleanTransaction(transactionReceipt as any); const cleanedTransactionReceipt = { ...cleanedTransaction, } as unknown as TransactionReceipt; ( Object.keys(transactionReceipt) as Array ).forEach((key) => { if (!transactionReceipt[key]) return; switch (key) { case "status": cleanedTransactionReceipt[key] = Number( hexToDecimal(transactionReceipt[key]) ); break; case "contractAddress": if (transactionReceipt[key]) { cleanedTransactionReceipt[key] = toChecksumAddress( transactionReceipt[key] ); } break; case "cumulativeGasUsed": case "effectiveGasPrice": case "gasUsed": cleanedTransactionReceipt[key] = tinyBig( hexToDecimal(transactionReceipt[key]) ); break; case "logs": transactionReceipt[key].forEach((log: RPCLog, index: number) => { cleanedTransactionReceipt[key][index] = cleanLog(log, true) as Log; }); } }); cleanedTransactionReceipt.byzantium = cleanedTransactionReceipt.blockNumber >= 4370000; return cleanedTransactionReceipt; }