state

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: May 8, 2018 License: LGPL-3.0 Imports: 11 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBalanceInsufficient     = errors.New("cannot subtract a value which is bigger than current balance")
	ErrAccountNotFound         = errors.New("cannot found account in storage")
	ErrContractAccountNotFound = errors.New("cannot found contract account in storage please check contract address is valid or deploy is success")
)

Errors

View Source
var (
	ErrCannotPrepareTxStateTwice           = errors.New("cannot prepare tx state twice")
	ErrCannotCloneOngoingWorldState        = errors.New("cannot clone an ongoing world state")
	ErrCannotBeginWorldStateTwice          = errors.New("cannot begin a world state twice")
	ErrCannotCommitWorldStateBeforeBegin   = errors.New("cannot commit a world state before begin")
	ErrCannotRollBackWorldStateBeforeBegin = errors.New("cannot rollback a world state before begin")
	ErrCannotPrepareTxStateBeforeBegin     = errors.New("cannot prepare a tx state before begin")
	ErrCannotCheckTxStateBeforePrepare     = errors.New("cannot check a tx state before prepare")
	ErrCannotUpdateTxStateBeforePrepare    = errors.New("cannot update a tx state before prepare")
	ErrCannotResetTxStateBeforePrepare     = errors.New("cannot reset a tx state before prepare")
	ErrContractCheckFailed                 = errors.New("contract check failed")
)

Errors

Functions

This section is empty.

Types

type Account

type Account interface {
	Address() byteutils.Hash
	Balance() *util.Uint128
	Nonce() uint64
	BirthPlace() byteutils.Hash
	VarsHash() byteutils.Hash

	Clone() (Account, error)

	ToBytes() ([]byte, error)
	FromBytes(bytes []byte, storage storage.Storage) error

	IncrNonce()
	AddBalance(value *util.Uint128) error
	SubBalance(value *util.Uint128) error
	Put(key []byte, value []byte) error
	Get(key []byte) ([]byte, error)
	Del(key []byte) error
	Iterator(prefix []byte) (Iterator, error)
}

Account Interface

type AccountState

type AccountState interface {
	RootHash() byteutils.Hash

	Flush() error
	Abort() error

	DirtyAccounts() ([]Account, error)
	Accounts() ([]Account, error)

	Clone() (AccountState, error)
	Replay(AccountState) error

	GetOrCreateUserAccount(byteutils.Hash) (Account, error)
	GetContractAccount(byteutils.Hash) (Account, error)
	CreateContractAccount(byteutils.Hash, byteutils.Hash) (Account, error)
}

AccountState Interface

func NewAccountState

func NewAccountState(root byteutils.Hash, storage storage.Storage) (AccountState, error)

NewAccountState create a new account state

type Consensus

type Consensus interface {
	NewState(*consensuspb.ConsensusRoot, storage.Storage, bool) (ConsensusState, error)
}

Consensus interface

type ConsensusState

type ConsensusState interface {
	RootHash() *consensuspb.ConsensusRoot
	String() string
	Clone() (ConsensusState, error)
	Replay(ConsensusState) error

	Proposer() byteutils.Hash
	TimeStamp() int64
	NextConsensusState(int64, WorldState) (ConsensusState, error)

	Dynasty() ([]byteutils.Hash, error)
	DynastyRoot() byteutils.Hash
}

ConsensusState interface of consensus state

type Event

type Event struct {
	Topic string
	Data  string
}

Event event structure.

type Iterator

type Iterator interface {
	Next() (bool, error)
	Value() []byte
}

Iterator Variables in Account Storage

type TxWorldState

type TxWorldState interface {
	AccountsRoot() byteutils.Hash
	TxsRoot() byteutils.Hash
	EventsRoot() byteutils.Hash
	ConsensusRoot() *consensuspb.ConsensusRoot

	CheckAndUpdate() ([]interface{}, error)
	Reset() error
	Close() error

	Accounts() ([]Account, error)
	GetOrCreateUserAccount(addr byteutils.Hash) (Account, error)
	GetContractAccount(addr byteutils.Hash) (Account, error)
	CreateContractAccount(owner byteutils.Hash, birthPlace byteutils.Hash) (Account, error)

	GetTx(txHash byteutils.Hash) ([]byte, error)
	PutTx(txHash byteutils.Hash, txBytes []byte) error

	RecordEvent(txHash byteutils.Hash, event *Event)
	FetchEvents(byteutils.Hash) ([]*Event, error)

	Dynasty() ([]byteutils.Hash, error)
	DynastyRoot() byteutils.Hash

	RecordGas(from string, gas *util.Uint128) error
}

TxWorldState is the world state of a single transaction

type WorldState

type WorldState interface {
	Begin() error
	Commit() error
	RollBack() error

	Prepare(interface{}) (TxWorldState, error)
	Reset() error
	Flush() error
	Abort() error

	LoadAccountsRoot(byteutils.Hash) error
	LoadTxsRoot(byteutils.Hash) error
	LoadEventsRoot(byteutils.Hash) error
	LoadConsensusRoot(*consensuspb.ConsensusRoot) error

	NextConsensusState(int64) (ConsensusState, error)
	SetConsensusState(ConsensusState)

	Clone() (WorldState, error)

	AccountsRoot() byteutils.Hash
	TxsRoot() byteutils.Hash
	EventsRoot() byteutils.Hash
	ConsensusRoot() *consensuspb.ConsensusRoot

	Accounts() ([]Account, error)
	GetOrCreateUserAccount(addr byteutils.Hash) (Account, error)
	GetContractAccount(addr byteutils.Hash) (Account, error)
	CreateContractAccount(owner byteutils.Hash, birthPlace byteutils.Hash) (Account, error)

	GetTx(txHash byteutils.Hash) ([]byte, error)
	PutTx(txHash byteutils.Hash, txBytes []byte) error

	RecordEvent(txHash byteutils.Hash, event *Event)
	FetchEvents(byteutils.Hash) ([]*Event, error)

	Dynasty() ([]byteutils.Hash, error)
	DynastyRoot() byteutils.Hash

	RecordGas(from string, gas *util.Uint128) error
	GetGas() map[string]*util.Uint128
}

WorldState interface of world state

func NewWorldState

func NewWorldState(consensus Consensus, storage storage.Storage) (WorldState, error)

NewWorldState create a new empty WorldState

Jump to

Keyboard shortcuts

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