iotex-core: Index | Files | Directories

package state

import ""


Package Files

account.go candidate.go iterator.go state.go


var (
    // ErrNotEnoughBalance is the error that the balance is not enough
    ErrNotEnoughBalance = errors.New("not enough balance")
    // ErrAccountCollision is the error that the account already exists
    ErrAccountCollision = errors.New("account already exists")
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")
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")
var ErrOutOfBoundary = errors.New("index is out of boundary")

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

func Deserialize Uses

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 Uses

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

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

type Account Uses

type Account struct {
    // 0 is reserved from actions in genesis block and coinbase transfers nonces
    // other actions' nonces start from 1
    Nonce        uint64
    Balance      *big.Int
    Root         hash.Hash256 // storage trie root for contract account
    CodeHash     []byte       // hash of the smart contract byte-code for contract account
    IsCandidate  bool
    VotingWeight *big.Int

Account is the canonical representation of an account.

func EmptyAccount Uses

func EmptyAccount() Account

EmptyAccount returns an empty account

func (*Account) AddBalance Uses

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

AddBalance adds balance for account state

func (*Account) Clone Uses

func (st *Account) Clone() *Account

Clone clones the account state

func (*Account) Deserialize Uses

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

Deserialize deserializes bytes into account state

func (*Account) FromProto Uses

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

FromProto converts from protobuf's Account

func (*Account) IsContract Uses

func (st *Account) IsContract() bool

IsContract returns true for contract account

func (Account) Serialize Uses

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

Serialize serializes account state into bytes

func (*Account) SubBalance Uses

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

SubBalance subtracts balance for account state

func (*Account) ToProto Uses

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

ToProto converts to protobuf's Account

type Candidate Uses

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

Candidate indicates the structure of a candidate

func (*Candidate) Clone Uses

func (c *Candidate) Clone() *Candidate

Clone makes a copy of the candidate

func (*Candidate) Deserialize Uses

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

Deserialize deserializes bytes to candidate

func (*Candidate) Equal Uses

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

Equal compares two candidate instances

func (*Candidate) Serialize Uses

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

Serialize serializes candidate to bytes

type CandidateList Uses

type CandidateList []*Candidate

CandidateList indicates the list of Candidates which is sortable

func MapToCandidates Uses

func MapToCandidates(candidateMap CandidateMap) (CandidateList, error)

MapToCandidates converts a map of cachedCandidates to candidate list

func (*CandidateList) Deserialize Uses

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

Deserialize deserializes bytes to list of Candidates

func (CandidateList) Len Uses

func (l CandidateList) Len() int

func (CandidateList) Less Uses

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

func (*CandidateList) LoadProto Uses

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

LoadProto loads candidate list from proto

func (*CandidateList) Proto Uses

func (l *CandidateList) Proto() *iotextypes.CandidateList

Proto converts the candidate list to a protobuf message

func (*CandidateList) Serialize Uses

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

Serialize serializes a list of Candidates to bytes

func (CandidateList) Swap Uses

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

type CandidateMap Uses

type CandidateMap map[hash.Hash160]*Candidate

CandidateMap is a map of Candidates using Hash160 as key

func CandidatesToMap Uses

func CandidatesToMap(candidates CandidateList) (CandidateMap, error)

CandidatesToMap converts a candidate list to map of cachedCandidates

type Deserializer Uses

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

Deserializer has Deserialize method to deserialize binary data to struct.

type Iterator Uses

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

Iterator defines an interator to read a set of states

func NewIterator Uses

func NewIterator(states [][]byte) Iterator

NewIterator returns an interator given a list of serialized states

type Serializer Uses

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

Serializer has Serialize method to serialize struct to binary data.

type State Uses

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



Package state imports 8 packages (graph) and is imported by 18 packages. Updated 2020-10-25. Refresh now. Tools for package owners.