state

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2021 License: Apache-2.0, BSD-2-Clause Imports: 14 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitLogger

func InitLogger()

func IsRequestCompleted

func IsRequestCompleted(addr *coretypes.ChainID, reqid *coretypes.RequestID) (bool, error)

func LoadSolidState

func LoadSolidState(chainID *coretypes.ChainID) (VirtualState, Block, bool, error)

func NewEmptyVirtualState

func NewEmptyVirtualState(chainID *coretypes.ChainID) *virtualState

func NewVirtualState

func NewVirtualState(db kvstore.KVStore, chainID *coretypes.ChainID) *virtualState

Types

type Block added in v0.1.0

type Block interface {
	ForEach(func(uint16, StateUpdate) bool)
	StateIndex() uint32
	WithBlockIndex(uint32) Block
	StateTransactionID() valuetransaction.ID
	WithStateTransaction(valuetransaction.ID) Block
	Timestamp() int64
	Size() uint16
	RequestIDs() []*coretypes.RequestID
	EssenceHash() hashing.HashValue // except state transaction id
	String() string
	Write(io.Writer) error
	Read(io.Reader) error
}

Block is a sequence of state updates applicable to the variable state

func LoadBlock added in v0.1.0

func LoadBlock(chainID *coretypes.ChainID, stateIndex uint32) (Block, error)

func MustNewOriginBlock added in v0.1.0

func MustNewOriginBlock(color *balance.Color) Block

block with empty state update and nil state hash

func NewBlock added in v0.1.0

func NewBlock(stateUpdates []StateUpdate) (Block, error)

validates, enumerates and creates a block from array of state updates

func NewBlockFromBytes added in v0.1.0

func NewBlockFromBytes(data []byte) (Block, error)

type StateUpdate

type StateUpdate interface {
	// request which resulted in this state update
	RequestID() *coretypes.RequestID
	Timestamp() int64
	WithTimestamp(int64) StateUpdate
	// the payload of variables/values
	String() string
	Mutations() buffered.MutationSequence
	Clone() StateUpdate
	Write(io.Writer) error
	Read(io.Reader) error
}

State update represents update to the variable state it is calculated by the VM (in batches) State updates comes in batches, all state updates within one block has same state index, state tx id and block size. ResultBlock index is unique in block ResultBlock is completed when it contains one state update for each index

func NewStateUpdate

func NewStateUpdate(reqid *coretypes.RequestID) StateUpdate

func NewStateUpdateRead

func NewStateUpdateRead(r io.Reader) (StateUpdate, error)

type VirtualState

type VirtualState interface {
	// index of the current state. State index is incremented when state transition occurs
	// index 0 means origin state
	BlockIndex() uint32
	ApplyBlockIndex(uint32)
	// timestamp
	Timestamp() int64
	// updates state without changing state index
	ApplyStateUpdate(stateUpd StateUpdate)
	// applies block of state updates, state index and timestamp
	ApplyBlock(Block) error
	// commit means saving virtual state to sc db, making it persistent (solid)
	CommitToDb(batch Block) error
	// return hash of the variable state. It is a root of the Merkle chain of all
	// state updates starting from the origin
	Hash() hashing.HashValue
	// the storage of variable/value pairs
	Variables() buffered.BufferedKVStore
	Clone() VirtualState
	DangerouslyConvertToString() string
}

represents an interface to the mutable state of the smart contract

Jump to

Keyboard shortcuts

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