types

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2023 License: LGPL-3.0 Imports: 23 Imported by: 8

Documentation

Index

Constants

View Source
const (
	LegacyTxType = iota
	AccessListTxType
	DynamicFeeTxType
)

Transaction types.

View Source
const (
	BloomByteLength = 256
)

Lengths of hashes and addresses in bytes.

Variables

View Source
var (
	ErrSyntax        = fmt.Errorf("invalid hex string")
	ErrMissingPrefix = fmt.Errorf("hex string without 0x prefix")
	ErrOddLength     = fmt.Errorf("hex string of odd length")
)

hasherPool holds LegacyKeccak256 hashers for rlpHash.

Functions

func GenerateTransactionAndSigner

func GenerateTransactionAndSigner(nonce uint64, to *Address, value *big.Int, data []byte) (*Transaction, *Signer, error)

func InitEIP155Signer

func InitEIP155Signer(chainId *big.Int)

func MarshalObjects

func MarshalObjects[T any, Constraint CodecObjectConstraint[T]](objs []*T) ([]byte, error)

func MarshalReceipts

func MarshalReceipts(objs []*Receipt) ([]byte, error)

func MarshalTransactions

func MarshalTransactions(objs []*Transaction) ([]byte, error)

func PrefixedRlpHash

func PrefixedRlpHash(prefix byte, x interface{}) *common.Hash

PrefixedRlpHash writes the prefix into the hasher before rlp-encoding x. It's used for typed transactions.

func RecoverPlain

func RecoverPlain(hash []byte, R, S, Vb *big.Int, homestead bool) ([]byte, error)

func RlpHash

func RlpHash(x interface{}) *common.Hash

RlpHash encodes x and hashes the encoded bytes.

func UnmarshalObjects

func UnmarshalObjects[T any, Constraint CodecObjectConstraint[T]](data []byte) ([]*T, error)

Types

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 types.AccessList // EIP-2930 access list
	V, R, S    *big.Int         // signature values
}

AccessListTx is the data of EIP-2930 access list transactions.

func (*AccessListTx) GetAccessList

func (tx *AccessListTx) GetAccessList() types.AccessList

func (*AccessListTx) GetChainID

func (tx *AccessListTx) GetChainID() *big.Int

func (*AccessListTx) GetData

func (tx *AccessListTx) GetData() []byte

func (*AccessListTx) GetGas

func (tx *AccessListTx) GetGas() uint64

func (*AccessListTx) GetGasFeeCap

func (tx *AccessListTx) GetGasFeeCap() *big.Int

func (*AccessListTx) GetGasPrice

func (tx *AccessListTx) GetGasPrice() *big.Int

func (*AccessListTx) GetGasTipCap

func (tx *AccessListTx) GetGasTipCap() *big.Int

func (*AccessListTx) GetNonce

func (tx *AccessListTx) GetNonce() uint64

func (*AccessListTx) GetTo

func (tx *AccessListTx) GetTo() *common.Address

func (*AccessListTx) GetValue

func (tx *AccessListTx) GetValue() *big.Int

func (*AccessListTx) RawSignatureValues

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

func (*AccessListTx) TxType

func (tx *AccessListTx) TxType() byte

type Address

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

func NewAddress

func NewAddress(b []byte) *Address

BytesToAddress returns Address with value b. If b is larger than len(h), b will be cropped address the left.

func NewAddressByStr

func NewAddressByStr(s string) *Address

func (*Address) Bytes

func (a *Address) Bytes() []byte

func (*Address) ETHAddress

func (h *Address) ETHAddress() common.Address

func (*Address) MarshalJSON

func (a *Address) MarshalJSON() ([]byte, error)

func (*Address) SetBytes

func (a *Address) SetBytes(b []byte)

SetBytes sets the address to the value of b. If b is larger than len(a) it will panic.

func (*Address) String

func (a *Address) String() string

String returns an EIP55-compliant hex string representation of the address.

func (*Address) UnmarshalJSON

func (a *Address) UnmarshalJSON(data []byte) error

type Block

type Block struct {
	BlockHeader  *BlockHeader
	Transactions []*Transaction
	BlockHash    *Hash
	Signature    []byte
	Extra        []byte
}

func (*Block) Hash

func (b *Block) Hash() *Hash

func (*Block) Height

func (b *Block) Height() uint64

func (*Block) Marshal

func (b *Block) Marshal() ([]byte, error)

func (*Block) Size

func (b *Block) Size() int

func (*Block) Unmarshal

func (b *Block) Unmarshal(data []byte) error

type BlockHeader

type BlockHeader struct {
	Number      uint64
	StateRoot   *Hash
	TxRoot      *Hash
	ReceiptRoot *Hash
	ParentHash  *Hash
	Timestamp   int64
	Version     []byte
	Bloom       *Bloom
	GasPrice    int64
}

func (*BlockHeader) Hash

func (h *BlockHeader) Hash() *Hash

func (*BlockHeader) Marshal

func (h *BlockHeader) Marshal() ([]byte, error)

func (*BlockHeader) Unmarshal

func (h *BlockHeader) Unmarshal(data []byte) error

type Bloom

type Bloom [BloomByteLength]byte

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

func (b *Bloom) Bytes() []byte

func (*Bloom) ETHBloom

func (b *Bloom) ETHBloom() types.Bloom

func (*Bloom) OrBloom

func (b *Bloom) OrBloom(bl *Bloom)

OrBloom executes an Or operation on the bloom

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

type CallArgs

type CallArgs struct {
	From                 *common.Address   `json:"from"`
	To                   *common.Address   `json:"to"`
	Gas                  *hexutil.Uint64   `json:"gas"`
	GasPrice             *hexutil.Big      `json:"gasPrice"`
	MaxFeePerGas         *hexutil.Big      `json:"maxFeePerGas"`
	MaxPriorityFeePerGas *hexutil.Big      `json:"maxPriorityFeePerGas"`
	Value                *hexutil.Big      `json:"value"`
	Nonce                *hexutil.Uint64   `json:"nonce"`
	Data                 *hexutil.Bytes    `json:"data"`
	Input                *hexutil.Bytes    `json:"input"`
	AccessList           *types.AccessList `json:"accessList"`
	ChainID              *hexutil.Big      `json:"chainId,omitempty"`
}

CallArgs represents the arguments for a call.

func (*CallArgs) GetData

func (args *CallArgs) GetData() []byte

GetData retrieves the transaction calldata. Input field is preferred.

func (*CallArgs) GetFrom

func (args *CallArgs) GetFrom() common.Address

GetFrom retrieves the transaction sender address.

func (*CallArgs) ToTransaction

func (args *CallArgs) ToTransaction() *types.Transaction

ToTransaction converts the arguments to a transaction. This assumes that setDefaults has been called.

type ChainMeta

type ChainMeta struct {
	Height    uint64
	BlockHash *Hash
}

func (*ChainMeta) Marshal

func (m *ChainMeta) Marshal() ([]byte, error)

func (*ChainMeta) Unmarshal

func (m *ChainMeta) Unmarshal(data []byte) error

type CodecObject

type CodecObject interface {
	Marshal() ([]byte, error)
	Unmarshal(buf []byte) error
}

type CodecObjectConstraint

type CodecObjectConstraint[T any] interface {
	*T
	CodecObject
}

type CommitEvent

type CommitEvent struct {
	Block     *Block
	LocalList []bool
}

type DynamicFeeTx

type DynamicFeeTx struct {
	ChainID    *big.Int
	Nonce      uint64
	GasTipCap  *big.Int
	GasFeeCap  *big.Int
	Gas        uint64
	To         *common.Address `rlp:"nil"` // nil means contract creation
	Value      *big.Int
	Data       []byte
	AccessList types.AccessList

	// Signature values
	V *big.Int `json:"v" gencodec:"required"`
	R *big.Int `json:"r" gencodec:"required"`
	S *big.Int `json:"s" gencodec:"required"`
}

func (*DynamicFeeTx) GetAccessList

func (tx *DynamicFeeTx) GetAccessList() types.AccessList

func (*DynamicFeeTx) GetChainID

func (tx *DynamicFeeTx) GetChainID() *big.Int

func (*DynamicFeeTx) GetData

func (tx *DynamicFeeTx) GetData() []byte

func (*DynamicFeeTx) GetGas

func (tx *DynamicFeeTx) GetGas() uint64

func (*DynamicFeeTx) GetGasFeeCap

func (tx *DynamicFeeTx) GetGasFeeCap() *big.Int

func (*DynamicFeeTx) GetGasPrice

func (tx *DynamicFeeTx) GetGasPrice() *big.Int

func (*DynamicFeeTx) GetGasTipCap

func (tx *DynamicFeeTx) GetGasTipCap() *big.Int

func (*DynamicFeeTx) GetNonce

func (tx *DynamicFeeTx) GetNonce() uint64

func (*DynamicFeeTx) GetTo

func (tx *DynamicFeeTx) GetTo() *common.Address

func (*DynamicFeeTx) GetValue

func (tx *DynamicFeeTx) GetValue() *big.Int

func (*DynamicFeeTx) RawSignatureValues

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

func (*DynamicFeeTx) TxType

func (tx *DynamicFeeTx) TxType() byte

accessors for innerTx.

type EIP155Signer

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

type Event

type Event struct {
	TxHash    *Hash
	Data      []byte
	EventType EventType
}

func (*Event) Marshal

func (e *Event) Marshal() ([]byte, error)

func (*Event) Unmarshal

func (e *Event) Unmarshal(data []byte) error

type EventType

type EventType int32
const (
	EventOTHER EventType = 0
)

func (EventType) String

func (x EventType) String() string

type EvmLog

type EvmLog struct {
	Address          *Address
	Topics           []*Hash
	Data             []byte
	BlockNumber      uint64
	TransactionHash  *Hash
	TransactionIndex uint64
	BlockHash        *Hash
	LogIndex         uint64
	Removed          bool
}

func (*EvmLog) Marshal

func (l *EvmLog) Marshal() ([]byte, error)

func (*EvmLog) MarshalJSON

func (l *EvmLog) MarshalJSON() ([]byte, error)

MarshalJSON marshals as JSON.

func (*EvmLog) Unmarshal

func (l *EvmLog) Unmarshal(data []byte) error

type Hash

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

func NewHash

func NewHash(b []byte) *Hash

func NewHashByStr

func NewHashByStr(s string) *Hash

func (*Hash) Bytes

func (h *Hash) Bytes() []byte

func (*Hash) CalculateHash

func (h *Hash) CalculateHash() ([]byte, error)

CalculateHash hashes the values of a TestContent

func (*Hash) ETHHash

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

func (*Hash) Equals

func (h *Hash) Equals(other mt.Content) (bool, error)

Equals tests for equality of two Contents

func (*Hash) MarshalJSON

func (h *Hash) MarshalJSON() ([]byte, error)

func (*Hash) SetBytes

func (h *Hash) SetBytes(b []byte)

func (*Hash) Size

func (h *Hash) Size() int

func (*Hash) String

func (h *Hash) String() string

func (*Hash) UnmarshalJSON

func (h *Hash) UnmarshalJSON(data []byte) error

type KeccakState

type KeccakState interface {
	hash.Hash
	Read([]byte) (int, error)
}

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.

func (*LegacyTx) GetAccessList

func (tx *LegacyTx) GetAccessList() types.AccessList

func (*LegacyTx) GetChainID

func (tx *LegacyTx) GetChainID() *big.Int

func (*LegacyTx) GetData

func (tx *LegacyTx) GetData() []byte

func (*LegacyTx) GetGas

func (tx *LegacyTx) GetGas() uint64

func (*LegacyTx) GetGasFeeCap

func (tx *LegacyTx) GetGasFeeCap() *big.Int

func (*LegacyTx) GetGasPrice

func (tx *LegacyTx) GetGasPrice() *big.Int

func (*LegacyTx) GetGasTipCap

func (tx *LegacyTx) GetGasTipCap() *big.Int

func (*LegacyTx) GetNonce

func (tx *LegacyTx) GetNonce() uint64

func (*LegacyTx) GetTo

func (tx *LegacyTx) GetTo() *common.Address

func (*LegacyTx) GetValue

func (tx *LegacyTx) GetValue() *big.Int

func (*LegacyTx) RawSignatureValues

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

func (*LegacyTx) TxType

func (tx *LegacyTx) TxType() byte

type Receipt

type Receipt struct {
	Version         []byte
	TxHash          *Hash
	Ret             []byte
	Status          ReceiptStatus
	Events          []*Event
	GasUsed         uint64
	EvmLogs         []*EvmLog
	Bloom           *Bloom
	ContractAddress *Address
}

func UnmarshalReceipts

func UnmarshalReceipts(data []byte) ([]*Receipt, error)

func (*Receipt) Hash

func (r *Receipt) Hash() *Hash

func (*Receipt) IsSuccess

func (r *Receipt) IsSuccess() bool

func (*Receipt) Marshal

func (r *Receipt) Marshal() ([]byte, error)

func (*Receipt) Unmarshal

func (r *Receipt) Unmarshal(data []byte) error

type ReceiptStatus

type ReceiptStatus int32
const (
	ReceiptSUCCESS ReceiptStatus = 0
	ReceiptFAILED  ReceiptStatus = 1
)

func (ReceiptStatus) String

func (x ReceiptStatus) String() string

type Signer

type Signer struct {
	Sk   *ecdsa.PrivateKey
	Addr *Address
}

func GenerateSigner

func GenerateSigner() (*Signer, error)

type Transaction

type Transaction struct {
	Inner TxData    // Consensus contents of a transaction
	Time  time.Time // Time first seen locally (spam avoidance)
	// contains filtered or unexported fields
}

Transaction is an Ethereum transaction.

func GenerateEmptyTransactionAndSigner

func GenerateEmptyTransactionAndSigner() (*Transaction, error)

func GenerateTransactionWithSigner

func GenerateTransactionWithSigner(nonce uint64, to *Address, value *big.Int, data []byte, s *Signer) (*Transaction, error)

func UnmarshalTransactions

func UnmarshalTransactions(data []byte) ([]*Transaction, error)

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

func (e *Transaction) FromCallArgs(callArgs CallArgs)

func (*Transaction) GetChainID

func (e *Transaction) GetChainID() *big.Int

func (*Transaction) GetExtra

func (e *Transaction) GetExtra() []byte

func (*Transaction) GetFrom

func (e *Transaction) GetFrom() *Address

func (*Transaction) GetGas

func (e *Transaction) GetGas() uint64

func (*Transaction) GetGasFeeCap

func (e *Transaction) GetGasFeeCap() *big.Int

func (*Transaction) GetGasPrice

func (e *Transaction) GetGasPrice() *big.Int

func (*Transaction) GetGasTipCap

func (e *Transaction) GetGasTipCap() *big.Int

func (*Transaction) GetHash

func (e *Transaction) GetHash() *Hash

func (*Transaction) GetInner

func (e *Transaction) GetInner() TxData

func (*Transaction) GetNonce

func (e *Transaction) GetNonce() uint64

func (*Transaction) GetPayload

func (e *Transaction) GetPayload() []byte

func (*Transaction) GetRawSignature

func (e *Transaction) GetRawSignature() (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) GetSignHash

func (e *Transaction) GetSignHash() *Hash

func (*Transaction) GetSignature

func (e *Transaction) GetSignature() []byte

func (*Transaction) GetTimeStamp

func (e *Transaction) GetTimeStamp() int64

func (*Transaction) GetTo

func (e *Transaction) GetTo() *Address

func (*Transaction) GetType

func (e *Transaction) GetType() byte

Type returns the transaction type.

func (*Transaction) GetValue

func (e *Transaction) GetValue() *big.Int

func (*Transaction) GetVersion

func (e *Transaction) GetVersion() []byte

func (*Transaction) Marshal

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

func (*Transaction) MarshalBinary

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)

func (*Transaction) Protected

func (e *Transaction) Protected() bool

Protected says whether the transaction is replay-protected.

func (*Transaction) RbftGetData

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

func (*Transaction) RbftGetFrom

func (tx *Transaction) RbftGetFrom() string

func (*Transaction) RbftGetNonce

func (tx *Transaction) RbftGetNonce() uint64

func (*Transaction) RbftGetSize

func (tx *Transaction) RbftGetSize() int

func (*Transaction) RbftGetTimeStamp

func (tx *Transaction) RbftGetTimeStamp() int64

func (*Transaction) RbftGetTxHash

func (tx *Transaction) RbftGetTxHash() string

func (*Transaction) RbftIsConfigTx

func (tx *Transaction) RbftIsConfigTx() bool

func (*Transaction) RbftMarshal

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

func (*Transaction) RbftUnmarshal

func (tx *Transaction) RbftUnmarshal(raw []byte) error

func (*Transaction) Sign

func (tx *Transaction) Sign(prv *ecdsa.PrivateKey) error

func (*Transaction) Size

func (e *Transaction) Size() int

func (*Transaction) Unmarshal

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

func (*Transaction) UnmarshalBinary

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

func (e *Transaction) VerifySignature() error

type TransactionMeta

type TransactionMeta struct {
	BlockHash   *Hash
	BlockHeight uint64
	Index       uint64
}

func (*TransactionMeta) Marshal

func (m *TransactionMeta) Marshal() ([]byte, error)

func (*TransactionMeta) Unmarshal

func (m *TransactionMeta) Unmarshal(data []byte) error

type TxData

type TxData interface {
	TxType() byte // returns the type ID

	GetChainID() *big.Int
	GetAccessList() types.AccessList
	GetData() []byte
	GetGas() uint64
	GetGasPrice() *big.Int
	GetGasTipCap() *big.Int
	GetGasFeeCap() *big.Int
	GetValue() *big.Int
	GetNonce() uint64
	GetTo() *common.Address

	RawSignatureValues() (v, r, s *big.Int)
	// contains filtered or unexported methods
}

TxData is the underlying data of a transaction.

This is implemented by DynamicFeeTx, LegacyTx and AccessListTx.

type VpInfo

type VpInfo struct {
	Id      uint64
	Pid     string
	Account string
	Hosts   []string
}

func (*VpInfo) Marshal

func (i *VpInfo) Marshal() ([]byte, error)

func (*VpInfo) Unmarshal

func (i *VpInfo) Unmarshal(data []byte) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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