Documentation
¶
Index ¶
- func BlockGasCost(b *ethtypes.Block) *big.Int
- func BlockMinDelayExcess(b *ethtypes.Block) *acp226.DelayExcess
- func BlockTime(eth *ethtypes.Header) time.Time
- func BlockTimeMilliseconds(b *ethtypes.Block) *uint64
- func HeaderTimeMilliseconds(h *ethtypes.Header) uint64
- func Register()
- func SetHeaderExtra(h *ethtypes.Header, extra *HeaderExtra)
- func WithHeaderExtra(h *ethtypes.Header, extra *HeaderExtra) *ethtypes.Header
- func WithTempRegisteredExtras(lock libevm.ExtrasLock, fn func() error) error
- type HeaderExtra
- func (h *HeaderExtra) DecodeJSON(eth *ethtypes.Header, input []byte) error
- func (h *HeaderExtra) DecodeRLP(eth *ethtypes.Header, stream *rlp.Stream) error
- func (h *HeaderExtra) EncodeJSON(eth *ethtypes.Header) ([]byte, error)
- func (h *HeaderExtra) EncodeRLP(eth *ethtypes.Header, writer io.Writer) error
- func (h *HeaderExtra) PostCopy(dst *ethtypes.Header)
- type HeaderSerializable
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BlockMinDelayExcess ¶ added in v0.8.0
func BlockMinDelayExcess(b *ethtypes.Block) *acp226.DelayExcess
func BlockTimeMilliseconds ¶ added in v0.8.0
func HeaderTimeMilliseconds ¶ added in v0.8.0
HeaderTimeMilliseconds returns the header timestamp in milliseconds. If the header has the Granite field TimeMilliseconds set in extras, it is used. Otherwise, it falls back to seconds-based Time multiplied by 1000.
func Register ¶ added in v0.8.0
func Register()
Register registers the types with libevm. It MUST NOT be called more than once and therefore is only allowed to be used in tests and `package main`, to avoid polluting other packages that transitively depend on this one but don't need registration.
Without a call to Register, none of the functionality of this package will work, and most will simply panic.
func SetHeaderExtra ¶
func SetHeaderExtra(h *ethtypes.Header, extra *HeaderExtra)
SetHeaderExtra sets the given HeaderExtra on the [Header].
func WithHeaderExtra ¶
func WithHeaderExtra(h *ethtypes.Header, extra *HeaderExtra) *ethtypes.Header
WithHeaderExtra sets the given HeaderExtra on the [Header] and returns the [Header] for chaining.
func WithTempRegisteredExtras ¶ added in v0.8.0
func WithTempRegisteredExtras(lock libevm.ExtrasLock, fn func() error) error
WithTempRegisteredExtras runs `fn` with temporary registration otherwise equivalent to a call to [RegisterExtras], but limited to the life of `fn`.
This function is not intended for direct use. Use `evm.WithTempRegisteredLibEVMExtras()` instead as it calls this along with all other temporary-registration functions.
Types ¶
type HeaderExtra ¶
type HeaderExtra struct {
BlockGasCost *big.Int
TimeMilliseconds *uint64
MinDelayExcess *acp226.DelayExcess
}
HeaderExtra is a struct that contains extra fields used by Subnet-EVM in the block header. This type uses HeaderSerializable to encode and decode the extra fields along with the upstream type for compatibility with existing network blocks.
func GetHeaderExtra ¶
func GetHeaderExtra(h *ethtypes.Header) *HeaderExtra
GetHeaderExtra returns the HeaderExtra from the given [Header].
func (*HeaderExtra) DecodeJSON ¶
func (h *HeaderExtra) DecodeJSON(eth *ethtypes.Header, input []byte) error
DecodeJSON JSON decodes from the `input` bytes and writes the output to both the ethtypes.Header passed as argument and to the receiver HeaderExtra.
func (*HeaderExtra) DecodeRLP ¶
DecodeRLP RLP decodes from the *rlp.Stream and writes the output to both the ethtypes.Header passed as argument and to the receiver HeaderExtra.
func (*HeaderExtra) EncodeJSON ¶
func (h *HeaderExtra) EncodeJSON(eth *ethtypes.Header) ([]byte, error)
EncodeJSON JSON encodes the given ethtypes.Header and HeaderExtra together to the `writer`. It does merge both structs into a single HeaderSerializable.
func (*HeaderExtra) EncodeRLP ¶
EncodeRLP RLP encodes the given ethtypes.Header and HeaderExtra together to the `writer`. It does merge both structs into a single HeaderSerializable.
func (*HeaderExtra) PostCopy ¶
func (h *HeaderExtra) PostCopy(dst *ethtypes.Header)
type HeaderSerializable ¶
type HeaderSerializable struct {
ParentHash common.Hash `json:"parentHash" gencodec:"required"`
UncleHash common.Hash `json:"sha3Uncles" gencodec:"required"`
Coinbase common.Address `json:"miner" gencodec:"required"`
Root common.Hash `json:"stateRoot" gencodec:"required"`
TxHash common.Hash `json:"transactionsRoot" gencodec:"required"`
ReceiptHash common.Hash `json:"receiptsRoot" gencodec:"required"`
Bloom ethtypes.Bloom `json:"logsBloom" gencodec:"required"`
Difficulty *big.Int `json:"difficulty" gencodec:"required"`
Number *big.Int `json:"number" gencodec:"required"`
GasLimit uint64 `json:"gasLimit" gencodec:"required"`
GasUsed uint64 `json:"gasUsed" gencodec:"required"`
Time uint64 `json:"timestamp" gencodec:"required"`
Extra []byte `json:"extraData" gencodec:"required"`
MixDigest common.Hash `json:"mixHash"`
Nonce ethtypes.BlockNonce `json:"nonce"`
// BaseFee was added by EIP-1559 and is ignored in legacy headers.
BaseFee *big.Int `json:"baseFeePerGas" rlp:"optional"`
// BlockGasCost was added by SubnetEVM and is ignored in legacy
// headers.
BlockGasCost *big.Int `json:"blockGasCost" rlp:"optional"`
// BlobGasUsed was added by EIP-4844 and is ignored in legacy headers.
BlobGasUsed *uint64 `json:"blobGasUsed" rlp:"optional"`
// ExcessBlobGas was added by EIP-4844 and is ignored in legacy headers.
ExcessBlobGas *uint64 `json:"excessBlobGas" rlp:"optional"`
// ParentBeaconRoot was added by EIP-4788 and is ignored in legacy headers.
ParentBeaconRoot *common.Hash `json:"parentBeaconBlockRoot" rlp:"optional"`
// TimeMilliseconds was added by Granite and is ignored in legacy headers.
TimeMilliseconds *uint64 `json:"timestampMilliseconds" rlp:"optional"`
// MinDelayExcess was added by Granite and is ignored in legacy headers.
// We use *uint64 type here to avoid rlpgen generating incorrect code
MinDelayExcess *uint64 `json:"minDelayExcess" rlp:"optional"`
}
HeaderSerializable defines the header of a block in the Ethereum blockchain, as it is to be serialized into RLP and JSON. Note it must be exported so that rlpgen can generate the serialization code from it.
func (*HeaderSerializable) Hash ¶
func (h *HeaderSerializable) Hash() common.Hash
Hash returns the block hash of the header, which is simply the keccak256 hash of its RLP encoding. This function MUST be exported and is used in [HeaderSerializable.EncodeJSON] which is generated to the file gen_header_json.go.
func (HeaderSerializable) MarshalJSON ¶
func (h HeaderSerializable) MarshalJSON() ([]byte, error)
MarshalJSON marshals as JSON.
func (*HeaderSerializable) UnmarshalJSON ¶
func (h *HeaderSerializable) UnmarshalJSON(input []byte) error
UnmarshalJSON unmarshals from JSON.