Documentation ¶
Index ¶
- Constants
- Variables
- func AddressToString(address Address) string
- func EncodeBigInt(b *big.Int) *string
- func EncodeBytes(b []byte) *string
- func EncodeUint64(b uint64) *string
- func IsValidAddress(address string) error
- func MarshalRLPTo(obj marshalRLPFunc, dst []byte) []byte
- func ParseBytes(val *string) ([]byte, error)
- func ParseUint256orHex(val *string) (*big.Int, error)
- func ParseUint64orHex(val *string) (uint64, error)
- func RegisterTxHashFork(txHashWithTypeFork string) error
- func StringToBytes(str string) []byte
- func UnmarshalRlp(obj unmarshalRLPFunc, input []byte) error
- type Address
- type Block
- func (b *Block) Body() *Body
- func (b *Block) Hash() Hash
- func (b *Block) MarshalRLP() []byte
- func (b *Block) MarshalRLPTo(dst []byte) []byte
- func (b *Block) MarshalRLPWith(ar *fastrlp.Arena) *fastrlp.Value
- func (b *Block) Number() uint64
- func (b *Block) ParentHash() Hash
- func (b *Block) Size() uint64
- func (b *Block) String() string
- func (b *Block) UnmarshalRLP(input []byte) error
- func (b *Block) WithSeal(header *Header) *Block
- type Bloom
- type Body
- type ExitProof
- type FullBlock
- type Hash
- type Header
- func (h *Header) ComputeHash() *Header
- func (h *Header) Copy() *Header
- func (h *Header) Equal(hh *Header) bool
- func (h *Header) HasBody() bool
- func (h *Header) HasReceipts() bool
- func (h *Header) IsGenesis() bool
- func (h *Header) MarshalRLP() []byte
- func (h *Header) MarshalRLPTo(dst []byte) []byte
- func (h *Header) MarshalRLPWith(arena *fastrlp.Arena) *fastrlp.Value
- func (h *Header) SetNonce(i uint64)
- func (h *Header) UnmarshalRLP(input []byte) error
- type Log
- type Nonce
- type OverrideAccount
- type Proof
- type RLPMarshaler
- type RLPStoreMarshaler
- type RLPStoreUnmarshaler
- type RLPUnmarshaler
- type Receipt
- func (r *Receipt) IsLegacyTx() bool
- func (r *Receipt) MarshalLogsWith(a *fastrlp.Arena) *fastrlp.Value
- func (r *Receipt) MarshalRLP() []byte
- func (r *Receipt) MarshalRLPTo(dst []byte) []byte
- func (r *Receipt) MarshalRLPWith(a *fastrlp.Arena) *fastrlp.Value
- func (r *Receipt) MarshalStoreRLPTo(dst []byte) []byte
- func (r *Receipt) SetContractAddress(contractAddress Address)
- func (r *Receipt) SetStatus(s ReceiptStatus)
- func (r *Receipt) UnmarshalRLP(input []byte) error
- func (r *Receipt) UnmarshalStoreRLP(input []byte) error
- type ReceiptStatus
- type Receipts
- type StateOverride
- type StateSyncEvent
- type StateSyncProof
- type Transaction
- func (t *Transaction) ComputeHash(blockNumber uint64) *Transaction
- func (t *Transaction) Copy() *Transaction
- func (t *Transaction) Cost() *big.Int
- func (t *Transaction) EffectiveGasTip(baseFee *big.Int) *big.Int
- func (t *Transaction) GetGasFeeCap() *big.Int
- func (t *Transaction) GetGasPrice(baseFee uint64) *big.Int
- func (t *Transaction) GetGasTipCap() *big.Int
- func (t *Transaction) IsContractCreation() bool
- func (t *Transaction) MarshalRLP() []byte
- func (t *Transaction) MarshalRLPTo(dst []byte) []byte
- func (t *Transaction) MarshalRLPWith(arena *fastrlp.Arena) *fastrlp.Value
- func (t *Transaction) MarshalStoreRLPTo(dst []byte) []byte
- func (t *Transaction) Size() uint64
- func (t *Transaction) UnmarshalRLP(input []byte) error
- func (t *Transaction) UnmarshalStoreRLP(input []byte) error
- type TransactionHashFork
- type TransactionHashForkV1
- type TransactionHashForkV2
- type TxType
Constants ¶
const ( HashLength = 32 AddressLength = 20 SignatureSize = 4 )
const BloomByteLength = 256
const (
RLPSingleByteUpperLimit = 0x7f
)
const (
// StateTransactionGasLimit is arbitrary default gas limit for state transactions
StateTransactionGasLimit = 1000000
)
Variables ¶
var ( // ZeroAddress is the default zero address ZeroAddress = Address{} // ZeroHash is the default zero hash ZeroHash = Hash{} // ZeroNonce is the default empty nonce ZeroNonce = Nonce{} // EmptyRootHash is the root when there are no transactions EmptyRootHash = StringToHash("0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421") // EmptyUncleHash is the root when there are no uncles EmptyUncleHash = StringToHash("0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347") // EmptyCodeHash is the root where there is no code. // Equivalent of: `types.BytesToHash(crypto.Keccak256(nil))` EmptyCodeHash = StringToHash("0xc5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470") )
var (
// this will change to use the generated code, but for now, we leave it as is, because of the circular import
ExecuteStateSyncABIMethod, _ = abi.NewMethod("function execute(" +
"bytes32[] proof, " +
"tuple(uint256 id, address sender, address receiver, bytes data) obj)")
)
var HeaderHash func(h *Header) Hash
Functions ¶
func AddressToString ¶
func EncodeBigInt ¶
func EncodeBytes ¶
func EncodeUint64 ¶
func IsValidAddress ¶
IsValidAddress checks if provided string is a valid Ethereum address
func MarshalRLPTo ¶
func ParseBytes ¶
func ParseUint64orHex ¶
ParseUint64orHex parses the given string as uint64 in hex It should go to the common package from the logical perspective as well as avoiding cycle imports. DEPRECATED. Use common.ParseUint64orHex.
func RegisterTxHashFork ¶
func StringToBytes ¶
func UnmarshalRlp ¶
Types ¶
type Address ¶
type Address [AddressLength]byte
func BytesToAddress ¶
func StringToAddress ¶
func (Address) MarshalText ¶
func (*Address) UnmarshalText ¶
UnmarshalText parses an address in hex syntax.
type Block ¶
type Block struct { Header *Header Transactions []*Transaction Uncles []*Header // contains filtered or unexported fields }
func (*Block) MarshalRLP ¶
func (*Block) MarshalRLPTo ¶
func (*Block) ParentHash ¶
func (*Block) UnmarshalRLP ¶
type Bloom ¶
type Bloom [BloomByteLength]byte
func CreateBloom ¶
CreateBloom creates a new bloom filter from a set of receipts
func (*Bloom) IsLogInBloom ¶
IsLogInBloom checks if the log has a possible presence in the bloom filter
func (Bloom) MarshalText ¶
MarshalText implements encoding.TextMarshaler
func (*Bloom) UnmarshalText ¶
type Body ¶
type Body struct { Transactions []*Transaction Uncles []*Header }
func (*Body) MarshalRLPTo ¶
func (*Body) UnmarshalRLP ¶
UnmarshalRLP unmarshals body from byte slice. Caution: Hash for each tx must be computed manually after!
type Hash ¶
type Hash [HashLength]byte
func BytesToHash ¶
func StringToHash ¶
func (Hash) MarshalText ¶
func (*Hash) UnmarshalText ¶
UnmarshalText parses a hash in hex syntax.
type Header ¶
type Header struct { ParentHash Hash Sha3Uncles Hash Miner []byte StateRoot Hash TxRoot Hash ReceiptsRoot Hash LogsBloom Bloom Difficulty uint64 Number uint64 GasLimit uint64 GasUsed uint64 Timestamp uint64 ExtraData []byte MixHash Hash Nonce Nonce Hash Hash // BaseFee was added by EIP-1559 and is ignored in legacy headers. BaseFee uint64 `json:"baseFeePerGas"` }
Header represents a block header in the Ethereum blockchain.
func (*Header) ComputeHash ¶
ComputeHash computes the hash of the header
func (*Header) HasReceipts ¶
func (*Header) MarshalRLP ¶
func (*Header) MarshalRLPTo ¶
func (*Header) MarshalRLPWith ¶
MarshalRLPWith marshals the header to RLP with a specific fastrlp.Arena
func (*Header) UnmarshalRLP ¶
type Nonce ¶
type Nonce [8]byte
func (Nonce) MarshalText ¶
MarshalText implements encoding.TextMarshaler
type OverrideAccount ¶
type RLPMarshaler ¶
type RLPStoreMarshaler ¶
type RLPStoreUnmarshaler ¶
type RLPUnmarshaler ¶
type Receipt ¶
type Receipt struct { // consensus fields Root Hash CumulativeGasUsed uint64 LogsBloom Bloom Logs []*Log Status *ReceiptStatus // context fields GasUsed uint64 ContractAddress *Address TxHash Hash TransactionType TxType }
func (*Receipt) IsLegacyTx ¶
func (*Receipt) MarshalLogsWith ¶
MarshalLogsWith marshals the logs of the receipt to RLP with a specific fastrlp.Arena
func (*Receipt) MarshalRLP ¶
func (*Receipt) MarshalRLPTo ¶
func (*Receipt) MarshalRLPWith ¶
MarshalRLPWith marshals a receipt with a specific fastrlp.Arena
func (*Receipt) MarshalStoreRLPTo ¶
func (*Receipt) SetContractAddress ¶
func (*Receipt) SetStatus ¶
func (r *Receipt) SetStatus(s ReceiptStatus)
func (*Receipt) UnmarshalRLP ¶
func (*Receipt) UnmarshalStoreRLP ¶
type ReceiptStatus ¶
type ReceiptStatus uint64
const ( ReceiptFailed ReceiptStatus = iota ReceiptSuccess )
type Receipts ¶
type Receipts []*Receipt
func (Receipts) MarshalRLPTo ¶
func (*Receipts) MarshalRLPWith ¶
func (Receipts) MarshalStoreRLPTo ¶
func (*Receipts) UnmarshalRLP ¶
func (*Receipts) UnmarshalStoreRLP ¶
type StateOverride ¶
type StateOverride map[Address]OverrideAccount
type StateSyncEvent ¶
type StateSyncEvent struct { // ID is the decoded 'index' field from the event ID uint64 // Sender is the decoded 'sender' field from the event Sender ethgo.Address // Receiver is the decoded 'receiver' field from the event Receiver ethgo.Address // Data is the decoded 'data' field from the event Data []byte }
StateSyncEvent is a bridge event from the rootchain
func (*StateSyncEvent) EncodeAbi ¶
func (sse *StateSyncEvent) EncodeAbi() ([]byte, error)
ToABI converts StateSyncEvent to ABI
func (*StateSyncEvent) String ¶
func (sse *StateSyncEvent) String() string
func (*StateSyncEvent) ToMap ¶
func (sse *StateSyncEvent) ToMap() map[string]interface{}
ToMap converts StateSyncEvent to map
type StateSyncProof ¶
type StateSyncProof struct { Proof []Hash StateSync *StateSyncEvent }
func (*StateSyncProof) DecodeAbi ¶
func (ssp *StateSyncProof) DecodeAbi(txData []byte) error
DecodeAbi contains logic for decoding given ABI data
func (*StateSyncProof) EncodeAbi ¶
func (ssp *StateSyncProof) EncodeAbi() ([]byte, error)
EncodeAbi contains logic for encoding given ABI data
type Transaction ¶
type Transaction struct { Nonce uint64 GasPrice *big.Int GasTipCap *big.Int GasFeeCap *big.Int Gas uint64 To *Address Value *big.Int Input []byte V, R, S *big.Int Hash Hash From Address Type TxType ChainID *big.Int // contains filtered or unexported fields }
func FindTxByHash ¶
func FindTxByHash(txs []*Transaction, hash Hash) (*Transaction, int)
FindTxByHash returns transaction and its index from a slice of transactions
func (*Transaction) ComputeHash ¶
func (t *Transaction) ComputeHash(blockNumber uint64) *Transaction
ComputeHash computes the hash of the transaction
func (*Transaction) Copy ¶
func (t *Transaction) Copy() *Transaction
func (*Transaction) Cost ¶
func (t *Transaction) Cost() *big.Int
Cost returns gas * gasPrice + value
func (*Transaction) EffectiveGasTip ¶
func (t *Transaction) EffectiveGasTip(baseFee *big.Int) *big.Int
EffectiveGasTip defines effective tip based on tx type. Spec: https://eips.ethereum.org/EIPS/eip-1559#specification We use EIP-1559 fields of the tx if the london hardfork is enabled. Effective tip be came to be either gas tip cap or (gas fee cap - current base fee)
func (*Transaction) GetGasFeeCap ¶
func (t *Transaction) GetGasFeeCap() *big.Int
GetGasFeeCap gets gas fee cap depending on tx type Spec: https://eips.ethereum.org/EIPS/eip-1559#specification
func (*Transaction) GetGasPrice ¶
func (t *Transaction) GetGasPrice(baseFee uint64) *big.Int
GetGasPrice returns gas price if not empty, or calculates one based on the given EIP-1559 fields if exist
Here is the logic:
- use existing gas price if exists
- or calculate a value with formula: min(gasFeeCap, gasTipCap * baseFee);
func (*Transaction) GetGasTipCap ¶
func (t *Transaction) GetGasTipCap() *big.Int
GetGasTipCap gets gas tip cap depending on tx type Spec: https://eips.ethereum.org/EIPS/eip-1559#specification
func (*Transaction) IsContractCreation ¶
func (t *Transaction) IsContractCreation() bool
IsContractCreation checks if tx is contract creation
func (*Transaction) MarshalRLP ¶
func (t *Transaction) MarshalRLP() []byte
func (*Transaction) MarshalRLPTo ¶
func (t *Transaction) MarshalRLPTo(dst []byte) []byte
func (*Transaction) MarshalRLPWith ¶
func (t *Transaction) MarshalRLPWith(arena *fastrlp.Arena) *fastrlp.Value
MarshalRLPWith marshals the transaction to RLP with a specific fastrlp.Arena Be careful! This function does not serialize tx type as a first byte. Use MarshalRLP/MarshalRLPTo in most cases
func (*Transaction) MarshalStoreRLPTo ¶
func (t *Transaction) MarshalStoreRLPTo(dst []byte) []byte
func (*Transaction) Size ¶
func (t *Transaction) Size() uint64
func (*Transaction) UnmarshalRLP ¶
func (t *Transaction) UnmarshalRLP(input []byte) error
UnmarshalRLP unmarshals transaction from byte slice Caution: Hash calculation should be done from the outside!
func (*Transaction) UnmarshalStoreRLP ¶
func (t *Transaction) UnmarshalStoreRLP(input []byte) error
UnmarshalStoreRLP unmarshals transaction from byte slice. Hash must be computed manually after!
type TransactionHashFork ¶
type TransactionHashFork interface { SerializeForRootCalculation(*Transaction, *fastrlp.ArenaPool) []byte ComputeHash(*Transaction) }
func GetTransactionHashHandler ¶
func GetTransactionHashHandler(blockNumber uint64) TransactionHashFork
type TransactionHashForkV1 ¶
type TransactionHashForkV1 struct { }
func (*TransactionHashForkV1) ComputeHash ¶
func (th *TransactionHashForkV1) ComputeHash(t *Transaction)
func (*TransactionHashForkV1) SerializeForRootCalculation ¶
func (th *TransactionHashForkV1) SerializeForRootCalculation(t *Transaction, ap *fastrlp.ArenaPool) []byte
type TransactionHashForkV2 ¶
type TransactionHashForkV2 struct { }
func (*TransactionHashForkV2) ComputeHash ¶
func (th *TransactionHashForkV2) ComputeHash(t *Transaction)
func (*TransactionHashForkV2) SerializeForRootCalculation ¶
func (th *TransactionHashForkV2) SerializeForRootCalculation(t *Transaction, _ *fastrlp.ArenaPool) []byte