Documentation
¶
Overview ¶
Package ethtypes provides a collection of common Ethereum types implemented in Go. These types are essential for building various tools and modules within the Ethereum ecosystem. The library aims to standardize and simplify the development process by offering a consistent set of types that can be reused across different projects.
Index ¶
- Constants
- Variables
- type AccessList
- type AccessListEntry
- type Account
- type Address
- type Block
- type Bloom
- type Hash
- type Header
- type Log
- type Nonce
- type Transaction
- func (t *Transaction) AccessList() []*AccessListEntry
- func (t *Transaction) ChainID() uint64
- func (t *Transaction) Cost() *big.Int
- func (t *Transaction) Data() []byte
- func (t *Transaction) Gas() uint64
- func (t *Transaction) GasPrice() *big.Int
- func (t *Transaction) Hash() Hash
- func (t *Transaction) MaxFeePerGas() *big.Int
- func (t *Transaction) MaxPriorityFeePerGas() *big.Int
- func (t *Transaction) Nonce() uint64
- func (t *Transaction) SigValues() (v, r, s *big.Int)
- func (t *Transaction) To() Address
- func (t *Transaction) Type() byte
- func (t *Transaction) Value() *big.Int
- type TransactionData
- type TxEIP1559
- type TxEIP2930
- type TxLegacy
Constants ¶
const ( TransactionLegacy = 0x00 Transaction2930 = 0x01 Transaction1559 = 0x02 )
Variables ¶
var ( ErrInvalidRLPChainID = errors.New("invalid chain ID RLP encoding") ErrInvalidRLPMaxPriorityFee = errors.New("invalid max priority fee per gas RLP encoding") ErrInvalidRLPMaxFeePerGas = errors.New("invalid max fee per gas RLP encoding") ErrInvalidRLPAccessList = errors.New("invalid access list RLP encoding") ErrInvalidRLPYParity = errors.New("invalid y parity param RLP encoding") )
var ( ErrInvalidRLPNonce = errors.New("invalid nonce RLP encoding") ErrInvalidRLPGasPrice = errors.New("invalid gas price RLP encoding") ErrInvalidRLPGasLimit = errors.New("invalid gas limit RLP encoding") ErrInvalidRLPValue = errors.New("invalid value RLP encoding") ErrInvalidRLPData = errors.New("invalid data RLP encoding") ErrInvalidRLPVParam = errors.New("invalid v sig param RLP encoding") ErrInvalidRLPRParam = errors.New("invalid r sig param RLP encoding") ErrInvalidRLPSParam = errors.New("invalid s sig param RLP encoding") )
var ZeroAddress = Address{}
ZeroAddress represents a placeholder address value that contains all zero bytes
var ZeroCodeHash = BytesToHash(keccak.New().Hash([]byte{}))
var ZeroHash = Hash{}
ZeroHash represents a placeholder hash value that contains all zero bytes
Functions ¶
This section is empty.
Types ¶
type AccessList ¶ added in v0.2.0
type AccessList []AccessListEntry
AccessList is a wrapper for access list entries
func (*AccessList) FromProto ¶ added in v0.2.0
func (l *AccessList) FromProto(protoList []*txProto.AccessListEntry)
FromProto parses the access list from the proto representation
func (*AccessList) FromRLP ¶ added in v0.2.0
func (l *AccessList) FromRLP(data []byte) error
FromRLP parses the RLP encoding of an access list
func (*AccessList) FromRLPValues ¶ added in v0.2.0
func (l *AccessList) FromRLPValues(listValues []ethrlp.Value) error
FromRLPValues parses the raw RLP values of an access list
func (AccessList) ToProto ¶ added in v0.2.0
func (l AccessList) ToProto() []*txProto.AccessListEntry
ToProto converts the access list to a proto representation
func (AccessList) ToRLP ¶ added in v0.2.0
func (l AccessList) ToRLP() []byte
ToRLP encodes the access list to RLP (RLP list)
type AccessListEntry ¶
AccessListEntry is a single access list entry, denoting the accessed storage keys (hashes) and address
func (*AccessListEntry) FromProto ¶ added in v0.2.0
func (e *AccessListEntry) FromProto(protoEntry *txProto.AccessListEntry)
FromProto parses the proto representation of an access list entry
func (*AccessListEntry) FromRLP ¶ added in v0.2.0
func (e *AccessListEntry) FromRLP(data []byte) error
FromRLP parses the RLP encoding of a single access list entry
func (AccessListEntry) ToProto ¶ added in v0.2.0
func (e AccessListEntry) ToProto() *txProto.AccessListEntry
ToProto converts the single access list entry to a proto representation
func (AccessListEntry) ToRLP ¶ added in v0.2.0
func (e AccessListEntry) ToRLP() []byte
ToRLP encodes the single access list entry to RLP (RLP Bytes)
type Account ¶ added in v0.2.0
type Address ¶
type Address [addressSize]byte
func BytesToAddress ¶
BytesToAddress converts the specified address bytes into an Address representation (20B)
func StringToAddress ¶
StringToAddress converts the specified address string into an Address representation
type Hash ¶
type Hash [hashSize]byte
func BytesToHash ¶
BytesToHash converts the specified hash bytes into a Hash representation (32B)
func StringToHash ¶
StringToHash converts the specified hash string into a Hash representation
type Transaction ¶
type Transaction struct {
// contains filtered or unexported fields
}
func (*Transaction) AccessList ¶ added in v0.2.0
func (t *Transaction) AccessList() []*AccessListEntry
func (*Transaction) ChainID ¶ added in v0.2.0
func (t *Transaction) ChainID() uint64
func (*Transaction) Cost ¶
func (t *Transaction) Cost() *big.Int
func (*Transaction) Data ¶ added in v0.2.0
func (t *Transaction) Data() []byte
func (*Transaction) Gas ¶ added in v0.2.0
func (t *Transaction) Gas() uint64
func (*Transaction) GasPrice ¶ added in v0.2.0
func (t *Transaction) GasPrice() *big.Int
func (*Transaction) Hash ¶ added in v0.2.0
func (t *Transaction) Hash() Hash
func (*Transaction) MaxFeePerGas ¶ added in v0.2.0
func (t *Transaction) MaxFeePerGas() *big.Int
func (*Transaction) MaxPriorityFeePerGas ¶ added in v0.2.0
func (t *Transaction) MaxPriorityFeePerGas() *big.Int
func (*Transaction) Nonce ¶ added in v0.2.0
func (t *Transaction) Nonce() uint64
func (*Transaction) SigValues ¶ added in v0.2.0
func (t *Transaction) SigValues() (v, r, s *big.Int)
func (*Transaction) To ¶ added in v0.2.0
func (t *Transaction) To() Address
To returns the To address of the transaction. If none is set (ex. contract deployment), it returns ZeroAddress
func (*Transaction) Type ¶ added in v0.2.0
func (t *Transaction) Type() byte
func (*Transaction) Value ¶ added in v0.2.0
func (t *Transaction) Value() *big.Int
type TransactionData ¶
type TransactionData interface {
// contains filtered or unexported methods
}
type TxEIP1559 ¶ added in v0.2.0
type TxEIP1559 struct {
ChainID *big.Int // the ID of the chain
MaxPriorityFeePerGas *big.Int // the max priority fee per gas
MaxFeePerGas *big.Int // the max fee per gas
Value *big.Int // value of the transfer (if any)
YParity, R, S *big.Int // the signature fields
To *[]byte // recipient address (nil means contract deployment)
Data []byte // data (payload) of the tx, if any
AccessList AccessList // the allowed access list for the tx, if any
Nonce uint64 // the sender nonce
Gas uint64 // the gas limit of the tx
}
TxEIP1559 represents a dynamic fee transaction, introduced as part of EIP-1559 (London hardfork) https://github.com/ethereum/EIPs/blob/master/EIPS/eip-1559.md
func (*TxEIP1559) FromRLP ¶ added in v0.2.0
FromRLP parses an EIP-1559 transaction from the transaction data RLP encoding. It expects the structure to be:
[chainID, nonce, maxPriorityFeePerGas, maxFeePerGas, gas, to, value, data, accessList, yParity, r, s] (12 elements)
func (*TxEIP1559) SignaturePayload ¶ added in v0.2.0
SignaturePayload constructs the EIP-1559 transaction signature payload. The signature payload (what's being signed) is the keccak of a specific RLP encoding.
RLP structure that needs to be constructed and keccak-ed later: rlp([chainID, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data, accessList])
The type of tx needs to be appended before keccaking (in this case 0x02, for EIP-1559 txs):
keccak256(0x02 || rlp([chainID, nonce, maxPriorityFeePerGas, maxFeePerGas, gasLimit, to, value, data, accessList]))
type TxEIP2930 ¶ added in v0.2.0
type TxEIP2930 struct {
ChainID *big.Int // the ID of the chain
GasPrice *big.Int // the gas price of the tx
Value *big.Int // value of the transfer (if any)
V, R, S *big.Int // the signature fields
To *[]byte // recipient address (nil means contract deployment)
Data []byte // data (payload) of the tx, if any
AccessList AccessList // the allowed access list of the tx, if any
Nonce uint64 // the sender nonce
Gas uint64 // the gas limit of the tx
}
TxEIP2930 represents an access list transaction, introduced as part of EIP-2930 https://github.com/ethereum/EIPs/blob/master/EIPS/eip-2930.md
func (*TxEIP2930) FromRLP ¶ added in v0.2.0
FromRLP parses an EIP-2930 transaction from the transaction data RLP encoding. It expects the structure to be:
[chainID, nonce, gasPrice, gas, to, value, data, accessList, yParity, r, s] (11 elements)
func (*TxEIP2930) SignaturePayload ¶ added in v0.2.0
SignaturePayload constructs the EIP-2930 transaction signature payload. The signature payload (what's being signed) is the keccak of a specific RLP encoding.
RLP structure that needs to be constructed and keccak-ed later: rlp([chainID, nonce, gasPrice, gas, to, value, data, accessList])
The type of tx needs to be appended before keccaking (in this case 0x01, for EIP-2930 txs):
keccak256(0x01 || rlp([chainID, nonce, gasPrice, gas, to, value, data, accessList]))
type TxLegacy ¶ added in v0.2.0
type TxLegacy struct {
GasPrice *big.Int // the gas price of the tx
Value *big.Int // value of the transfer (if any)
V, R, S *big.Int // the signature fields
To *[]byte // recipient address (nil means contract deployment)
Data []byte // data (payload) of the tx, if any
Nonce uint64 // the sender nonce
Gas uint64 // the gas limit of the tx
}
TxLegacy represents the legacy transaction type (pre EIP-2930, and pre EIP-1559)
func (*TxLegacy) FromRLP ¶ added in v0.2.0
FromRLP parses a legacy transaction from the transaction data RLP encoding. It expects the structure to be:
[nonce, gasPrice, gas, to, value, data, v, r, s] (9 elements)
func (*TxLegacy) SignaturePayload ¶ added in v0.2.0
SignaturePayload constructs the legacy transaction signature payload. The signature payload (what's being signed) is the keccak of a specific RLP encoding.
RLP structure that needs to be constructed and keccak-ed later:
- Pre-EIP-155 (Homestead) RLP: [nonce, gasPrice, gas, to, value, data] (6 elements)
- EIP-155 RLP: [nonce, gasPrice, gas, to, value, data, chainID, 0, 0] (9 elements)
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package hex provides the common hex manipulation functionality.
|
Package hex provides the common hex manipulation functionality. |
|
Package keccak provides a utility wrapper for the sha256 legacy keccak implementation.
|
Package keccak provides a utility wrapper for the sha256 legacy keccak implementation. |
|
proto
|
|