Skip to content

Commit

Permalink
Refactor newEthTxReceipt
Browse files Browse the repository at this point in the history
  • Loading branch information
Geoff Stuart committed Jan 23, 2023
1 parent dd5f8b0 commit 5b3e4ee
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions node/impl/full/eth.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 5b3e4ee

Please sign in to comment.