state

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2018 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidAddr is the error that the address format is invalid, cannot be decoded
	ErrInvalidAddr = errors.New("address format is invalid")

	// ErrNotEnoughBalance is the error that the balance is not enough
	ErrNotEnoughBalance = errors.New("not enough balance")

	// ErrAccountNotExist is the error that the account does not exist
	ErrAccountNotExist = errors.New("the account does not exist")

	// ErrFailedToMarshalState is the error that the state marshaling is failed
	ErrFailedToMarshalState = errors.New("failed to marshal state")

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

Functions

This section is empty.

Types

type Candidate

type Candidate struct {
	Address string
	Votes   *big.Int
	PubKey  []byte
	// contains filtered or unexported fields
}

Candidate is used in the heap

type CandidateMaxPQ

type CandidateMaxPQ struct {
	Capacity int
	// contains filtered or unexported fields
}

CandidateMaxPQ is a max Priority Queue

func (*CandidateMaxPQ) CandidateList

func (pqStruct *CandidateMaxPQ) CandidateList() []*Candidate

CandidateList return a list of candidates

func (CandidateMaxPQ) Len

func (pqStruct CandidateMaxPQ) Len() int

func (CandidateMaxPQ) Less

func (pqStruct CandidateMaxPQ) Less(i, j int) bool

func (*CandidateMaxPQ) Pop

func (pqStruct *CandidateMaxPQ) Pop() interface{}

Pop pops a candidate in the heap

func (*CandidateMaxPQ) Push

func (pqStruct *CandidateMaxPQ) Push(x interface{})

Push pushes a candidate in the heap

func (CandidateMaxPQ) Swap

func (pqStruct CandidateMaxPQ) Swap(i, j int)

func (*CandidateMaxPQ) Top

func (pqStruct *CandidateMaxPQ) Top() interface{}

Top return the candidate with highest votes

type CandidateMinPQ

type CandidateMinPQ struct {
	Capacity int
	// contains filtered or unexported fields
}

CandidateMinPQ is a min Priority Queue

func (*CandidateMinPQ) CandidateList

func (pqStruct *CandidateMinPQ) CandidateList() []*Candidate

CandidateList return a list of candidates

func (CandidateMinPQ) Len

func (pqStruct CandidateMinPQ) Len() int

func (CandidateMinPQ) Less

func (pqStruct CandidateMinPQ) Less(i, j int) bool

func (*CandidateMinPQ) Pop

func (pqStruct *CandidateMinPQ) Pop() interface{}

Pop pops a candidate in the heap

func (*CandidateMinPQ) Push

func (pqStruct *CandidateMinPQ) Push(x interface{})

Push pushes a candidate in the heap

func (CandidateMinPQ) Swap

func (pqStruct CandidateMinPQ) Swap(i, j int)

func (*CandidateMinPQ) Top

func (pqStruct *CandidateMinPQ) Top() interface{}

Top returns the candidate with smallest votes

type Factory

type Factory interface {
	CreateState(string, uint64) (*State, error)
	Balance(string) (*big.Int, error)
	CommitStateChanges(uint64, []*action.Transfer, []*action.Vote) error
	// Note that nonce starts with 1.
	Nonce(string) (uint64, error)
	State(string) (*State, error)
	RootHash() common.Hash32B
	Candidates() (uint64, []*Candidate)
}

Factory defines an interface for managing states

func NewFactory

func NewFactory(tr trie.Trie) Factory

NewFactory creates a new state factory

func NewFactoryFromTrieDBPath

func NewFactoryFromTrieDBPath(dbPath string, inMem bool) (Factory, error)

NewFactoryFromTrieDBPath creates a new stateFactory from give trie db path.

type State

type State struct {
	// 0 is reserved from actions in genesis block and coinbase transfers nonces
	// other actions' nonces start from 1
	Nonce        uint64
	Balance      *big.Int
	Address      string
	IsCandidate  bool
	VotingWeight *big.Int
	Votee        string
	Voters       map[string]*big.Int
}

State is the canonical representation of an account.

func (*State) AddBalance

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

AddBalance adds balance for state

func (*State) SubBalance

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

SubBalance subtracts balance for state

Jump to

Keyboard shortcuts

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