types

package
v0.0.3-0...-aa4f25e Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2024 License: LGPL-3.0 Imports: 29 Imported by: 8

Documentation

Index

Constants

View Source
const (
	ProposerElectionTypeWRF              = "wrf"
	ProposerElectionTypeAbnormalRotation = "abnormal-rotation"

	RatioLimit = 10000
)
View Source
const (
	TrieDegree       = 16
	TypeInternalNode = 0
	TypeLeafNode     = 1
)
View Source
const (
	LegacyTxType = iota
	AccessListTxType
	DynamicFeeTxType
	IncentiveTxType
)

Transaction types.

View Source
const (
	BloomByteLength = 256
)

Lengths of hashes and addresses in bytes.

Variables

View Source
var AxcUnit = big.NewInt(1_000000000_000000000)
View Source
var AxcUnitStr = "axc"
View Source
var GmolUnit = big.NewInt(1_000000000)
View Source
var GmolUnitStr = "gmol"
View Source
var MolUnit = big.NewInt(1)
View Source
var MolUnitStr = "mol"

Functions

func BytesToHex

func BytesToHex(h []byte) []byte

BytesToHex expand normal bytes to hex bytes (nibbles)

func CloneTransaction

func CloneTransaction[T any, C TXConstraint[T]](tx *T) *T

func CopyAddress

func CopyAddress(src *common.Address) *common.Address

func GenerateTransactionAndSigner

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

func GenerateWrongSignTransactionAndSigner

func GenerateWrongSignTransactionAndSigner(illegalSign bool) (*Transaction, *Signer, error)

NOTICE!! this function just supoort for unit test case

func HexToBytes

func HexToBytes(src []byte) []byte

HexToBytes compress hex bytes (also called nibbles) to normal bytes

func InitEIP155Signer

func InitEIP155Signer(chainId *big.Int)

func IsZeroBytes

func IsZeroBytes(bytes []byte) bool

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 any) *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 RecycleTrieNode

func RecycleTrieNode(n Node)

func RlpHash

func RlpHash(x any) *common.Hash

RlpHash encodes x and hashes the encoded bytes.

func UnmarshalObjects

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

func UnmarshalObjectsWithIndex

func UnmarshalObjectsWithIndex[T any, Constraint CodecObjectConstraint[T]](data []byte, index uint64) (*T, error)

Types

type AccessList

type AccessList []AccessTuple

AccessList is an EIP-2930 access list.

func (AccessList) ToEthAccessList

func (l AccessList) ToEthAccessList() types.AccessList

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

func (tx *AccessListTx) EffectiveGasPrice(baseFee *big.Int) *big.Int

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

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

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 AccessTuple

type AccessTuple struct {
	Address     Address
	StorageKeys []Hash
}

AccessTuple is the element type of an access list.

func (AccessTuple) ToEthAccessTuple

func (t AccessTuple) ToEthAccessTuple() types.AccessTuple

type Address

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

func NewAddress

func NewAddress(b []byte) *Address

NewAddress 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 (a *Address) ETHAddress() common.Address

func (*Address) IsZero

func (a *Address) IsZero() bool

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 {
	Header       *BlockHeader
	Transactions []*Transaction
	Extra        *BlockExtra
}

func (*Block) CalculateSize

func (b *Block) CalculateSize() int64

func (*Block) Clone

func (b *Block) Clone() *Block

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() int64

func (*Block) Unmarshal

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

type BlockBody

type BlockBody struct {
	Transactions []*Transaction
	Extra        *BlockExtra
}

func (*BlockBody) Clone

func (b *BlockBody) Clone() *BlockBody

func (*BlockBody) Marshal

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

func (*BlockBody) Unmarshal

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

type BlockExtra

type BlockExtra struct {
	// full block size
	Size int64
}

For TIMC and system contract

func (*BlockExtra) Clone

func (b *BlockExtra) Clone() *BlockExtra

func (*BlockExtra) Marshal

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

func (*BlockExtra) Unmarshal

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

type BlockHeader

type BlockHeader struct {
	Number         uint64
	StateRoot      *Hash
	TxRoot         *Hash
	ReceiptRoot    *Hash
	ParentHash     *Hash
	Timestamp      int64
	Epoch          uint64
	Bloom          *Bloom
	ProposerNodeID uint64
	GasPrice       uint64
	GasUsed        uint64
	TotalGasFee    *big.Int
	GasFeeReward   *big.Int
	// contains filtered or unexported fields
}

func (*BlockHeader) CalculateHash

func (h *BlockHeader) CalculateHash() *Hash

func (*BlockHeader) Clone

func (h *BlockHeader) Clone() *BlockHeader

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 Child

type Child struct {
	Hash    common.Hash
	Version uint64
	Leaf    bool
}

type CodecObject

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

type CodecObjectConstraint

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

type CoinNumber

type CoinNumber big.Int

func CoinNumberByAxc

func CoinNumberByAxc(axc uint64) *CoinNumber

func CoinNumberByBigInt

func CoinNumberByBigInt(x *big.Int) *CoinNumber

func CoinNumberByGmol

func CoinNumberByGmol(gmol uint64) *CoinNumber

func CoinNumberByMol

func CoinNumberByMol(mol uint64) *CoinNumber

func ParseCoinNumber

func ParseCoinNumber(valueStr string) (*CoinNumber, error)

func (*CoinNumber) Clone

func (c *CoinNumber) Clone() *CoinNumber

func (*CoinNumber) InitNoZero

func (c *CoinNumber) InitNoZero()

func (*CoinNumber) MarshalText

func (c *CoinNumber) MarshalText() (text []byte, err error)

func (*CoinNumber) String

func (c *CoinNumber) String() string

func (*CoinNumber) ToBigInt

func (c *CoinNumber) ToBigInt() *big.Int

func (*CoinNumber) UnmarshalText

func (c *CoinNumber) UnmarshalText(b []byte) error

type ConsensusParams

type ConsensusParams struct {
	// The proposer election type, default is wrf
	// wrf: WRF
	// abnormal-rotation: rotating by view(pbft logic, disable auto change proposer)
	ProposerElectionType string `mapstructure:"proposer_election_type" toml:"proposer_election_type" json:"proposer_election_type"`

	// The number of sustained blocks per Checkpoint.
	CheckpointPeriod uint64 `mapstructure:"checkpoint_period" toml:"checkpoint_period" json:"checkpoint_period"`

	// Used to calculate max log size in memory: CheckpointPeriod*HighWatermarkCheckpointPeriod.
	HighWatermarkCheckpointPeriod uint64 `` /* 127-byte string literal not displayed */

	// The minimum number of validators in the network.
	MinValidatorNum uint64 `mapstructure:"min_validator_num" toml:"min_validator_num" json:"min_validator_num"`

	// The maximum number of validators in the network.
	MaxValidatorNum uint64 `mapstructure:"max_validator_num" toml:"max_validator_num" json:"max_validator_num"`

	// The maximum number of packaged transactions per block.
	BlockMaxTxNum uint64 `mapstructure:"block_max_tx_num" toml:"block_max_tx_num" json:"block_max_tx_num"`

	// Enable timed gen empty block feature.
	EnableTimedGenEmptyBlock bool `mapstructure:"enable_timed_gen_empty_block" toml:"enable_timed_gen_empty_block" json:"enable_timed_gen_empty_block"`

	// The weight of the faulty node after viewchange is triggered is set to the weight so that the node has a low probability of blocking.
	NotActiveWeight int64 `mapstructure:"not_active_weight" toml:"not_active_weight" json:"not_active_weight"`

	// The low weight of the viewchange node is restored to normal after the specified number of rounds.
	AbnormalNodeExcludeView uint64 `mapstructure:"abnormal_node_exclude_view" toml:"abnormal_node_exclude_view" json:"abnormal_node_exclude_view"`

	// The block interval for node to propose again in validators num percentage,
	// Ensure that a node cannot continuously produce blocks
	// min is 1, max is validatorSetNum - 1
	AgainProposeIntervalBlockInValidatorsNumPercentage uint64 `` /* 202-byte string literal not displayed */

	// ContinuousNullRequestToleranceNumber Viewchange will be sent when there is a packageable transaction locally and n nullrequests are received consecutively.
	ContinuousNullRequestToleranceNumber uint64 `` /* 151-byte string literal not displayed */

	// ReBroadcastToleranceNumber replicate will rebroadcast pending ready txs when receiving null requests from primary above the threshold
	// !!! notice!!! this param must smaller than  ContinuousNullRequestToleranceNumber
	ReBroadcastToleranceNumber uint64 `mapstructure:"rebroadcast_tolerance_number" toml:"rebroadcast_tolerance_number" json:"rebroadcast_tolerance_number"`
}

func (*ConsensusParams) Validate

func (p *ConsensusParams) Validate() error

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

func (tx *DynamicFeeTx) EffectiveGasPrice(baseFee *big.Int) *big.Int

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

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

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 Eip2930Signer

type Eip2930Signer struct{ EIP155Signer }

func NewEIP2930Signer

func NewEIP2930Signer(chainId *big.Int) Eip2930Signer

NewEIP2930Signer returns a signer that accepts EIP-2930 access list transactions, EIP-155 replay protected transactions, and legacy Homestead transactions.

func (Eip2930Signer) SignatureValues

func (s Eip2930Signer) SignatureValues(tx *Transaction, sig []byte) (R, S, V *big.Int, err error)

type EpochInfo

type EpochInfo struct {
	// Epoch number.
	Epoch uint64 `mapstructure:"epoch" toml:"epoch" json:"epoch"`

	// The number of blocks lasting per Epoch (must be a multiple of the CheckpointPeriod).
	EpochPeriod uint64 `mapstructure:"epoch_period" toml:"epoch_period" json:"epoch_period"`

	// Epoch start block.
	StartBlock uint64 `mapstructure:"start_block" toml:"start_block" json:"start_block"`

	// Consensus params.
	ConsensusParams ConsensusParams `mapstructure:"consensus_params" toml:"consensus_params" json:"consensus_params"`

	// FinanceParams params about gas
	FinanceParams FinanceParams `mapstructure:"finance_params" toml:"finance_params" json:"finance_params"`

	// StakeParams params about stake
	StakeParams StakeParams `mapstructure:"stake_params" toml:"stake_params" json:"stake_params"`

	MiscParams MiscParams `mapstructure:"misc_params" toml:"misc_params" json:"misc_params"`
}

func (*EpochInfo) Clone

func (e *EpochInfo) Clone() *EpochInfo

func (*EpochInfo) Marshal

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

func (*EpochInfo) Unmarshal

func (e *EpochInfo) Unmarshal(raw []byte) error

func (*EpochInfo) Validate

func (e *EpochInfo) Validate() error

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 FinanceParams

type FinanceParams struct {
	GasLimit uint64 `mapstructure:"gas_limit" toml:"gas_limit" json:"gas_limit"`

	MinGasPrice *CoinNumber `mapstructure:"min_gas_price" toml:"min_gas_price" json:"min_gas_price"`
}

func (*FinanceParams) Validate

func (p *FinanceParams) Validate() 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) Clone

func (h *Hash) Clone() *Hash

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

func (h *Hash) IsZero() bool

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 IncentiveTx

type IncentiveTx 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

	IncentiveAddress *common.Address

	// Signature values
	V *big.Int `json:"v" gencodec:"required"`

	R *big.Int `json:"r" gencodec:"required"`
	S *big.Int `json:"s" gencodec:"required"`
}

func (*IncentiveTx) EffectiveGasPrice

func (tx *IncentiveTx) EffectiveGasPrice(baseFee *big.Int) *big.Int

func (*IncentiveTx) GetAccessList

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

func (*IncentiveTx) GetChainID

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

func (*IncentiveTx) GetData

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

func (*IncentiveTx) GetGas

func (tx *IncentiveTx) GetGas() uint64

func (*IncentiveTx) GetGasFeeCap

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

func (*IncentiveTx) GetGasPrice

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

func (*IncentiveTx) GetGasTipCap

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

func (*IncentiveTx) GetIncentiveAddress

func (tx *IncentiveTx) GetIncentiveAddress() *common.Address

func (*IncentiveTx) GetNonce

func (tx *IncentiveTx) GetNonce() uint64

func (*IncentiveTx) GetTo

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

func (*IncentiveTx) GetValue

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

func (*IncentiveTx) RawSignatureValues

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

func (*IncentiveTx) TxType

func (tx *IncentiveTx) TxType() byte

type InnerAccount

type InnerAccount struct {
	Nonce       uint64      `json:"nonce"`
	Balance     *big.Int    `json:"balance"`
	CodeHash    []byte      `json:"code_hash"`
	StorageRoot common.Hash `json:"storage_root"`
}

func (*InnerAccount) CopyOrNewIfEmpty

func (o *InnerAccount) CopyOrNewIfEmpty() *InnerAccount

func (*InnerAccount) InnerAccountChanged

func (o *InnerAccount) InnerAccountChanged(account1 *InnerAccount) bool

func (*InnerAccount) Marshal

func (o *InnerAccount) Marshal() ([]byte, error)

Marshal marshals the account into byte

func (*InnerAccount) String

func (o *InnerAccount) String() string

func (*InnerAccount) Unmarshal

func (o *InnerAccount) Unmarshal(data []byte) error

Unmarshal unmarshals the account byte into structure

type InternalNode

type InternalNode struct {
	Children [TrieDegree]*Child
	// contains filtered or unexported fields
}

func (*InternalNode) Copy

func (n *InternalNode) Copy() Node

deep copy

func (*InternalNode) Encode

func (n *InternalNode) Encode() []byte

func (*InternalNode) GetHash

func (n *InternalNode) GetHash() common.Hash

func (*InternalNode) String

func (n *InternalNode) String() string

just for debug

func (*InternalNode) Type

func (n *InternalNode) Type() int

type KeccakState

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

type LeafNode

type LeafNode struct {
	Key  []byte
	Val  []byte
	Hash common.Hash
}

func (*LeafNode) Copy

func (n *LeafNode) Copy() Node

deep copy

func (*LeafNode) Encode

func (n *LeafNode) Encode() []byte

func (*LeafNode) GetHash

func (n *LeafNode) GetHash() common.Hash

GetHash get LeafNode's hash, which is only determined by its Key and Val

func (*LeafNode) String

func (n *LeafNode) String() string

just for debug

func (*LeafNode) Type

func (n *LeafNode) Type() int

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

func (tx *LegacyTx) EffectiveGasPrice(baseFee *big.Int) *big.Int

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

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

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 LondonSigner

type LondonSigner struct{ EIP155Signer }

func NewLondonSigner

func NewLondonSigner(chainId *big.Int) LondonSigner

func (LondonSigner) SignatureValues

func (s LondonSigner) SignatureValues(tx *Transaction, sig []byte) (R, S, V *big.Int, err error)

type MiscParams

type MiscParams struct {
	TxMaxSize uint64 `mapstructure:"tx_max_size" toml:"tx_max_size" json:"tx_max_size"`
}

func (*MiscParams) Validate

func (p *MiscParams) Validate() error

type Node

type Node interface {
	Encode() []byte
	GetHash() common.Hash
	Copy() Node
	Type() int
	String() string // just for debug
}

func UnmarshalJMTNodeFromPb

func UnmarshalJMTNodeFromPb(data []byte) (Node, error)

type NodeInfo

type NodeInfo struct {
	// The node serial number is unique in the entire network.
	// Once allocated, it will not change.
	// It is allocated through the governance contract in a manner similar to the self-incrementing primary key.
	ID uint64 `json:"id"`

	// Use BLS12-381(Use of new consensus algorithm)
	ConsensusPubKey string `json:"consensus_pub_key"`

	// Use ed25519(Currently used in consensus and p2p)
	P2PPubKey string `json:"p2p_pub_key"`

	P2PID string `json:"p2p_id"`

	// Operator address, with permission to manage node (can update)
	OperatorAddress string `json:"operator_address"`

	// Meta data (can update)
	MetaData NodeMetaData `json:"meta_data"`

	// Node status
	Status NodeStatus `json:"status"`
}

func (*NodeInfo) Marshal

func (n *NodeInfo) Marshal() ([]byte, error)

func (*NodeInfo) Unmarshal

func (n *NodeInfo) Unmarshal(raw []byte) error

type NodeKey

type NodeKey struct {
	Version uint64 // version of current tree node.
	Path    []byte // addressing path from root to current node. Path is part of LeafNode.Key.
	Type    []byte // additional field for identify a tree uniquely together with Version and Path.
}

func DecodeNodeKey

func DecodeNodeKey(raw []byte) *NodeKey

DecodeNodeKey decode from bytes in physical storage to NodeKey

func (*NodeKey) Encode

func (nk *NodeKey) Encode() []byte

func (*NodeKey) GetIndex

func (nk *NodeKey) GetIndex() []byte

func (*NodeKey) String

func (nk *NodeKey) String() string

just for debug

type NodeKeyHeap

type NodeKeyHeap []*NodeKey // max heap to store NodeKey

func (NodeKeyHeap) Len

func (h NodeKeyHeap) Len() int

func (NodeKeyHeap) Less

func (h NodeKeyHeap) Less(i, j int) bool

func (*NodeKeyHeap) Pop

func (h *NodeKeyHeap) Pop() any

func (*NodeKeyHeap) Push

func (h *NodeKeyHeap) Push(x any)

func (NodeKeyHeap) Swap

func (h NodeKeyHeap) Swap(i, j int)

type NodeMetaData

type NodeMetaData struct {
	Name       string `json:"name"`
	Desc       string `json:"desc"`
	ImageURL   string `json:"image_url"`
	WebsiteURL string `json:"website_url"`
}

type NodeStatus

type NodeStatus uint8
const (
	NodeStatusDataSyncer NodeStatus = iota
	NodeStatusCandidate
	NodeStatusActive
	NodeStatusPendingInactive
	NodeStatusExited
)

status constants, the order is important

type RbftTransaction

type RbftTransaction interface {
	RbftGetTxHash() string
	RbftGetFrom() string
	RbftGetTo() string
	RbftGetTimeStamp() int64
	RbftGetData() []byte
	RbftGetNonce() uint64
	RbftUnmarshal(raw []byte) error
	RbftMarshal() ([]byte, error)
	RbftIsConfigTx() bool
	RbftGetSize() int
	RbftGetGasPrice() *big.Int
	RbftGetGasLimit() uint64
	RbftGetGasFeeCap() *big.Int
	RbftGetValue() *big.Int
	RbftGetAccessList() AccessList
	RbftClone() RbftTransaction
}

type Receipt

type Receipt struct {
	TxHash            *Hash
	Ret               []byte
	Status            ReceiptStatus
	GasUsed           uint64
	CumulativeGasUsed uint64
	EffectiveGasPrice *big.Int
	EvmLogs           []*EvmLog
	Bloom             *Bloom
	ContractAddress   *Address
}

func UnmarshalReceiptWithIndex

func UnmarshalReceiptWithIndex(data []byte, index uint64) (*Receipt, error)

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)

func LoadSignerWithPk

func LoadSignerWithPk(pk string) (*Signer, error)

type SnapshotJournal

type SnapshotJournal struct {
	Journals []*SnapshotJournalEntry
}

func DecodeSnapshotJournal

func DecodeSnapshotJournal(data []byte) (*SnapshotJournal, error)

func (*SnapshotJournal) Encode

func (j *SnapshotJournal) Encode() ([]byte, error)

type SnapshotJournalEntry

type SnapshotJournalEntry struct {
	Address        *Address
	PrevAccount    *InnerAccount
	AccountChanged bool
	PrevStates     map[string][]byte
}

func (*SnapshotJournalEntry) String

func (entry *SnapshotJournalEntry) String() string

type StakeParams

type StakeParams struct {
	StakeEnable           bool   `mapstructure:"stake_enable" toml:"stake_enable" json:"stake_enable"`
	MaxAddStakeRatio      uint64 `mapstructure:"max_add_stake_ratio" toml:"max_add_stake_ratio" json:"max_add_stake_ratio"`
	MaxUnlockStakeRatio   uint64 `mapstructure:"max_unlock_stake_ratio" toml:"max_unlock_stake_ratio" json:"max_unlock_stake_ratio"`
	MaxUnlockingRecordNum uint64 `mapstructure:"max_unlocking_record_num" toml:"max_unlocking_record_num" json:"max_unlocking_record_num"`

	// unit: seconds
	UnlockPeriod uint64 `mapstructure:"unlock_period" toml:"unlock_period" json:"unlock_period"`

	MaxPendingInactiveValidatorRatio uint64      `` /* 139-byte string literal not displayed */
	MinDelegateStake                 *CoinNumber `mapstructure:"min_delegate_stake" toml:"min_delegate_stake" json:"min_delegate_stake"`
	MinValidatorStake                *CoinNumber `mapstructure:"min_validator_stake" toml:"min_validator_stake" json:"min_validator_stake"`
	MaxValidatorStake                *CoinNumber `mapstructure:"max_validator_stake" toml:"max_validator_stake" json:"max_validator_stake"`
	EnablePartialUnlock              bool        `mapstructure:"enable_partial_unlock" toml:"enable_partial_unlock" json:"enable_partial_unlock"`
}

func (*StakeParams) Validate

func (p *StakeParams) Validate() error

type StateDelta

type StateDelta struct {
	Journal []*TrieJournal
}

func DecodeStateDelta

func DecodeStateDelta(data []byte) (*StateDelta, error)

func (*StateDelta) Encode

func (delta *StateDelta) Encode() []byte

type TXConstraint

type TXConstraint[T any] interface {
	*T
	RbftTransaction
}

TXConstraint is used to ensure that the pointer of T must be RbftTransaction

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 GenerateAccessListTxAndSigner

func GenerateAccessListTxAndSigner() (*Transaction, error)

func GenerateDynamicFeeTxAndSinger

func GenerateDynamicFeeTxAndSinger() (*Transaction, error)

func GenerateEmptyTransactionAndSigner

func GenerateEmptyTransactionAndSigner() (*Transaction, error)

func GenerateTransactionWithGasPrice

func GenerateTransactionWithGasPrice(nonce uint64, gas uint64, gasPrice *big.Int, s *Signer) (*Transaction, error)

func GenerateTransactionWithSigner

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

func UnmarshalTransactionWithIndex

func UnmarshalTransactionWithIndex(data []byte, index uint64) (*Transaction, error)

func UnmarshalTransactions

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

func (*Transaction) Clone

func (tx *Transaction) Clone() *Transaction

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 (tx *Transaction) FromCallArgs(callArgs CallArgs)

func (*Transaction) GetAccessList

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

func (*Transaction) GetChainID

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

func (*Transaction) GetExtra

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

func (*Transaction) GetFrom

func (tx *Transaction) GetFrom() *Address

func (*Transaction) GetGas

func (tx *Transaction) GetGas() uint64

func (*Transaction) GetGasFeeCap

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

func (*Transaction) GetGasPrice

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

func (*Transaction) GetGasTipCap

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

func (*Transaction) GetHash

func (tx *Transaction) GetHash() *Hash

func (*Transaction) GetInner

func (tx *Transaction) GetInner() TxData

func (*Transaction) GetNonce

func (tx *Transaction) GetNonce() uint64

func (*Transaction) GetPayload

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

func (*Transaction) GetRawSignature

func (tx *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 (tx *Transaction) GetSignHash() *Hash

func (*Transaction) GetSignature

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

func (*Transaction) GetTimeStamp

func (tx *Transaction) GetTimeStamp() int64

func (*Transaction) GetTo

func (tx *Transaction) GetTo() *Address

func (*Transaction) GetType

func (tx *Transaction) GetType() byte

Type returns the transaction type.

func (*Transaction) GetValue

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

func (*Transaction) GetVersion

func (tx *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 (tx *Transaction) Protected() bool

Protected says whether the transaction is replay-protected.

func (*Transaction) RbftClone

func (tx *Transaction) RbftClone() RbftTransaction

func (*Transaction) RbftGetAccessList

func (tx *Transaction) RbftGetAccessList() AccessList

func (*Transaction) RbftGetData

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

func (*Transaction) RbftGetFrom

func (tx *Transaction) RbftGetFrom() string

func (*Transaction) RbftGetGasFeeCap

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

func (*Transaction) RbftGetGasLimit

func (tx *Transaction) RbftGetGasLimit() uint64

func (*Transaction) RbftGetGasPrice

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

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

func (tx *Transaction) RbftGetTo() string

func (*Transaction) RbftGetTxHash

func (tx *Transaction) RbftGetTxHash() string

func (*Transaction) RbftGetValue

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

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

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

func (*Transaction) Size

func (tx *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 (tx *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 TrieJournal

type TrieJournal struct {
	Type        byte
	DirtySet    map[string]Node
	PruneSet    map[string]struct{}
	RootHash    common.Hash
	RootNodeKey *NodeKey
}

func (*TrieJournal) String

func (j *TrieJournal) String() string

just for debug

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
	GetIncentiveAddress() *common.Address

	RawSignatureValues() (v, r, s *big.Int)

	EffectiveGasPrice(baseFee *big.Int) *big.Int
	// contains filtered or unexported methods
}

TxData is the underlying data of a transaction.

This is implemented by DynamicFeeTx, LegacyTx and AccessListTx.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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