state

package
v0.6.1 Latest Latest
Warning

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

Go to latest
Published: May 24, 2019 License: Apache-2.0 Imports: 8 Imported by: 5 modules, 41 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

This section is empty.

Variables

View Source
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")
)
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")
)

Functions

func CandidatesToMap added in v0.3.0

func CandidatesToMap(candidates CandidateList) (map[hash.Hash160]*Candidate, error)

CandidatesToMap converts a candidate list to map of cachedCandidates

func Deserialize added in v0.3.0

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

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

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

func EmptyAccount() Account

EmptyAccount returns an empty account

func (*Account) AddBalance added in v0.4.0

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

AddBalance adds balance for account state

func (*Account) Clone added in v0.4.4

func (st *Account) Clone() *Account

Clone clones the account state

func (*Account) Deserialize added in v0.4.0

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

Deserialize deserializes bytes into account state

func (*Account) FromProto added in v0.4.0

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

FromProto converts from protobuf's Account

func (*Account) IsContract added in v0.5.0

func (st *Account) IsContract() bool

IsContract returns true for contract account

func (Account) Serialize added in v0.4.0

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

Serialize serializes account state into bytes

func (*Account) SubBalance added in v0.4.0

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

SubBalance subtracts balance for account state

func (*Account) ToProto added in v0.4.0

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

ToProto converts to protobuf's Account

type Candidate

type Candidate struct {
	Address       string
	Votes         *big.Int
	RewardAddress string
}

Candidate indicates the structure of a candidate

func (*Candidate) Equal added in v0.5.0

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

Equal compares two candidate instances

type CandidateList added in v0.3.0

type CandidateList []*Candidate

CandidateList indicates the list of Candidates which is sortable

func MapToCandidates added in v0.3.0

func MapToCandidates(candidateMap map[hash.Hash160]*Candidate) (CandidateList, error)

MapToCandidates converts a map of cachedCandidates to candidate list

func (*CandidateList) Deserialize added in v0.4.0

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

Deserialize deserializes bytes to list of Candidates

func (CandidateList) Len added in v0.3.0

func (l CandidateList) Len() int

func (CandidateList) Less added in v0.3.0

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

func (*CandidateList) LoadProto added in v0.5.0

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

LoadProto loads candidate list from proto

func (*CandidateList) Proto added in v0.5.0

Proto converts the candidate list to a protobuf message

func (*CandidateList) Serialize added in v0.4.0

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

Serialize serializes a list of Candidates to bytes

func (CandidateList) Swap added in v0.3.0

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

type Deserializer added in v0.4.4

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

Deserializer has Deserialize method to deserialize binary data to struct.

type Serializer added in v0.4.4

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