import { Address } from 'web3x/address' ; import { sha3Buffer } from 'web3x/utils' ; import { recoverTransactionSender , serializeTx , serializeTxReceipt , Tx , TxReceipt } from '../tx' ; import { executeTransaction , ExTxContext , ExTxResult } from '../vm' ; import { WorldState } from '../world' ; import { BlockchainContext } from './blockchain' ; export interface EvaluatedTx { tx : Tx ; serializedTx : Buffer ; txHash : Buffer ; receipt : TxReceipt ; serializedReceipt : Buffer ; sender : Address ; result : ExTxResult ; } export async function evaluateTxs ( worldState , blockchainContext , txs , sender ? ) { let cumulativeGasUsed = BigInt ( 0 ) ; const evaluatedTxs = [ ] ; for ( const tx of txs ) { const serializedTx = serializeTx ( tx ) ; const txHash = sha3Buffer ( serializedTx ) ; sender = sender || recoverTransactionSender ( tx ) ; const exTxContext = { worldState , blockchainContext , sender , } ; const result = await executeTransaction ( exTxContext , tx ) ; cumulativeGasUsed += tx . gasLimit - result . remainingGas ; const receipt = { cumulativeGasUsed , logs : result . txSubstrate ? result . txSubstrate . logs : [ ] , logsBloomFilter : Buffer . of ( ) , status : ! result . reverted , } ; const serializedReceipt = serializeTxReceipt ( receipt ) ; const evaluatedTx = { tx , serializedTx , receipt , serializedReceipt , sender , txHash , result , } ; evaluatedTxs . push ( evaluatedTx ) ; } return evaluatedTxs ; }