From 5b3e4ee6dfe15af657e3ed58077356b34e0d8cc0 Mon Sep 17 00:00:00 2001 From: Geoff Stuart Date: Mon, 23 Jan 2023 14:55:54 -0500 Subject: [PATCH] Refactor newEthTxReceipt --- node/impl/full/eth.go | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/node/impl/full/eth.go b/node/impl/full/eth.go index c7096a6e0f9..2264510c539 100644 --- a/node/impl/full/eth.go +++ b/node/impl/full/eth.go @@ -1697,8 +1697,27 @@ func newEthTxReceipt(ctx context.Context, tx ethtypes.EthTx, lookup *api.MsgLook LogsBloom: ethtypes.EmptyEthBloom[:], } - // V.Int will be nil for non-eth transactions, so we want to skip unmarshalling the create return. - if receipt.To == nil && lookup.Receipt.ExitCode.IsSuccess() && tx.V.Int != nil { + if lookup.Receipt.ExitCode.IsSuccess() { + receipt.Status = 1 + } + if lookup.Receipt.ExitCode.IsError() { + receipt.Status = 0 + } + + receipt.GasUsed = ethtypes.EthUint64(lookup.Receipt.GasUsed) + + // TODO: handle CumulativeGasUsed + receipt.CumulativeGasUsed = ethtypes.EmptyEthInt + + effectiveGasPrice := big.Div(replay.GasCost.TotalCost, big.NewInt(lookup.Receipt.GasUsed)) + receipt.EffectiveGasPrice = ethtypes.EthBigInt(effectiveGasPrice) + + // V.Int will be nil for non-eth transactions, so we want return here and skip eth-specific stuff + if tx.V.Int == nil { + return receipt, nil + } + + if receipt.To == nil && lookup.Receipt.ExitCode.IsSuccess() { // Create and Create2 return the same things. var ret eam.CreateExternalReturn if err := ret.UnmarshalCBOR(bytes.NewReader(lookup.Receipt.Return)); err != nil { @@ -1708,13 +1727,6 @@ func newEthTxReceipt(ctx context.Context, tx ethtypes.EthTx, lookup *api.MsgLook receipt.ContractAddress = &addr } - if lookup.Receipt.ExitCode.IsSuccess() { - receipt.Status = 1 - } - if lookup.Receipt.ExitCode.IsError() { - receipt.Status = 0 - } - if len(events) > 0 { // TODO return a dummy non-zero bloom to signal that there are logs // need to figure out how worth it is to populate with a real bloom @@ -1755,14 +1767,6 @@ func newEthTxReceipt(ctx context.Context, tx ethtypes.EthTx, lookup *api.MsgLook } } - receipt.GasUsed = ethtypes.EthUint64(lookup.Receipt.GasUsed) - - // TODO: handle CumulativeGasUsed - receipt.CumulativeGasUsed = ethtypes.EmptyEthInt - - effectiveGasPrice := big.Div(replay.GasCost.TotalCost, big.NewInt(lookup.Receipt.GasUsed)) - receipt.EffectiveGasPrice = ethtypes.EthBigInt(effectiveGasPrice) - return receipt, nil }