import { toHex } from '../encoding/toHex.js' import type { ErrorType } from '../errors/utils.js' import type { Log, RpcLog } from '../types/log.js' export type FromRpcLogErrorType = ErrorType export function fromRpcLog( log: RpcLog, { args, eventName, }: { args?: unknown | undefined; eventName?: string | undefined } = {}, ): Log { return { ...log, blockHash: log.blockHash ? log.blockHash : null, blockNumber: log.blockNumber ? BigInt(log.blockNumber) : null, logIndex: log.logIndex ? Number(log.logIndex) : null, transactionHash: log.transactionHash ? log.transactionHash : null, transactionIndex: log.transactionIndex ? Number(log.transactionIndex) : null, ...(eventName ? { args, eventName } : {}), } } export type ToRpcLogErrorType = ErrorType export function toRpcLog( log: Log, ): RpcLog { return { ...log, blockNumber: log.blockNumber ? toHex(log.blockNumber) : null, logIndex: log.logIndex ? toHex(log.logIndex) : null, transactionIndex: log.transactionIndex ? toHex(log.transactionIndex) : null, } as RpcLog }