From 89082466fc63afccf2b35ed22d01093ae19ca57e Mon Sep 17 00:00:00 2001 From: i-norden Date: Wed, 1 Nov 2023 14:51:19 -0500 Subject: [PATCH] BlockOverride required by tracing endpoints --- pkg/eth/api.go | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/pkg/eth/api.go b/pkg/eth/api.go index ef4da70c..8709754f 100644 --- a/pkg/eth/api.go +++ b/pkg/eth/api.go @@ -27,7 +27,9 @@ import ( "strconv" "time" - "github.com/cerc-io/plugeth-statediff" + "github.com/ethereum/go-ethereum/core/vm" + + statediff "github.com/cerc-io/plugeth-statediff" "github.com/ethereum/go-ethereum/accounts/abi" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" @@ -1008,6 +1010,45 @@ func (diff *StateOverride) Apply(state *ipld_direct_state.StateDB) error { return nil } +// BlockOverrides is a set of header fields to override. +type BlockOverrides struct { + Number *hexutil.Big + Difficulty *hexutil.Big + Time *hexutil.Uint64 + GasLimit *hexutil.Uint64 + Coinbase *common.Address + Random *common.Hash + BaseFee *hexutil.Big +} + +// Apply overrides the given header fields into the given block context. +func (diff *BlockOverrides) Apply(blockCtx *vm.BlockContext) { + if diff == nil { + return + } + if diff.Number != nil { + blockCtx.BlockNumber = diff.Number.ToInt() + } + if diff.Difficulty != nil { + blockCtx.Difficulty = diff.Difficulty.ToInt() + } + if diff.Time != nil { + blockCtx.Time = uint64(*diff.Time) + } + if diff.GasLimit != nil { + blockCtx.GasLimit = uint64(*diff.GasLimit) + } + if diff.Coinbase != nil { + blockCtx.Coinbase = *diff.Coinbase + } + if diff.Random != nil { + blockCtx.Random = diff.Random + } + if diff.BaseFee != nil { + blockCtx.BaseFee = diff.BaseFee.ToInt() + } +} + // Call executes the given transaction on the state for the given block number. // // Additionally, the caller can specify a batch of contract for fields overriding.