state

package
v1.8.0-rc.21 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2022 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// IDTypeID is the type ID for ids.ID
	IDTypeID uint64 = math.MaxUint64 - iota
	// StatusTypeID is the type ID for choices.Status
	StatusTypeID
	// TimeTypeID is the type ID for time
	TimeTypeID
	// BlockTypeID is the type ID of blocks in state
	BlockTypeID
)

Variables

This section is empty.

Functions

This section is empty.

Types

type State

type State interface {
	// In [db], add a key-value pair.
	// [value] will be converted to bytes by calling Bytes() on it.
	// [typeID] must have already been registered using RegisterType.
	// If [value] is nil, the value associated with [key] and [typeID] is deleted (if it exists).
	Put(db database.Database, typeID uint64, key ids.ID, value interface{}) error

	// From [db], get the value of type [typeID] whose key is [key]
	// Returns database.ErrNotFound if the entry doesn't exist
	Get(db database.Database, typeID uint64, key ids.ID) (interface{}, error)

	// Return whether [key] exists in [db] for type [typeID]
	Has(db database.Database, typeID uint64, key ids.ID) (bool, error)

	// PutStatus associates [key] with [status] in [db]
	PutStatus(db database.Database, key ids.ID, status choices.Status) error

	// GetStatus gets the status associated with [key] in [db]
	GetStatus(db database.Database, key ids.ID) choices.Status

	// PutID associates [key] with [ID] in [db]
	PutID(db database.Database, key ids.ID, ID ids.ID) error

	// GetID gets the ID associated with [key] in [db]
	GetID(db database.Database, key ids.ID) (ids.ID, error)

	// PutTime associates [key] with [time] in [db]
	PutTime(db database.Database, key ids.ID, time time.Time) error

	// GetTime gets the time associated with [key] in [db]
	GetTime(db database.Database, key ids.ID) (time.Time, error)

	// Register a new type.
	// When values that were Put with [typeID] are retrieved from the database,
	// they will be unmarshaled from bytes using [unmarshal].
	// Returns an error if there is already a type with ID [typeID]
	RegisterType(typeID uint64,
		marshal func(interface{}) ([]byte, error),
		unmarshal func([]byte) (interface{}, error),
	) error
}

State is a key-value store where every value is associated with a "type ID". Every different type of value must have its own type ID.

For example, if you're storing blocks, accounts and addresses, each of those types must have their own type ID.

Each type ID is associated with a function that specifies how to unmarshal bytes to a struct/value of a given type.

State has built-in support for putting and getting choices.Status and ids.ID To put/get any other type, you must first register that type using RegisterType

func NewState

func NewState() (State, error)

NewState returns a new State

Jump to

Keyboard shortcuts

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