types

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2024 License: GPL-3.0 Imports: 22 Imported by: 0

Documentation

Overview

Copyright 2023 The AmazeChain Authors This file is part of the AmazeChain library.

The AmazeChain library is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

The AmazeChain library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with the AmazeChain library. If not, see <http://www.gnu.org/licenses/>.

Index

Constants

View Source
const (
	LegacyTxType = iota
	AccessListTxType
	DynamicFeeTxType
)
View Source
const (
	// BloomByteLength represents the number of bytes used in a header log bloom.
	BloomByteLength = 256

	// BloomBitLength represents the number of bits used in a header log bloom.
	BloomBitLength = 8 * BloomByteLength
)

Variables

View Source
var (
	ErrInvalidSig           = errors.New("invalid transaction v, r, s values")
	ErrUnexpectedProtection = errors.New("transaction type does not supported EIP-155 protected signatures")
	ErrInvalidTxType        = errors.New("transaction type not valid in this context")
	ErrTxTypeNotSupported   = errors.New("transaction type not supported")
	ErrGasFeeCapTooLow      = errors.New("fee cap less than base fee")

	ErrInvalidChainId = errors.New("invalid chain id for signer")
)
View Source
var EmptyUncleHash = types.HexToHash("0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347")

var EmptyUncleHash = rlpHash([]*Header(nil))

Functions

func Bloom9

func Bloom9(data []byte) []byte

Bloom9 returns the bloom filter for the given data

func BloomLookup

func BloomLookup(bin Bloom, topic bytesBacked) bool

BloomLookup is a convenience-method to check presence in the bloom filter

func FromAmcAddress

func FromAmcAddress(address *types.Address) *common.Address

func FromAmcHash

func FromAmcHash(hash types.Hash) common.Hash

func LogsBloom

func LogsBloom(logs []*Log) []byte

LogsBloom returns the bloom bytes for the given logs

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.

func ToAmcAccessList

func ToAmcAccessList(accessList AccessList) transaction.AccessList

func ToAmcAddress

func ToAmcAddress(addr *common.Address) *types.Address

func ToAmcHash

func ToAmcHash(hash common.Hash) types.Hash

func ToAmcLog

func ToAmcLog(log *Log) *block.Log

func ToAmcLogs

func ToAmcLogs(logs []*Log) []*block.Log

Types

type AccessList

type AccessList []AccessTuple

func FromAmcAccessList

func FromAmcAccessList(accessList transaction.AccessList) AccessList

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 BlockNonce

type BlockNonce [8]byte

func EncodeNonce

func EncodeNonce(i uint64) BlockNonce

EncodeNonce converts the given integer to a block nonce.

func (BlockNonce) MarshalText

func (n BlockNonce) MarshalText() ([]byte, error)

MarshalText encodes n as a hex string with 0x prefix.

func (BlockNonce) Uint64

func (n BlockNonce) Uint64() uint64

Uint64 returns the integer value of a block nonce.

func (*BlockNonce) UnmarshalText

func (n *BlockNonce) UnmarshalText(input []byte) error

UnmarshalText implements encoding.TextUnmarshaler.

type Bloom

type Bloom [BloomByteLength]byte

Bloom represents a 2048 bit bloom filter.

func BytesToBloom

func BytesToBloom(b []byte) Bloom

BytesToBloom converts a byte slice to a bloom filter. It panics if b is not of suitable size.

func (*Bloom) Add

func (b *Bloom) Add(d []byte)

Add adds d to the filter. Future calls of Test(d) will return true.

func (Bloom) Big

func (b Bloom) Big() *big.Int

Big converts b to a big integer. Note: Converting a bloom filter to a big.Int and then calling GetBytes does not return the same bytes, since big.Int will trim leading zeroes

func (Bloom) Bytes

func (b Bloom) Bytes() []byte

Bytes returns the backing byte slice of the bloom

func (Bloom) MarshalText

func (b Bloom) MarshalText() ([]byte, error)

MarshalText encodes b as a hex string with 0x prefix.

func (*Bloom) SetBytes

func (b *Bloom) SetBytes(d []byte)

SetBytes sets the content of b to the given bytes. It panics if d is not of suitable size.

func (Bloom) Test

func (b Bloom) Test(topic []byte) bool

Test checks if the given topic is present in the bloom filter

func (*Bloom) UnmarshalText

func (b *Bloom) UnmarshalText(input []byte) error

UnmarshalText b as a hex string with 0x prefix.

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"`
}

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{}

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 Header struct {
	ParentHash  common.Hash    `json:"parentHash"       gencodec:"required"`
	UncleHash   common.Hash    `json:"sha3Uncles"       gencodec:"required"`
	Coinbase    common.Address `json:"miner"`
	Root        common.Hash    `json:"stateRoot"        gencodec:"required"`
	TxHash      common.Hash    `json:"transactionsRoot" gencodec:"required"`
	ReceiptHash common.Hash    `json:"receiptsRoot"     gencodec:"required"`
	Bloom       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       BlockNonce     `json:"nonce"`

	// BaseFee was added by EIP-1559 and is ignored in legacy headers.
	BaseFee *big.Int `json:"baseFeePerGas" rlp:"optional"`
}

func FromAmcHeader

func FromAmcHeader(iHeader block.IHeader) *Header

func (*Header) Hash

func (h *Header) Hash() common.Hash

Hash returns the block hash of the header, which is simply the keccak256 hash of its RLP encoding.

func (Header) MarshalJSON

func (h Header) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*Header) Size

func (h *Header) Size() common.StorageSize

Size returns the approximate memory used by all internal contents. It is used to approximate and limit the memory consumption of various caches.

func (*Header) UnmarshalJSON

func (h *Header) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

type HomesteadSigner

type HomesteadSigner struct{ FrontierSigner }

HomesteadTransaction implements TransactionInterface 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 regular Ethereum transactions.

type Log

type Log struct {
	// Consensus fields:
	// address of the contract that generated the event
	Address common.Address `json:"address" gencodec:"required"`
	// list of topics provided by the contract.
	Topics []common.Hash `json:"topics" gencodec:"required"`
	// supplied by the contract, usually ABI-encoded
	Data []byte `json:"data" gencodec:"required"`

	// Derived fields. These fields are filled in by the node
	// but not secured by consensus.
	// block in which the transaction was included
	BlockNumber uint64 `json:"blockNumber"`
	// hash of the transaction
	TxHash common.Hash `json:"transactionHash" gencodec:"required"`
	// index of the transaction in the block
	TxIndex uint `json:"transactionIndex" gencodec:"required"`
	// hash of the block in which the transaction was included
	BlockHash common.Hash `json:"blockHash"`
	// index of the log in the receipt
	Index uint `json:"logIndex" gencodec:"required"`

	// The Removed field is true if this log was reverted due to a chain reorganisation.
	// You must pay attention to this field if you receive logs through a filter query.
	Removed bool `json:"removed"`
}

func FromAmcLog

func FromAmcLog(log *block.Log) *Log

func FromAmcLogs

func FromAmcLogs(amcLogs []*block.Log) []*Log

func (Log) MarshalJSON

func (l Log) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*Log) UnmarshalJSON

func (l *Log) UnmarshalJSON(input []byte) error

UnmarshalJSON unmarshals from JSON.

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 EIP-155 replay protection and EIP-2930 access list transactions when their respective forks are scheduled to occur at any block number in the chain blockchain.

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) Signer

MakeSigner returns a Signer based on the given chain blockchain and block number.

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 Transaction

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

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 NewTx

func NewTx(inner TxData) *Transaction

NewTx creates a new transaction.

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) AccessList

func (tx *Transaction) AccessList() AccessList

AccessList returns the access list of the transaction.

func (*Transaction) ChainId

func (tx *Transaction) ChainId() *big.Int

ChainId returns the EIP155 chain ID of the transaction. The return value will always be non-nil. For legacy transactions which are not replay-protected, the return value is zero.

func (*Transaction) Data

func (tx *Transaction) Data() []byte

Data returns the input data of the transaction.

func (*Transaction) FromAmcTransaction

func (tx *Transaction) FromAmcTransaction(amcTx *transaction.Transaction)

func (*Transaction) Gas

func (tx *Transaction) Gas() uint64

Gas returns the gas limit of the transaction.

func (*Transaction) GasFeeCap

func (tx *Transaction) GasFeeCap() *big.Int

GasFeeCap returns the fee cap per gas of the transaction.

func (*Transaction) GasPrice

func (tx *Transaction) GasPrice() *big.Int

GasPrice returns the gas price of the transaction.

func (*Transaction) GasTipCap

func (tx *Transaction) GasTipCap() *big.Int

GasTipCap returns the gasTipCap per gas of the transaction.

func (*Transaction) Hash

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

Hash returns the transaction hash.

func (*Transaction) Nonce

func (tx *Transaction) Nonce() uint64

Nonce returns the sender account nonce of the transaction.

func (*Transaction) Protected

func (tx *Transaction) Protected() bool

Protected says whether the transaction is replay-protected.

func (*Transaction) RawSignatureValues

func (tx *Transaction) RawSignatureValues() (v, r, s *big.Int)

func (*Transaction) Size

func (tx *Transaction) Size() common.StorageSize

Size returns the true RLP encoded storage size of the transaction, either by encoding and returning it, or returning a previously cached value.

func (*Transaction) To

func (tx *Transaction) To() *common.Address

To returns the recipient address of the transaction. For contract-creation transactions, To returns nil.

func (*Transaction) ToAmcTransaction

func (tx *Transaction) ToAmcTransaction(chainConfig *params.ChainConfig, blockNumber *big.Int) (*transaction.Transaction, error)

func (*Transaction) Type

func (tx *Transaction) Type() uint8

Type returns the transaction type.

func (*Transaction) UnmarshalBinary

func (tx *Transaction) UnmarshalBinary(b []byte) error

UnmarshalBinary

func (*Transaction) Value

func (tx *Transaction) Value() *big.Int

Value returns the ether amount of the transaction.

func (*Transaction) WithSignature

func (tx *Transaction) WithSignature(signer Signer, sig []byte) (*Transaction, error)

WithSignature returns a new transaction with the given signature. This signature needs to be in the [R || S || V] format where V is 0 or 1.

type TxData

type TxData interface {
	// contains filtered or unexported methods
}

Jump to

Keyboard shortcuts

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