types

package
v0.3.9 Latest Latest
Warning

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

Go to latest
Published: Sep 15, 2021 License: GPL-3.0 Imports: 16 Imported by: 0

Documentation

Overview

Package types defines the eth-like core types (Transaction, etc) and RPC result types.

Index

Constants

View Source
const (
	LegacyTxType = iota
	AccessListTxType
	DynamicFeeTxType
)

Transaction types.

Variables

View Source
var (
	ErrInvalidChainID     = errors.New("invalid chain id for signer")
	ErrInvalidSig         = errors.New("invalid transaction v, r, s values")
	ErrTxTypeNotSupported = errors.New("transaction type not supported")
)

sign tx errors

Functions

func CalcOkexTransactionHash added in v0.3.9

func CalcOkexTransactionHash(tx *Transaction) (hash common.Hash, err error)

CalcOkexTransactionHash calc okex tx hash

func IsOkexChain added in v0.3.9

func IsOkexChain(chainID *big.Int) bool

IsOkexChain judge if it is okex blockchain by chain ID. okex chain is different from eth (transaction hash calc, rpc response behavior)

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 ToBlockNumArg

func ToBlockNumArg(number *big.Int) string

ToBlockNumArg to block number arg

func ToFilterArg

func ToFilterArg(q *FilterQuery) (interface{}, error)

ToFilterArg query to filter arg

Types

type AccessList added in v0.3.9

type AccessList []AccessTuple

AccessList is an EIP-2930 access list.

type AccessListTx added in v0.3.9

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 added in v0.3.9

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 DynamicFeeTx added in v0.3.9

type DynamicFeeTx struct {
	ChainID    *big.Int        // destination chain ID
	Nonce      uint64          // nonce of sender account
	GasTipCap  *big.Int        // maxPriorityFeePerGas
	GasFeeCap  *big.Int        // maxFeePerGas
	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
}

DynamicFeeTx is the data of EIP-1559 dynamic fee transactions.

type EIP155Signer

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

EIP155Signer implements Signer using the EIP155 rules.

func NewEIP155Signer

func NewEIP155Signer(chainID *big.Int) EIP155Signer

NewEIP155Signer new EIP155Signer

func (EIP155Signer) Equal

func (s EIP155Signer) Equal(s2 Signer) bool

Equal compare signer

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)

Sender get sender

func (EIP155Signer) SignatureValues

func (s EIP155Signer) SignatureValues(tx *Transaction, sig []byte) (rsvR, rsvS, rsvV *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 FeeHistoryResult added in v0.3.9

type FeeHistoryResult struct {
	OldestBlock  interface{}      `json:"oldestBlock"`
	Reward       [][]*hexutil.Big `json:"reward,omitempty"`
	BaseFee      []*hexutil.Big   `json:"baseFeePerGas,omitempty"`
	GasUsedRatio []float64        `json:"gasUsedRatio"`
}

FeeHistoryResult fee history result

type FilterQuery

type FilterQuery struct {
	BlockHash *common.Hash
	FromBlock *big.Int
	ToBlock   *big.Int
	Addresses []common.Address
	Topics    [][]common.Hash
}

FilterQuery struct

type FrontierSigner

type FrontierSigner struct{}

FrontierSigner frontier signer

func (FrontierSigner) Equal

func (fs FrontierSigner) Equal(s2 Signer) bool

Equal compare signer

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)

Sender get sender

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 }

HomesteadSigner implements TransactionInterface using the homestead rules.

func (HomesteadSigner) Equal

func (hs HomesteadSigner) Equal(s2 Signer) bool

Equal compare signer

func (HomesteadSigner) Sender

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

Sender get sender

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 added in v0.3.9

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 MsgEthereumTx added in v0.3.9

type MsgEthereumTx struct {
	Data txdata
}

MsgEthereumTx encapsulates an Ethereum transaction as an SDK message.

type RPCBaseBlock added in v0.3.8

type RPCBaseBlock struct {
	Hash       *common.Hash    `json:"hash"`
	ParentHash *common.Hash    `json:"parentHash"`
	Coinbase   *common.Address `json:"miner"`
	Difficulty *hexutil.Big    `json:"difficulty"`
	Number     *hexutil.Big    `json:"number"`
	GasLimit   *hexutil.Uint64 `json:"gasLimit"`
	GasUsed    *hexutil.Uint64 `json:"gasUsed"`
	Time       *hexutil.Big    `json:"timestamp"`
	BaseFee    *hexutil.Big    `json:"baseFeePerGas"`
}

RPCBaseBlock struct

type RPCBlock

type RPCBlock struct {
	Hash         *common.Hash    `json:"hash"`
	ParentHash   *common.Hash    `json:"parentHash"`
	Coinbase     *common.Address `json:"miner"`
	Difficulty   *hexutil.Big    `json:"difficulty"`
	Number       *hexutil.Big    `json:"number"`
	GasLimit     *hexutil.Uint64 `json:"gasLimit"`
	GasUsed      *hexutil.Uint64 `json:"gasUsed"`
	Time         *hexutil.Big    `json:"timestamp"`
	BaseFee      *hexutil.Big    `json:"baseFeePerGas"`
	Transactions []*common.Hash  `json:"transactions"`
}

RPCBlock struct

type RPCLog

type RPCLog struct {
	Address *common.Address `json:"address"`
	Topics  []common.Hash   `json:"topics"`
	Data    *hexutil.Bytes  `json:"data"`
	Removed *bool           `json:"removed"`
}

RPCLog struct

type RPCTransaction

type RPCTransaction struct {
	Type         hexutil.Uint64  `json:"type"`
	Hash         *common.Hash    `json:"hash"`
	BlockNumber  *hexutil.Big    `json:"blockNumber"`
	BlockHash    *common.Hash    `json:"blockHash"`
	From         *common.Address `json:"from"`
	AccountNonce string          `json:"nonce"` // unexpect RSK has leading zero (eg. 0x01)
	Price        *hexutil.Big    `json:"gasPrice"`
	GasTipCap    *hexutil.Big    `json:"maxPriorityFeePerGas,omitempty"`
	GasFeeCap    *hexutil.Big    `json:"maxFeePerGas,omitempty"`
	GasLimit     *hexutil.Uint64 `json:"gas"`
	Recipient    *common.Address `json:"to"`
	Amount       *hexutil.Big    `json:"value"`
	Payload      *hexutil.Bytes  `json:"input"`
	V            *hexutil.Big    `json:"v"`
	R            *hexutil.Big    `json:"r"`
	S            *hexutil.Big    `json:"s"`
	ChainID      *hexutil.Big    `json:"chainId,omitempty"`
}

RPCTransaction struct

func (*RPCTransaction) GetAccountNonce added in v0.3.8

func (tx *RPCTransaction) GetAccountNonce() uint64

GetAccountNonce convert

type RPCTxReceipt

type RPCTxReceipt struct {
	Type        hexutil.Uint64  `json:"type"`
	TxHash      *common.Hash    `json:"transactionHash"`
	TxIndex     *hexutil.Uint   `json:"transactionIndex"`
	BlockNumber *hexutil.Big    `json:"blockNumber"`
	BlockHash   *common.Hash    `json:"blockHash"`
	Status      *hexutil.Uint64 `json:"status"`
	From        *common.Address `json:"from"`
	Recipient   *common.Address `json:"to"`
	GasUsed     *hexutil.Uint64 `json:"gasUsed"`
	Logs        []*RPCLog       `json:"logs"`
}

RPCTxReceipt struct

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)
	// Hash returns the hash to be signed.
	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. Note that this interface is not a stable API and may change at any time to accommodate new protocol rules.

func MakeSigner

func MakeSigner(signType string, chainID *big.Int) Signer

MakeSigner make signer

func NewEIP2930Signer added in v0.3.9

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 added in v0.3.9

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 StorageSize

type StorageSize = common.StorageSize

StorageSize type

type Transaction

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

Transaction struct

func NewContractCreation

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

NewContractCreation new contract creation

func NewDynamicFeeTx added in v0.3.9

func NewDynamicFeeTx(chainID *big.Int, nonce uint64, to *common.Address, amount *big.Int,
	gasLimit uint64, gasTipCap, gasFeeCap *big.Int, data []byte, accessList AccessList) *Transaction

NewDynamicFeeTx new dynamic fee tx for EIP-1559

func NewTransaction

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

NewTransaction new tx

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 added in v0.3.9

func (tx *Transaction) AccessList() AccessList

AccessList returns the access list of the transaction.

func (*Transaction) ChainID

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

ChainID returns which chain id this transaction was signed for (if at all)

func (*Transaction) CheckNonce

func (tx *Transaction) CheckNonce() bool

CheckNonce check nonce

func (*Transaction) Cost

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

Cost returns amount + gasprice * gaslimit.

func (*Transaction) Data

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

Data tx data

func (*Transaction) DecodeRLP

func (tx *Transaction) DecodeRLP(s *rlp.Stream) error

DecodeRLP implements rlp.Decoder

func (*Transaction) EncodeRLP

func (tx *Transaction) EncodeRLP(w io.Writer) error

EncodeRLP implements rlp.Encoder

func (*Transaction) Gas

func (tx *Transaction) Gas() uint64

Gas tx gas

func (*Transaction) GasFeeCap added in v0.3.9

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

GasFeeCap gas fee cap

func (*Transaction) GasPrice

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

GasPrice tx gas price

func (*Transaction) GasTipCap added in v0.3.9

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

GasTipCap gas tip cap

func (*Transaction) Hash

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

Hash returns the transaction hash

func (*Transaction) MarshalBinary added in v0.3.9

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

MarshalBinary returns the canonical encoding of the transaction. For legacy transactions, it returns the RLP encoding. For EIP-2718 typed transactions, it returns the type and payload.

func (*Transaction) MarshalJSON

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

MarshalJSON encodes the web3 RPC transaction format.

func (*Transaction) Nonce

func (tx *Transaction) Nonce() uint64

Nonce tx nonce

func (*Transaction) PrintPretty

func (tx *Transaction) PrintPretty()

PrintPretty print pretty (json)

func (*Transaction) PrintRaw

func (tx *Transaction) PrintRaw()

PrintRaw print raw encoded (hex string)

func (*Transaction) Protected

func (tx *Transaction) Protected() bool

Protected returns whether the transaction is protected from replay protection.

func (*Transaction) RawSignatureValues

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

RawSignatureValues returns the V, R, S signature values of the transaction. The return values should not be modified by the caller.

func (*Transaction) RawStr

func (tx *Transaction) RawStr() string

RawStr return raw encoded (hex string)

func (*Transaction) SetGasPrice added in v0.3.7

func (tx *Transaction) SetGasPrice(gasPrice *big.Int)

SetGasPrice tx gas price

func (*Transaction) Size

func (tx *Transaction) Size() StorageSize

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

func (*Transaction) To

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

To returns the recipient address of the transaction. It returns nil if the transaction is a contract creation.

func (*Transaction) Type added in v0.3.9

func (tx *Transaction) Type() uint8

Type returns tx type

func (*Transaction) UnmarshalBinary added in v0.3.9

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

UnmarshalBinary decodes the canonical encoding of transactions. It supports legacy RLP transactions and EIP2718 typed transactions.

func (*Transaction) UnmarshalJSON

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

UnmarshalJSON decodes the web3 RPC transaction format.

func (*Transaction) Value

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

Value tx value

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.

Jump to

Keyboard shortcuts

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