types

package
v0.15.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 20, 2025 License: GPL-3.0, LGPL-3.0 Imports: 20 Imported by: 134

Documentation

Overview

Package types provides type aliases to ethereum types This ensures compatibility with ethereum interfaces while allowing our own extensions

Index

Constants

View Source
const (
	// Transaction types
	LegacyTxType     = ethtypes.LegacyTxType
	AccessListTxType = ethtypes.AccessListTxType
	DynamicFeeTxType = ethtypes.DynamicFeeTxType
	BlobTxType       = ethtypes.BlobTxType

	// Receipt status
	ReceiptStatusFailed     = ethtypes.ReceiptStatusFailed
	ReceiptStatusSuccessful = ethtypes.ReceiptStatusSuccessful
)

Constants

View Source
const (
	BloomBitLength  = ethtypes.BloomBitLength
	BloomByteLength = ethtypes.BloomByteLength
)

Constants for bloom filters

Variables

View Source
var (
	// Hashes
	EmptyRootHash        = ethtypes.EmptyRootHash
	EmptyCodeHash        = ethtypes.EmptyCodeHash
	EmptyTxsHash         = ethtypes.EmptyTxsHash
	EmptyReceiptsHash    = ethtypes.EmptyReceiptsHash
	EmptyWithdrawalsHash = ethtypes.EmptyWithdrawalsHash

	// Errors
	ErrInvalidSig           = ethtypes.ErrInvalidSig
	ErrUnexpectedProtection = ethtypes.ErrUnexpectedProtection
	ErrInvalidTxType        = ethtypes.ErrInvalidTxType
	ErrTxTypeNotSupported   = ethtypes.ErrTxTypeNotSupported
	ErrGasFeeCapTooLow      = ethtypes.ErrGasFeeCapTooLow
	ErrInvalidChainId       = ethtypes.ErrInvalidChainId
)

Variables

View Source
var (
	// Transaction creation
	NewTx               = ethtypes.NewTx
	NewTransaction      = ethtypes.NewTransaction
	NewContractCreation = ethtypes.NewContractCreation

	// Signing
	SignTx                 = ethtypes.SignTx
	SignNewTx              = ethtypes.SignNewTx
	MustSignNewTx          = ethtypes.MustSignNewTx
	Sender                 = ethtypes.Sender
	LatestSigner           = ethtypes.LatestSigner
	LatestSignerForChainID = ethtypes.LatestSignerForChainID
	NewEIP155Signer        = ethtypes.NewEIP155Signer
	NewLondonSigner        = ethtypes.NewLondonSigner
	NewCancunSigner        = ethtypes.NewCancunSigner
	MakeSigner             = ethtypes.MakeSigner

	// Block functions
	CalcUncleHash = ethtypes.CalcUncleHash
	DeriveSha     = ethtypes.DeriveSha
)

Functions

View Source
var ErrInvalidChainId = errors.New("invalid chain id for signer")
View Source
var (
	NewEmptyStateAccount = ethtypes.NewEmptyStateAccount
)

Functions for accounts

Functions

func DeriveSha

func DeriveSha(list DerivableList, hasher TrieHasher) common.Hash

DeriveSha creates the tree hashes of transactions, receipts, and withdrawals in a block header.

func Sender

func Sender(signer Signer, tx *Transaction) (common.Address, error)

Sender returns the address derived from the signature (V, R, S) using secp256k1 elliptic curve and an error if it failed deriving or upon an incorrect signature.

Sender may cache the address, allowing it to be used regardless of signing method. The cache is invalidated if the cached signer does not match the signer used in the current call.

Types

type AccessList

type AccessList []AccessTuple

AccessList is an EIP-2930 access list.

func (AccessList) StorageKeys

func (al AccessList) StorageKeys() int

StorageKeys returns the total number of storage keys in the access list.

type AccessListTx

type AccessListTx struct {
	ChainID    *big.Int        // destination chain ID
	Nonce      uint64          // nonce of sender account
	GasPrice   *big.Int        // wei per gas
	Gas        uint64          // gas limit
	To         *common.Address `rlp:"nil"` // nil means contract creation
	Value      *big.Int        // wei amount
	Data       []byte          // contract invocation input data
	AccessList AccessList      // EIP-2930 access list
	V, R, S    *big.Int        // signature values
}

AccessListTx is the data of EIP-2930 access list transactions.

type AccessTuple

type AccessTuple struct {
	Address     common.Address `json:"address"     gencodec:"required"`
	StorageKeys []common.Hash  `json:"storageKeys" gencodec:"required"`
}

AccessTuple is the element type of an access list.

type Account

type Account struct {
	Code    []byte                      `json:"code,omitempty"`
	Storage map[common.Hash]common.Hash `json:"storage,omitempty"`
	Balance *big.Int                    `json:"balance" gencodec:"required"`
	Nonce   uint64                      `json:"nonce,omitempty"`

	// used in tests
	PrivateKey []byte `json:"secretKey,omitempty"`
}

Account represents an Ethereum account and its attached data. This type is used to specify accounts in the genesis block state, and is also useful for JSON encoding/decoding of accounts.

type BlobTx

type BlobTx struct {
	ChainID    *uint256.Int
	Nonce      uint64
	GasTipCap  *uint256.Int // a.k.a. maxPriorityFeePerGas
	GasFeeCap  *uint256.Int // a.k.a. maxFeePerGas
	Gas        uint64
	To         common.Address
	Value      *uint256.Int
	Data       []byte
	AccessList AccessList
	BlobFeeCap *uint256.Int // a.k.a. maxFeePerBlobGas
	BlobHashes []common.Hash

	// A blob transaction can optionally contain blobs. This field must be set when BlobTx
	// is used to create a transaction for signing.
	Sidecar *BlobTxSidecar `rlp:"-"`

	// Signature values
	V *uint256.Int `json:"v" gencodec:"required"`
	R *uint256.Int `json:"r" gencodec:"required"`
	S *uint256.Int `json:"s" gencodec:"required"`
}

BlobTx represents an EIP-4844 transaction.

type BlobTxSidecar

type BlobTxSidecar struct {
	Blobs       []kzg4844.Blob       // Blobs needed by the blob pool
	Commitments []kzg4844.Commitment // Commitments needed by the blob pool
	Proofs      []kzg4844.Proof      // Proofs needed by the blob pool
}

BlobTxSidecar contains the blobs of a blob transaction.

func (*BlobTxSidecar) BlobHashes

func (sc *BlobTxSidecar) BlobHashes() []common.Hash

BlobHashes computes the blob hashes of the given blobs.

type Block

type Block = ethtypes.Block

Block types

type BlockNonce

type BlockNonce = ethtypes.BlockNonce

Core types - direct aliases to ethereum types

type Bloom

type Bloom = ethtypes.Bloom

Core types - direct aliases to ethereum types

type Body

type Body = ethtypes.Body

Core types - direct aliases to ethereum types

type DerivableList

type DerivableList interface {
	Len() int
	EncodeIndex(int, *bytes.Buffer)
}

DerivableList is the input to DeriveSha. It is implemented by the 'Transactions' and 'Receipts' types. This is internal, do not use these methods.

type DynamicFeeTx

type DynamicFeeTx struct {
	ChainID    *big.Int
	Nonce      uint64
	GasTipCap  *big.Int // a.k.a. maxPriorityFeePerGas
	GasFeeCap  *big.Int // a.k.a. maxFeePerGas
	Gas        uint64
	To         *common.Address `rlp:"nil"` // nil means contract creation
	Value      *big.Int
	Data       []byte
	AccessList AccessList

	// Signature values
	V *big.Int `json:"v" gencodec:"required"`
	R *big.Int `json:"r" gencodec:"required"`
	S *big.Int `json:"s" gencodec:"required"`
}

DynamicFeeTx represents an EIP-1559 transaction.

type EIP155Signer

type EIP155Signer struct {
	// contains filtered or unexported fields
}

EIP155Signer implements Signer using the EIP-155 rules. This accepts transactions which are replay-protected as well as unprotected homestead transactions.

func NewEIP155Signer

func NewEIP155Signer(chainId *big.Int) EIP155Signer

func (EIP155Signer) ChainID

func (s EIP155Signer) ChainID() *big.Int

func (EIP155Signer) Equal

func (s EIP155Signer) Equal(s2 Signer) bool

func (EIP155Signer) Hash

func (s EIP155Signer) Hash(tx *Transaction) common.Hash

Hash returns the hash to be signed by the sender. It does not uniquely identify the transaction.

func (EIP155Signer) Sender

func (s EIP155Signer) Sender(tx *Transaction) (common.Address, error)

func (EIP155Signer) SignatureValues

func (s EIP155Signer) SignatureValues(tx *Transaction, sig []byte) (R, S, V *big.Int, err error)

SignatureValues returns signature values. This signature needs to be in the [R || S || V] format where V is 0 or 1.

type FrontierSigner

type FrontierSigner struct{}

FrontierSigner implements Signer interface using the frontier rules.

func (FrontierSigner) ChainID

func (s FrontierSigner) ChainID() *big.Int

func (FrontierSigner) Equal

func (s FrontierSigner) Equal(s2 Signer) bool

func (FrontierSigner) Hash

func (fs FrontierSigner) Hash(tx *Transaction) common.Hash

Hash returns the hash to be signed by the sender. It does not uniquely identify the transaction.

func (FrontierSigner) Sender

func (fs FrontierSigner) Sender(tx *Transaction) (common.Address, error)

func (FrontierSigner) SignatureValues

func (fs FrontierSigner) SignatureValues(tx *Transaction, sig []byte) (r, s, v *big.Int, err error)

SignatureValues returns signature values. This signature needs to be in the [R || S || V] format where V is 0 or 1.

type FullAccount

type FullAccount = StateAccount

FullAccount is StateAccount in newer versions

type GenesisAccount added in v0.15.4

type GenesisAccount struct {
	Code       []byte                      `json:"code,omitempty"`
	Storage    map[common.Hash]common.Hash `json:"storage,omitempty"`
	Balance    *big.Int                    `json:"balance" gencodec:"required"`
	MCBalance  GenesisMultiCoinBalance     `json:"mcbalance,omitempty"`
	Nonce      uint64                      `json:"nonce,omitempty"`
	PrivateKey []byte                      `json:"secretKey,omitempty"` // for tests
}

GenesisAccount is an account in the state of the genesis block.

type GenesisAlloc

type GenesisAlloc map[common.Address]GenesisAccount

GenesisAlloc specifies the initial state of a genesis block.

func (*GenesisAlloc) UnmarshalJSON

func (ga *GenesisAlloc) UnmarshalJSON(data []byte) error

type GenesisMultiCoinBalance added in v0.15.4

type GenesisMultiCoinBalance map[common.Hash]*big.Int
type Header = ethtypes.Header

Core types - direct aliases to ethereum types

type HomesteadSigner

type HomesteadSigner struct{ FrontierSigner }

HomesteadSigner implements Signer interface using the homestead rules.

func (HomesteadSigner) ChainID

func (s HomesteadSigner) ChainID() *big.Int

func (HomesteadSigner) Equal

func (s HomesteadSigner) Equal(s2 Signer) bool

func (HomesteadSigner) Sender

func (hs HomesteadSigner) Sender(tx *Transaction) (common.Address, error)

func (HomesteadSigner) SignatureValues

func (hs HomesteadSigner) SignatureValues(tx *Transaction, sig []byte) (r, s, v *big.Int, err error)

SignatureValues returns signature values. This signature needs to be in the [R || S || V] format where V is 0 or 1.

type LegacyTx

type LegacyTx struct {
	Nonce    uint64          // nonce of sender account
	GasPrice *big.Int        // wei per gas
	Gas      uint64          // gas limit
	To       *common.Address `rlp:"nil"` // nil means contract creation
	Value    *big.Int        // wei amount
	Data     []byte          // contract invocation input data
	V, R, S  *big.Int        // signature values
}

LegacyTx is the transaction data of the original Ethereum transactions.

type Log

type Log = ethtypes.Log

Core types - direct aliases to ethereum types

type Receipt

type Receipt = ethtypes.Receipt

Receipt types

type Receipts

type Receipts = ethtypes.Receipts

Core types - direct aliases to ethereum types

type Signer

type Signer interface {
	// Sender returns the sender address of the transaction.
	Sender(tx *Transaction) (common.Address, error)

	// SignatureValues returns the raw R, S, V values corresponding to the
	// given signature.
	SignatureValues(tx *Transaction, sig []byte) (r, s, v *big.Int, err error)
	ChainID() *big.Int

	// Hash returns 'signature hash', i.e. the transaction hash that is signed by the
	// private key. This hash does not uniquely identify the transaction.
	Hash(tx *Transaction) common.Hash

	// Equal returns true if the given signer is the same as the receiver.
	Equal(Signer) bool
}

Signer encapsulates transaction signature handling. The name of this type is slightly misleading because Signers don't actually sign, they're just for validating and processing of signatures.

Note that this interface is not a stable API and may change at any time to accommodate new protocol rules.

func LatestSigner

func LatestSigner(config *params.ChainConfig) Signer

LatestSigner returns the 'most permissive' Signer available for the given chain configuration. Specifically, this enables support of all types of transactions when their respective forks are scheduled to occur at any block number (or time) in the chain config.

Use this in transaction-handling code where the current block number is unknown. If you have the current block number available, use MakeSigner instead.

func LatestSignerForChainID

func LatestSignerForChainID(chainID *big.Int) Signer

LatestSignerForChainID returns the 'most permissive' Signer available. Specifically, this enables support for EIP-155 replay protection and all implemented EIP-2718 transaction types if chainID is non-nil.

Use this in transaction-handling code where the current block number and fork configuration are unknown. If you have a ChainConfig, use LatestSigner instead. If you have a ChainConfig and know the current block number, use MakeSigner instead.

func MakeSigner

func MakeSigner(config *params.ChainConfig, blockNumber *big.Int, blockTime uint64) Signer

MakeSigner returns a Signer based on the given chain config and block number or time.

func NewCancunSigner

func NewCancunSigner(chainId *big.Int) Signer

NewCancunSigner returns a signer that accepts - EIP-4844 blob transactions - EIP-1559 dynamic fee transactions - EIP-2930 access list transactions, - EIP-155 replay protected transactions, and - legacy Homestead transactions.

func NewEIP2930Signer

func NewEIP2930Signer(chainId *big.Int) Signer

NewEIP2930Signer returns a signer that accepts EIP-2930 access list transactions, EIP-155 replay protected transactions, and legacy Homestead transactions.

func NewLondonSigner

func NewLondonSigner(chainId *big.Int) Signer

NewLondonSigner returns a signer that accepts - EIP-1559 dynamic fee transactions - EIP-2930 access list transactions, - EIP-155 replay protected transactions, and - legacy Homestead transactions.

type StateAccount

type StateAccount = ethtypes.StateAccount

Additional aliases for missing types

type Transaction

type Transaction = ethtypes.Transaction

Transaction types

func MustSignNewTx

func MustSignNewTx(prv *ecdsa.PrivateKey, s Signer, txdata TxData) *Transaction

MustSignNewTx creates a transaction and signs it. This panics if the transaction cannot be signed.

func NewContractCreation

func NewContractCreation(nonce uint64, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte) *Transaction

NewContractCreation creates an unsigned legacy transaction. Deprecated: use NewTx instead.

func NewTransaction

func NewTransaction(nonce uint64, to common.Address, amount *big.Int, gasLimit uint64, gasPrice *big.Int, data []byte) *Transaction

NewTransaction creates an unsigned legacy transaction. Deprecated: use NewTx instead.

func SignNewTx

func SignNewTx(prv *ecdsa.PrivateKey, s Signer, txdata TxData) (*Transaction, error)

SignNewTx creates a transaction and signs it.

func SignTx

func SignTx(tx *Transaction, s Signer, prv *ecdsa.PrivateKey) (*Transaction, error)

SignTx signs the transaction using the given signer and private key.

func (*Transaction) MarshalJSON

func (tx *Transaction) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON with a hash.

func (*Transaction) UnmarshalJSON

func (tx *Transaction) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type Transactions

type Transactions = ethtypes.Transactions

Core types - direct aliases to ethereum types

type TrieHasher

type TrieHasher interface {
	Reset()
	Update([]byte, []byte) error
	Hash() common.Hash
}

TrieHasher is the tool used to calculate the hash of derivable list. This is internal, do not use.

type TxByNonce

type TxByNonce = ethtypes.TxByNonce

Core types - direct aliases to ethereum types

type TxData

type TxData = ethtypes.TxData

Core types - direct aliases to ethereum types

type Withdrawal

type Withdrawal = ethtypes.Withdrawal

Core types - direct aliases to ethereum types

type Withdrawals

type Withdrawals = ethtypes.Withdrawals

Core types - direct aliases to ethereum types

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL