dposstate

package
v0.0.0-...-84d53aa Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2019 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CandidatePrefix = "c_" // alias account prefix for account state trie
	DynastyPrefix   = "d_" // alias account prefix for account state trie
)

TODO applying prefix Prefixes for blockState trie

Variables

This section is empty.

Functions

This section is empty.

Types

type Candidate

type Candidate struct {
	ID         []byte // candidate id = txHash
	Addr       common.Address
	Collateral *util.Uint128 // candidate collateral
	VotePower  *util.Uint128 // sum of voters' staking
	URL        string
	Timestamp  int64
}

Candidate is struct for save candidate state

func (*Candidate) FromBytes

func (c *Candidate) FromBytes(bytes []byte) error

FromBytes set Candidate struct from bytes

func (*Candidate) String

func (c *Candidate) String() string

String returns string representation of candidate

func (*Candidate) ToBytes

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

ToBytes marshal Candidate struct to bytes

type State

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

State is a structure for dpos state

func NewDposState

func NewDposState(candidateStateHash []byte, dynastyStateHash []byte, stor storage.Storage) (*State, error)

NewDposState returns new dpos state

func (*State) AddVotePowerToCandidate

func (s *State) AddVotePowerToCandidate(id []byte, amount *util.Uint128) error

AddVotePowerToCandidate add vote power to candidate

func (*State) BeginBatch

func (s *State) BeginBatch() error

BeginBatch begin batch

func (*State) Clone

func (s *State) Clone() (*State, error)

Clone clone state

func (*State) Commit

func (s *State) Commit() error

Commit saves batch to state

func (*State) DelCandidate

func (s *State) DelCandidate(cid []byte) error

DelCandidate del candidate from candidate state

func (*State) Flush

func (s *State) Flush() error

Flush flush data to storage

func (*State) GetCandidate

func (s *State) GetCandidate(cid []byte) (*Candidate, error)

GetCandidate returns candidate from candidate state

func (*State) GetCandidates

func (s *State) GetCandidates() ([]*Candidate, error)

GetCandidates returns candidate list from candidate state.

func (*State) GetProposer

func (s *State) GetProposer(index int) (common.Address, error)

GetProposer returns proposer address of index

func (*State) Prepare

func (s *State) Prepare() error

Prepare prepare trie

func (*State) PutCandidate

func (s *State) PutCandidate(cid []byte, candidate *Candidate) error

PutCandidate puts candidate to candidate state

func (*State) PutProposer

func (s *State) PutProposer(index int, addr common.Address) error

PutProposer sets proposer address to index

func (*State) Reset

func (s *State) Reset() error

Reset reset trie's refCounter

func (*State) RollBack

func (s *State) RollBack() error

RollBack rollback batch

func (*State) RootBytes

func (s *State) RootBytes() ([]byte, error)

RootBytes returns root bytes for dpos state

func (*State) SetDynasty

func (s *State) SetDynasty(dynasty []common.Address) error

SetDynasty set dynastyState by using dynasty slice

func (*State) SortByVotePower

func (s *State) SortByVotePower() ([]common.Address, error)

SortByVotePower returns Descending ordered candidate slice

func (*State) SubVotePowerToCandidate

func (s *State) SubVotePowerToCandidate(id []byte, amount *util.Uint128) error

SubVotePowerToCandidate sub vote power from candidate's vote power

Jump to

Keyboard shortcuts

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