github.com/lmittmann/w3@v0.20.0/w3types/rpc.go (about)

     1  package w3types
     2  
     3  import (
     4  	"encoding/json"
     5  	"math/big"
     6  
     7  	"github.com/ethereum/go-ethereum/common"
     8  	"github.com/ethereum/go-ethereum/common/hexutil"
     9  )
    10  
    11  type BlockOverrides struct {
    12  	Number        *big.Int
    13  	Difficulty    *big.Int
    14  	Time          uint64
    15  	GasLimit      uint64
    16  	FeeRecipient  common.Address
    17  	PrevRandao    common.Hash
    18  	BaseFeePerGas *big.Int
    19  	BlobBaseFee   *big.Int
    20  }
    21  
    22  type blockOverrides struct {
    23  	Number        *hexutil.Big    `json:"number,omitempty"`
    24  	Difficulty    *hexutil.Big    `json:"difficulty,omitempty"`
    25  	Time          hexutil.Uint64  `json:"time,omitempty"`
    26  	GasLimit      hexutil.Uint64  `json:"gasLimit,omitempty"`
    27  	FeeRecipient  *common.Address `json:"feeRecipient,omitempty"` // TODO: omitzero (Go1.24)
    28  	PrevRandao    *common.Hash    `json:"prevRandao,omitempty"`   // TODO: omitzero (Go1.24)
    29  	BaseFeePerGas *hexutil.Big    `json:"baseFeePerGas,omitempty"`
    30  	BlobBaseFee   *hexutil.Big    `json:"blobBaseFee,omitempty"`
    31  }
    32  
    33  func (o BlockOverrides) MarshalJSON() ([]byte, error) {
    34  	dec := &blockOverrides{
    35  		Number:        (*hexutil.Big)(o.Number),
    36  		Difficulty:    (*hexutil.Big)(o.Difficulty),
    37  		Time:          hexutil.Uint64(o.Time),
    38  		GasLimit:      hexutil.Uint64(o.GasLimit),
    39  		BaseFeePerGas: (*hexutil.Big)(o.BaseFeePerGas),
    40  		BlobBaseFee:   (*hexutil.Big)(o.BlobBaseFee),
    41  	}
    42  	if o.FeeRecipient != (common.Address{}) {
    43  		dec.FeeRecipient = &o.FeeRecipient
    44  	}
    45  	if o.PrevRandao != (common.Hash{}) {
    46  		dec.PrevRandao = &o.PrevRandao
    47  	}
    48  	return json.Marshal(dec)
    49  }