transaction

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: 17 Imported by: 1

Documentation

Index

Constants

View Source
const (
	LegacyTxType = iota
	AccessListTxType
	DynamicFeeTxType
)

Transaction types.

Variables

View Source
var (
	ErrGasFeeCapTooLow = fmt.Errorf("fee cap less than base fee")
	ErrUnmarshalHash   = fmt.Errorf("hash verify falied")
)
View Source
var (
	ErrInvalidSig         = errors.New("invalid transaction v, r, s values")
	ErrTxTypeNotSupported = errors.New("transaction type not supported")
	ErrInvalidChainId     = errors.New("invalid chain id for signer")
)

Functions

func DeriveChainId

func DeriveChainId(v *uint256.Int) *uint256.Int

deriveChainID derives the chain id from the given v parameter

func Sender

func Sender(signer Signer, tx *Transaction) (types.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

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    *uint256.Int   // destination chain ID
	Nonce      uint64         // nonce of sender account
	GasPrice   *uint256.Int   // wei per gas
	Gas        uint64         // gas limit
	To         *types.Address `rlp:"nil"` // nil means contract creation
	From       *types.Address `rlp:"nil"` // nil means contract creation
	Value      *uint256.Int   // wei amount
	Data       []byte         // contract invocation input data
	AccessList AccessList     // EIP-2930 access list
	Sign       []byte         // signature values
	V, R, S    *uint256.Int   // signature values
}

type AccessTuple

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

AccessTuple is the element type of an access list.

type DynamicFeeTx

type DynamicFeeTx struct {
	ChainID    *uint256.Int
	Nonce      uint64
	GasTipCap  *uint256.Int // a.k.a. maxPriorityFeePerGas
	GasFeeCap  *uint256.Int // a.k.a. maxFeePerGas
	Gas        uint64
	To         *types.Address `rlp:"nil"` // nil means contract creation
	From       *types.Address `rlp:"nil"` // nil means contract creation
	Value      *uint256.Int
	Data       []byte
	AccessList AccessList
	Sign       []byte       // Signature values
	V, R, S    *uint256.Int // signature values
}

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) types.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) (types.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) types.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) (types.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 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) (types.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 *uint256.Int   // wei per gas
	Gas      uint64         // gas limit
	To       *types.Address `rlp:"nil"` // nil means contract creation
	From     *types.Address `rlp:"nil"` // nil means contract creation
	Value    *uint256.Int   // wei amount
	Data     []byte         // contract invocation input data
	V, R, S  *uint256.Int   // signature values
	Sign     []byte
}

LegacyTx is the transaction data of regular Ethereum transactions.

type Message

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

Message is a fully derived transaction and implements core.Message

func NewMessage

func NewMessage(from types.Address, to *types.Address, nonce uint64, amount *uint256.Int, gasLimit uint64, gasPrice *uint256.Int, feeCap, tip *uint256.Int, data []byte, accessList AccessList, checkNonce bool, isFree bool) Message

func (Message) AccessList

func (m Message) AccessList() AccessList

func (Message) CheckNonce

func (m Message) CheckNonce() bool

func (Message) Data

func (m Message) Data() []byte

func (Message) FeeCap

func (m Message) FeeCap() *uint256.Int

func (Message) From

func (m Message) From() types.Address

func (Message) Gas

func (m Message) Gas() uint64

func (Message) GasPrice

func (m Message) GasPrice() *uint256.Int

func (Message) IsFree

func (m Message) IsFree() bool

func (Message) Nonce

func (m Message) Nonce() uint64

func (*Message) SetCheckNonce

func (m *Message) SetCheckNonce(checkNonce bool)

func (*Message) SetIsFree

func (m *Message) SetIsFree(isFree bool)

func (Message) Tip

func (m Message) Tip() *uint256.Int

func (Message) To

func (m Message) To() *types.Address

func (Message) Value

func (m Message) Value() *uint256.Int

type SakuragiTx

type SakuragiTx struct {
	Nonce    uint64      // nonce of sender account
	GasPrice uint256.Int // wei per gas
	Gas      uint64      // gas limit
	To       *types.Address
	From     *types.Address
	Value    uint256.Int // wei amount
	Data     []byte      // contract invocation input data
	Sign     []byte      // signature values
}

type Signer

type Signer interface {
	// Sender returns the sender address of the transaction.
	Sender(tx *Transaction) (types.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) types.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 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 config 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 FromProtoMessage

func FromProtoMessage(message proto.Message) (*Transaction, error)

func NewContractCreation

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

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

func NewTransaction

func NewTransaction(nonce uint64, from types.Address, to *types.Address, amount *uint256.Int, gasLimit uint64, gasPrice *uint256.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

func (*Transaction) AsMessage

func (tx *Transaction) AsMessage(s Signer, baseFee *uint256.Int) (Message, error)

AsMessage returns the transaction as a core.Message.

func (*Transaction) ChainId

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

func (*Transaction) Cost

func (tx *Transaction) Cost() *uint256.Int

func (*Transaction) Data

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

func (*Transaction) EffectiveGasTip

func (tx *Transaction) EffectiveGasTip(baseFee *uint256.Int) (*uint256.Int, error)

EffectiveGasTip returns the effective miner gasTipCap for the given base fee. Note: if the effective gasTipCap is negative, this method returns both error the actual negative value, _and_ ErrGasFeeCapTooLow

func (*Transaction) EffectiveGasTipCmp

func (tx *Transaction) EffectiveGasTipCmp(other *Transaction, baseFee *uint256.Int) int

EffectiveGasTipCmp compares the effective gasTipCap of two transactions assuming the given base fee.

func (*Transaction) EffectiveGasTipIntCmp

func (tx *Transaction) EffectiveGasTipIntCmp(other *uint256.Int, baseFee *uint256.Int) int

EffectiveGasTipIntCmp compares the effective gasTipCap of a transaction to the given gasTipCap.

func (*Transaction) EffectiveGasTipValue

func (tx *Transaction) EffectiveGasTipValue(baseFee *uint256.Int) *uint256.Int

EffectiveGasTipValue is identical to EffectiveGasTip, but does not return an error in case the effective gasTipCap is negative

func (*Transaction) From

func (tx *Transaction) From() *types.Address

func (*Transaction) Gas

func (tx *Transaction) Gas() uint64

func (*Transaction) GasFeeCap

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

func (*Transaction) GasFeeCapCmp

func (tx *Transaction) GasFeeCapCmp(other *Transaction) int

GasFeeCapCmp compares the fee cap of two transactions.

func (*Transaction) GasFeeCapIntCmp

func (tx *Transaction) GasFeeCapIntCmp(other *uint256.Int) int

GasFeeCapIntCmp compares the fee cap of the transaction against the given fee cap.

func (*Transaction) GasPrice

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

func (*Transaction) GasTipCap

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

func (*Transaction) GasTipCapCmp

func (tx *Transaction) GasTipCapCmp(other *Transaction) int

GasTipCapCmp compares the gasTipCap of two transactions.

func (*Transaction) GasTipCapIntCmp

func (tx *Transaction) GasTipCapIntCmp(other *uint256.Int) int

GasTipCapIntCmp compares the gasTipCap of the transaction against the given gasTipCap.

func (*Transaction) Hash

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

func (Transaction) Marshal

func (tx Transaction) Marshal() ([]byte, error)

func (*Transaction) MarshalTo

func (tx *Transaction) MarshalTo(data []byte) (n int, err error)

func (*Transaction) Nonce

func (tx *Transaction) Nonce() uint64

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 *uint256.Int)

func (*Transaction) SetFrom

func (tx *Transaction) SetFrom(addr types.Address)

func (*Transaction) SetNonce

func (tx *Transaction) SetNonce(nonce uint64)

func (*Transaction) Sign

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

func (*Transaction) To

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

func (*Transaction) ToProtoMessage

func (tx *Transaction) ToProtoMessage() proto.Message

func (*Transaction) Type

func (tx *Transaction) Type() uint8

func (*Transaction) Unmarshal

func (tx *Transaction) Unmarshal(data []byte) error

func (*Transaction) Value

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

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.

func (*Transaction) WithSignatureValues

func (tx *Transaction) WithSignatureValues(v, r, s *uint256.Int) (*Transaction, error)

WithSignature todo

type Transactions

type Transactions []*Transaction

Transactions implements DerivableList for transactions.

func (Transactions) EncodeIndex

func (s Transactions) EncodeIndex(i int, w *bytes.Buffer)

EncodeIndex encodes the i'th transaction to w. Note that this does not check for errors because we assume that *Transaction will only ever contain valid txs that were either constructed by decoding or via public API in this package.

func (Transactions) Len

func (s Transactions) Len() int

Len returns the length of s.

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