github.com/ethereum/go-ethereum@v1.14.4-0.20240516095835-473ee8fc07a3/eth/tracers/internal/tracetest/util.go (about) 1 package tracetest 2 3 import ( 4 "math/big" 5 "strings" 6 "unicode" 7 8 "github.com/ethereum/go-ethereum/common" 9 "github.com/ethereum/go-ethereum/common/math" 10 "github.com/ethereum/go-ethereum/consensus/misc/eip4844" 11 "github.com/ethereum/go-ethereum/core" 12 "github.com/ethereum/go-ethereum/core/vm" 13 14 // Force-load native and js packages, to trigger registration 15 _ "github.com/ethereum/go-ethereum/eth/tracers/js" 16 _ "github.com/ethereum/go-ethereum/eth/tracers/native" 17 ) 18 19 // camel converts a snake cased input string into a camel cased output. 20 func camel(str string) string { 21 pieces := strings.Split(str, "_") 22 for i := 1; i < len(pieces); i++ { 23 pieces[i] = string(unicode.ToUpper(rune(pieces[i][0]))) + pieces[i][1:] 24 } 25 return strings.Join(pieces, "") 26 } 27 28 type callContext struct { 29 Number math.HexOrDecimal64 `json:"number"` 30 Difficulty *math.HexOrDecimal256 `json:"difficulty"` 31 Time math.HexOrDecimal64 `json:"timestamp"` 32 GasLimit math.HexOrDecimal64 `json:"gasLimit"` 33 Miner common.Address `json:"miner"` 34 BaseFee *math.HexOrDecimal256 `json:"baseFeePerGas"` 35 } 36 37 func (c *callContext) toBlockContext(genesis *core.Genesis) vm.BlockContext { 38 context := vm.BlockContext{ 39 CanTransfer: core.CanTransfer, 40 Transfer: core.Transfer, 41 Coinbase: c.Miner, 42 BlockNumber: new(big.Int).SetUint64(uint64(c.Number)), 43 Time: uint64(c.Time), 44 Difficulty: (*big.Int)(c.Difficulty), 45 GasLimit: uint64(c.GasLimit), 46 } 47 if genesis.Config.IsLondon(context.BlockNumber) { 48 context.BaseFee = (*big.Int)(c.BaseFee) 49 } 50 if genesis.ExcessBlobGas != nil && genesis.BlobGasUsed != nil { 51 excessBlobGas := eip4844.CalcExcessBlobGas(*genesis.ExcessBlobGas, *genesis.BlobGasUsed) 52 context.BlobBaseFee = eip4844.CalcBlobFee(excessBlobGas) 53 } 54 return context 55 }