factory

package
v0.5.0-rc10-hotfix1 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2019 License: Apache-2.0 Imports: 21 Imported by: 12

Documentation

Index

Constants

View Source
const (
	// AccountKVNameSpace is the bucket name for account trie
	AccountKVNameSpace = "Account"

	// CandidateKVNameSpace is the bucket name for candidate data storage
	CandidateKVNameSpace = "Candidate"

	// CurrentHeightKey indicates the key of current factory height in underlying DB
	CurrentHeightKey = "currentHeight"
	// AccountTrieRootKey indicates the key of accountTrie root hash in underlying DB
	AccountTrieRootKey = "accountTrieRoot"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Factory

type Factory interface {
	lifecycle.StartStopper
	// Accounts
	Balance(string) (*big.Int, error)
	Nonce(string) (uint64, error) // Note that Nonce starts with 1.
	AccountState(string) (*state.Account, error)
	RootHash() hash.Hash256
	RootHashByHeight(uint64) (hash.Hash256, error)
	Height() (uint64, error)
	NewWorkingSet() (WorkingSet, error)
	Commit(WorkingSet) error
	// Candidate pool
	CandidatesByHeight(uint64) ([]*state.Candidate, error)

	State(hash.Hash160, interface{}) error
	AddActionHandlers(...protocol.ActionHandler)
}

Factory defines an interface for managing states

func NewFactory

func NewFactory(cfg config.Config, opts ...Option) (Factory, error)

NewFactory creates a new state factory

func NewStateDB

func NewStateDB(cfg config.Config, opts ...StateDBOption) (Factory, error)

NewStateDB creates a new state db

type Option

type Option func(*factory, config.Config) error

Option sets Factory construction parameter

func DefaultTrieOption

func DefaultTrieOption() Option

DefaultTrieOption creates trie from config for state factory

func InMemTrieOption

func InMemTrieOption() Option

InMemTrieOption creates in memory trie for state factory

func PrecreatedTrieDBOption

func PrecreatedTrieDBOption(kv db.KVStore) Option

PrecreatedTrieDBOption uses pre-created trie DB for state factory

type StateDBOption

type StateDBOption func(*stateDB, config.Config) error

StateDBOption sets stateDB construction parameter

func DefaultStateDBOption

func DefaultStateDBOption() StateDBOption

DefaultStateDBOption creates trie from config for state db

func InMemStateDBOption

func InMemStateDBOption() StateDBOption

InMemStateDBOption creates in memory trie for state db

type WorkingSet

type WorkingSet interface {
	// states and actions
	//RunActions(context.Context, uint64, []action.SealedEnvelope) (map[hash.Hash32B]*action.Receipt, error)
	RunAction(protocol.RunActionsCtx, action.SealedEnvelope) (*action.Receipt, error)
	UpdateBlockLevelInfo(blockHeight uint64) hash.Hash256
	RunActions(context.Context, uint64, []action.SealedEnvelope) ([]*action.Receipt, error)
	Snapshot() int
	Revert(int) error
	Commit() error
	RootHash() hash.Hash256
	Digest() hash.Hash256
	Version() uint64
	Height() uint64
	// General state
	State(hash.Hash160, interface{}) error
	PutState(hash.Hash160, interface{}) error
	DelState(pkHash hash.Hash160) error
	GetDB() db.KVStore
	GetCachedBatch() db.CachedBatch
}

WorkingSet defines an interface for working set of states changes

func NewWorkingSet

func NewWorkingSet(
	version uint64,
	kv db.KVStore,
	root hash.Hash256,
	actionHandlers []protocol.ActionHandler,
) (WorkingSet, error)

NewWorkingSet creates a new working set

Jump to

Keyboard shortcuts

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