state

package
v2.3.0-rc15 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2025 License: Apache-2.0 Imports: 10 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// SystemNamespace is the namespace to store system information such as candidates/probationList/unproductiveDelegates
	// Poll Protocol uses this namespace to store states:
	//   - hash256(CurCandidateKey/NextCandidateKey) --> CandidatesList
	//   - hash256(CurProbationKey/NextProbationKey) --> ProbationList
	//   - hash256(UnproductiveDelegatesKey) --> UnproductiveDelegates
	//   - hash256(BlockMetaPrefix)+height%heightInEpoch --> BlockMeta
	SystemNamespace = "System"

	// AccountKVNamespace is the bucket name for account
	// Poll Protocol uses this namespace to store LEGACY states:
	//   - hash160(CandidatesPrefix+height) --> CandidatesList
	// Rewarding Protocol uses this namespace to store LEGACY states:
	//   - hash160(hash160(rewarding)+adminKey) --> admin
	//   - hash160(hash160(rewarding)+exemptKey) --> exempt
	//   - hash160(hash160(rewarding)+fundKey) --> fund
	//   - hash160(hash160(rewarding)+_blockRewardHistoryKeyPrefix+height) --> rewardHistory
	//   - hash160(hash160(rewarding)+_epochRewardHistoryKeyPrefix+epoch) --> rewardHistory
	//   - hash160(hash160(rewarding)+adminKey+address) --> rewardAccount
	AccountKVNamespace = "Account"

	// RewardingNamespace is the namespace to store rewarding information
	//   - hash160(rewarding)+adminKey --> admin
	//   - hash160(rewarding)+exemptKey --> exempt
	//   - hash160(rewarding)+fundKey --> fund
	//   - hash160(rewarding)+_blockRewardHistoryKeyPrefix+height --> rewardHistory
	//   - hash160(rewarding)+_epochRewardHistoryKeyPrefix+epoch --> rewardHistory
	//   - hash160(rewarding)+adminKey+address --> rewardAccount
	RewardingNamespace = "Rewarding"

	// StakingNamespace is the namespace to store staking information
	//   - "0" + totalBucketKey --> totalBucketCount
	//   - "1" + <bucketID> --> VoteBucket
	//   - "2" + <owner> --> BucketIndices
	//   - "3" + <candidate> --> BucketIndices
	//   - "4" + <bucketID> --> Endorsement
	StakingNamespace = "Staking"

	// StakingViewNamespace is the namespace to store staking view information
	//   - "voteview" + <contractAddress> --> CandidateVotes
	StakingViewNamespace = "StakingView"

	// ContractStakingBucketNamespacePrefix is the namespace to store staking contract buckets
	//   - <contractAddress> --> <bucketID> --> Bucket
	ContractStakingBucketNamespacePrefix = "cs_bucket_"
	// ContractStakingBucketTypeNamespacePrefix is the namespace to store staking contract bucket types
	//   - <contractAddress> --> <typeID> --> BucketType
	ContractStakingBucketTypeNamespacePrefix = "cs_bucket_type_"
	// StakingContractMetaNamespace is the namespace to store staking contract meta information
	StakingContractMetaNamespace = "staking_contract_meta"

	// CandidateNamespace is the namespace to store candidate information
	//   - <ID> --> Candidate
	CandidateNamespace = "Candidate"

	// CandsMapNamespace is the namespace to store candidate map
	//   - "name" --> CandidateList
	//   - "operator" --> CandidateList
	//   - "owner" --> CandidateList
	CandsMapNamespace = "CandsMap"

	// CodeKVNameSpace is the bucket name for code
	//   codeHash --> code
	CodeKVNameSpace = "Code"

	// ContractKVNameSpace is the bucket name for contract data storage
	//   trieKey --> trieValue
	ContractKVNameSpace = "Contract"

	// PreimageKVNameSpace is the bucket name for preimage data storage
	PreimageKVNameSpace = "Preimage"
)

Variables

View Source
var (
	// ErrNotEnoughBalance is the error that the balance is not enough
	ErrNotEnoughBalance = errors.New("not enough balance")
	// ErrInvalidAmount is the error that the amount to add is negative
	ErrInvalidAmount = errors.New("invalid amount")
	// ErrAccountCollision is the error that the account already exists
	ErrAccountCollision = errors.New("account already exists")
	// ErrInvalidNonce is the error that the nonce to set is invalid
	ErrInvalidNonce = errors.New("invalid nonce")
	// ErrUnknownAccountType is the error that the account type is unknown
	ErrUnknownAccountType = errors.New("unknown account type")
	// ErrNonceOverflow is the error that the nonce overflow
	ErrNonceOverflow = errors.New("nonce overflow")
)
View Source
var (
	// ErrCandidate indicates the error of candidate
	ErrCandidate = errors.New("invalid candidate")
	// ErrCandidatePb indicates the error of protobuf's candidate message
	ErrCandidatePb = errors.New("invalid protobuf's candidate message")
	// ErrCandidateMap indicates the error of candidate map
	ErrCandidateMap = errors.New("invalid candidate map")
	// ErrCandidateList indicates the error of candidate list
	ErrCandidateList = errors.New("invalid candidate list")
)
View Source
var (
	// ErrStateSerialization is the error that the state marshaling is failed
	ErrStateSerialization = errors.New("failed to marshal state")

	// ErrStateDeserialization is the error that the state un-marshaling is failed
	ErrStateDeserialization = errors.New("failed to unmarshal state")

	// ErrStateNotExist is the error that the state does not exist
	ErrStateNotExist = errors.New("state does not exist")

	// ErrErigonStoreNotSupported is the error that the erigon store is not supported
	ErrErigonStoreNotSupported = errors.New("erigon store not supported")
)
View Source
var ErrInConsistentLength = errors.New("keys and states have inconsistent length")

ErrInConsistentLength is an error when keys and states have inconsistent length

View Source
var ErrNilValue = errors.New("value is nil")

ErrNilValue is an error when value is nil

View Source
var ErrOutOfBoundary = errors.New("index is out of boundary")

ErrOutOfBoundary defines an error when the index in the iterator is out of boundary

Functions

func Deserialize

func Deserialize(x interface{}, data []byte) error

Deserialize check if input is Deserializer, if it is, use the input's Deserialize method, otherwise use Gob.

func Serialize

func Serialize(d interface{}) ([]byte, error)

Serialize check if input is Serializer, if it is, use the input's Serialize method, otherwise use Gob.

Types

type Account

type Account struct {
	Balance  *big.Int
	Root     hash.Hash256 // storage trie root for contract account
	CodeHash []byte       // hash of the smart contract byte-code for contract account
	// contains filtered or unexported fields
}

Account is the canonical representation of an account.

func NewAccount

func NewAccount(opts ...AccountCreationOption) (*Account, error)

NewAccount creates a new account with options

func (*Account) AccountType

func (st *Account) AccountType() int32

AccountType returns the account type

func (*Account) AddBalance

func (st *Account) AddBalance(amount *big.Int) error

AddBalance adds balance for account state

func (*Account) Clone

func (st *Account) Clone() *Account

Clone clones the account state

func (*Account) ConvertFreshAccountToZeroNonceType

func (st *Account) ConvertFreshAccountToZeroNonceType(nonce uint64) bool

ConvertFreshAccountToZeroNonceType converts a fresh legacy account to zero-nonce account

func (*Account) Deserialize

func (st *Account) Deserialize(buf []byte) error

Deserialize deserializes bytes into account state

func (*Account) FromProto

func (st *Account) FromProto(acPb *accountpb.Account)

FromProto converts from protobuf's Account

func (*Account) HasSufficientBalance

func (st *Account) HasSufficientBalance(amount *big.Int) bool

HasSufficientBalance returns true if balance is larger than amount

func (*Account) IsContract

func (st *Account) IsContract() bool

IsContract returns true for contract account

func (*Account) IsLegacyFreshAccount

func (st *Account) IsLegacyFreshAccount() bool

IsLegacyFreshAccount returns true if a legacy account has not sent any actions

func (*Account) IsNewbieAccount

func (st *Account) IsNewbieAccount() bool

IsNewbieAccount returns true if the account has not sent any actions

func (*Account) MarkAsCandidate

func (st *Account) MarkAsCandidate()

MarkAsCandidate marks the account as a candidate

func (*Account) PendingNonce

func (st *Account) PendingNonce() uint64

PendingNonce returns the pending nonce of the account

func (*Account) PendingNonceConsideringFreshAccount

func (st *Account) PendingNonceConsideringFreshAccount() uint64

PendingNonceConsideringFreshAccount return the pending nonce considering fresh legacy account

func (Account) Serialize

func (st Account) Serialize() ([]byte, error)

Serialize serializes account state into bytes

func (*Account) SetPendingNonce

func (st *Account) SetPendingNonce(nonce uint64) error

SetPendingNonce sets the pending nonce

func (*Account) SubBalance

func (st *Account) SubBalance(amount *big.Int) error

SubBalance subtracts balance for account state

func (*Account) ToProto

func (st *Account) ToProto() *accountpb.Account

ToProto converts to protobuf's Account

type AccountCreationOption

type AccountCreationOption func(*Account) error

AccountCreationOption is to create new account with specific settings

func DelegateCandidateOption

func DelegateCandidateOption() AccountCreationOption

DelegateCandidateOption is an option to create a delegate candidate account

func LegacyNonceAccountTypeOption

func LegacyNonceAccountTypeOption() AccountCreationOption

LegacyNonceAccountTypeOption is an option to create account with new account type

type Candidate

type Candidate struct {
	Address       string
	Votes         *big.Int
	RewardAddress string
	CanName       []byte // used as identifier to merge with native staking result, not part of protobuf
	BLSPubKey     []byte // BLS public key, used for verification
}

Candidate indicates the structure of a candidate

func (*Candidate) Clone

func (c *Candidate) Clone() *Candidate

Clone makes a copy of the candidate

func (*Candidate) Deserialize

func (c *Candidate) Deserialize(buf []byte) error

Deserialize deserializes bytes to candidate

func (*Candidate) Equal

func (c *Candidate) Equal(d *Candidate) bool

Equal compares two candidate instances

func (*Candidate) Serialize

func (c *Candidate) Serialize() ([]byte, error)

Serialize serializes candidate to bytes

type CandidateList

type CandidateList []*Candidate

CandidateList indicates the list of Candidates which is sortable

func MapToCandidates

func MapToCandidates(candidateMap CandidateMap) (CandidateList, error)

MapToCandidates converts a map of cachedCandidates to candidate list

func (*CandidateList) Decode added in v2.3.0

Decode decodes a GenericValue into CandidateList

func (*CandidateList) Deserialize

func (l *CandidateList) Deserialize(buf []byte) error

Deserialize deserializes bytes to list of Candidates

func (*CandidateList) Encode added in v2.3.0

Encode encodes a CandidateList into a GenericValue

func (CandidateList) Len

func (l CandidateList) Len() int

func (CandidateList) Less

func (l CandidateList) Less(i, j int) bool

func (*CandidateList) LoadProto

func (l *CandidateList) LoadProto(candList *iotextypes.CandidateList) error

LoadProto loads candidate list from proto

func (*CandidateList) Proto

Proto converts the candidate list to a protobuf message

func (*CandidateList) Serialize

func (l *CandidateList) Serialize() ([]byte, error)

Serialize serializes a list of Candidates to bytes

func (CandidateList) Swap

func (l CandidateList) Swap(i, j int)

type CandidateMap

type CandidateMap map[hash.Hash160]*Candidate

CandidateMap is a map of Candidates using Hash160 as key

func CandidatesToMap

func CandidatesToMap(candidates CandidateList) (CandidateMap, error)

CandidatesToMap converts a candidate list to map of cachedCandidates

type Deserializer

type Deserializer interface {
	Deserialize(data []byte) error
}

Deserializer has Deserialize method to deserialize binary data to struct.

type Iterator

type Iterator interface {
	// Size returns the size of the iterator
	Size() int
	// Next deserializes the next state in the iterator
	Next(interface{}) ([]byte, error)
}

Iterator defines an iterator to read a set of states

func NewIterator

func NewIterator(keys [][]byte, states [][]byte) (Iterator, error)

NewIterator returns an iterator given a list of serialized states

type Serializer

type Serializer interface {
	Serialize() ([]byte, error)
}

Serializer has Serialize method to serialize struct to binary data.

type State

type State interface {
	Serialize() ([]byte, error)
	Deserialize(data []byte) error
}

State is the interface, which defines the common methods for state struct to be handled by state factory

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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