state

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2018 License: LGPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrKeyExisted          = fmt.Errorf("key already existed")
	ErrKeyNotExist         = fmt.Errorf("key not existed")
	ErrInvalidNonce        = fmt.Errorf("invalid nonce")
	ErrInsufficientBalance = fmt.Errorf("balance is lower than the amount to be executed")
)

Functions

func JointKvDataKey

func JointKvDataKey(acc, key string) (rkey string)

key is dangerous, so be carefull

func KVDataFromBytes

func KVDataFromBytes(key string, data []byte) (cvtypes.StateDataItfc, error)

func KvDataSplit

func KvDataSplit(str string) (acc, key string)

func RemoteAccFromBytes

func RemoteAccFromBytes(key string, data []byte) (cvtypes.StateDataItfc, error)

Types

type ModifiedUndoItfc

type ModifiedUndoItfc interface {
	Undo(state cvtypes.StateItfc)
	Copy() ModifiedUndoItfc
}

type ModifyBalanceUndo

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

func (*ModifyBalanceUndo) Copy

func (*ModifyBalanceUndo) Undo

func (n *ModifyBalanceUndo) Undo(state cvtypes.StateItfc)

type ModifyKvUndo

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

func (*ModifyKvUndo) Copy

func (n *ModifyKvUndo) Copy() ModifiedUndoItfc

func (*ModifyKvUndo) Undo

func (n *ModifyKvUndo) Undo(state cvtypes.StateItfc)

type ModifyNonceUndo

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

func (*ModifyNonceUndo) Copy

func (*ModifyNonceUndo) Undo

func (n *ModifyNonceUndo) Undo(state cvtypes.StateItfc)

type RemoteAccount

type RemoteAccount struct {
	cvtypes.RemoteAccountData
	// contains filtered or unexported fields
}

func (*RemoteAccount) AddBalance

func (ra *RemoteAccount) AddBalance(add *big.Int)

func (*RemoteAccount) AddNonce

func (ra *RemoteAccount) AddNonce(add uint64)

func (*RemoteAccount) Bytes

func (ra *RemoteAccount) Bytes() ([]byte, error)

func (*RemoteAccount) Copy

func (ra *RemoteAccount) Copy() cvtypes.StateDataItfc

func (*RemoteAccount) DelKv

func (ra *RemoteAccount) DelKv(key string)

func (*RemoteAccount) GetBalance

func (ra *RemoteAccount) GetBalance() *big.Int

func (*RemoteAccount) GetKv

func (ra *RemoteAccount) GetKv(key string) []byte

func (*RemoteAccount) GetNonce

func (ra *RemoteAccount) GetNonce() uint64

func (*RemoteAccount) Init

func (ra *RemoteAccount) Init(accID string, balance *big.Int, state *RemoteState)

func (*RemoteAccount) Key

func (ra *RemoteAccount) Key() string

func (*RemoteAccount) Load

func (ra *RemoteAccount) Load(state *RemoteState)

func (*RemoteAccount) OnCommit

func (ra *RemoteAccount) OnCommit() error

func (*RemoteAccount) SetKv

func (ra *RemoteAccount) SetKv(key string, value []byte) (err error)

func (*RemoteAccount) SubBalance

func (ra *RemoteAccount) SubBalance(sub *big.Int) error

type RemoteState

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

func NewRemoteState

func NewRemoteState(database db.DB, log *zap.Logger) *RemoteState

func (*RemoteState) AccDelKv

func (rs *RemoteState) AccDelKv(accID string, key string)

func (*RemoteState) AccGetKv

func (rs *RemoteState) AccGetKv(accID string, key string) []byte

func (*RemoteState) AccSetKv

func (rs *RemoteState) AccSetKv(accID string, key string, value []byte) error

func (*RemoteState) AddNonce

func (rs *RemoteState) AddNonce(accID string, add uint64)

func (*RemoteState) Copy

func (rs *RemoteState) Copy() *RemoteState

func (*RemoteState) CreateRemoteAcc

func (rs *RemoteState) CreateRemoteAcc(accID string, balance *big.Int) *RemoteAccount

func (*RemoteState) GetBalance

func (rs *RemoteState) GetBalance(accID string) *big.Int

func (*RemoteState) GetNonce

func (rs *RemoteState) GetNonce(accID string) uint64

func (*RemoteState) RemoteAcc

func (rs *RemoteState) RemoteAcc(accID string) *RemoteAccount

func (*RemoteState) RevertToSnapshot

func (rs *RemoteState) RevertToSnapshot(version int)

func (*RemoteState) Snapshot

func (rs *RemoteState) Snapshot() int

func (*RemoteState) Transfer

func (rs *RemoteState) Transfer(fromID, toID string, balance *big.Int) bool

type RevertLayer

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

func (*RevertLayer) Copy

func (rl *RevertLayer) Copy() *RevertLayer

func (*RevertLayer) Init

func (rl *RevertLayer) Init(state cvtypes.StateItfc)

func (*RevertLayer) RevertToVerstion

func (rl *RevertLayer) RevertToVerstion(v int)

func (*RevertLayer) Snapshot

func (rl *RevertLayer) Snapshot() int

type StVersion

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

type State

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

func NewState

func NewState(database db.DB) *State

func (*State) Commit

func (os *State) Commit() ([]byte, error)

Commit returns the new root bytes

func (*State) Copy

func (os *State) Copy() (cp *State)

func (*State) CreateData

func (os *State) CreateData(acc cvtypes.StateDataItfc) (err error)

func (*State) ExistData

func (os *State) ExistData(accID string) bool

func (*State) GetData

func (os *State) GetData(accID string, fromBytes cvtypes.FromBytesFunc) (acc cvtypes.StateDataItfc, err error)

func (*State) Load

func (os *State) Load(root []byte)

Load dumps all the buffer, start every thing from a clean slate

func (*State) Lock

func (os *State) Lock()

func (*State) MarkModified

func (os *State) MarkModified(key string)

MarkModified puts accounts into dirty cache and they will be persisted during commit

func (*State) ModifyData

func (os *State) ModifyData(key string, data cvtypes.StateDataItfc)

func (*State) Reload

func (os *State) Reload(root []byte)

Reload works the same as Load, just for semantic purpose

func (*State) RemoveData

func (os *State) RemoveData(accID string) bool

RemoveData acts in a sync-block way remove related bufferred data and remove the data from db immediately

func (*State) Unlock

func (os *State) Unlock()

type StateKvData

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

for RemoteAccount, the key of saved KVdata should always like "<acc>-<user-key>"

func (*StateKvData) Bytes

func (k *StateKvData) Bytes() ([]byte, error)

func (*StateKvData) Copy

func (k *StateKvData) Copy() cvtypes.StateDataItfc

func (*StateKvData) Init

func (k *StateKvData) Init(key string, value []byte)

func (*StateKvData) Key

func (k *StateKvData) Key() string

func (*StateKvData) OnCommit

func (k *StateKvData) OnCommit() error

func (*StateKvData) Reset

func (k *StateKvData) Reset(key string, value []byte)

Jump to

Keyboard shortcuts

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