store

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2019 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// StateDbName is the filename of the kvstore
	StateDbName = "mstate"
)

Variables

View Source
var (
	// ErrOutOfBounds for the list
	ErrOutOfBounds = errors.New("Index out of bounds")
)
View Source
var (

	// ErrValueNotFound returned when the value for a key is nil
	ErrValueNotFound = errors.New("Store get: nil value for given key")
)

Functions

This section is empty.

Types

type KVCache

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

KVCache used by the app. It wraps a simple cache and access to the State Store

func NewCache

func NewCache(store *StateStore) *KVCache

NewCache return a fresh empty cache with ref to the State Store

func (*KVCache) ApplyToState

func (cache *KVCache) ApplyToState()

ApplyToState is called during abci.commit(). It sorts all keys in the cache for determinism, then writes the set to the tree

func (*KVCache) Delete added in v0.3.0

func (cache *KVCache) Delete(key []byte)

Delete a key/value

func (*KVCache) Exists added in v0.3.0

func (cache *KVCache) Exists(key []byte) bool

Exists - checks for a given key

func (*KVCache) Get

func (cache *KVCache) Get(key []byte) ([]byte, error)

Get a value for a given key. Try the cache first and then the state db

func (*KVCache) GetCommitted added in v0.3.0

func (cache *KVCache) GetCommitted(key []byte) ([]byte, error)

GetCommitted only returns committed data, nothing cached

func (*KVCache) IterateKeyRange

func (cache *KVCache) IterateKeyRange(start, end []byte, ascending bool, fn func(key []byte, value []byte) bool) bool

IterateKeyRange returns results that are processed via the callback func

func (*KVCache) Set

func (cache *KVCache) Set(key, val []byte)

Set a key in the cache

type List added in v0.3.0

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

List provides an array like structure over a key/value store using composite keys. The following format is used in the realize a list:

/{key}/count => num     (where num is the total number of items in a list for a given key)
/{key}/{index} => value (where index is list index pointing to the value )

key: Is a unique key used across the list Example:

Say we want to model that 'Each user has-many public keys'
We can use the List to capture this:
'bob' is our key...maybe an account address. So,
/bob/count => 3 (this means bob has 3 public keys)
/bob/0 => publickey{}
/bob/1 => publickey{}
/bob/2 => publickey{}

Everytime a new publickey{} is added for bob, the count is incremented and we use the count as an index into the list.

func NewList added in v0.3.0

func NewList(st *KVCache, key []byte) List

NewList returns a new or existing list based on the key

func (List) Clear added in v0.3.0

func (l List) Clear() error

Clear the list removing all values

func (List) Extend added in v0.3.0

func (l List) Extend(values [][]byte)

Extend the list for the given values, increasing the len Ex: if list A = [1,2] then A.extend([3,4,5]) => [1,2,3,4,5]

func (List) Get added in v0.3.0

func (l List) Get(index uint64) ([]byte, error)

Get a value at a given index. Will return an error if the given index is out of bounds.

func (List) IsEmpty added in v0.3.0

func (l List) IsEmpty() bool

IsEmpty -

func (List) Iterate added in v0.3.0

func (l List) Iterate(fn func(index uint64, value []byte) bool) bool

Iterate over entries in the *committed* list. The callback function will be passed each visited index and value. NOTE: The iterator will not return un-committed entries in the current cache

func (List) Len added in v0.3.0

func (l List) Len() uint64

Len returns the current length

func (List) Pop added in v0.3.0

func (l List) Pop() []byte

Pop removes and returns a value from the end of the list

func (List) Push added in v0.3.0

func (l List) Push(value []byte)

Push a new value on to the list

func (List) Set added in v0.3.0

func (l List) Set(index uint64, value []byte) error

Set (overwrite) a value at a given index. This will return an error if the index is out of bounds

func (List) Truncate added in v0.3.0

func (l List) Truncate(index uint64) error

Truncate - 'chop' off the end of the list at a given index Ex: if list A = [1,2,3,4,5] then A.Truncate(2) => [1,2]

type StateStore

type StateStore struct {
	CommitInfo sdk.CommitInfo
	// contains filtered or unexported fields
}

StateStore provides access the the levelDb and Tree

func NewStateStore

func NewStateStore(dbdir string) *StateStore

NewStateStore creates a new instance. If 'dbdir' == "", it'll return an in-memory database

func (*StateStore) Close

func (st *StateStore) Close()

Close the underlying db

func (*StateStore) Commit

func (st *StateStore) Commit() sdk.CommitInfo

Commit information about the current state to the db

func (*StateStore) Delete added in v0.3.0

func (st *StateStore) Delete(key []byte)

Delete a k/v from the tree

func (*StateStore) Get

func (st *StateStore) Get(key []byte) ([]byte, error)

Get returns committed data from the tree

func (*StateStore) GetCommitted added in v0.3.0

func (st *StateStore) GetCommitted(key []byte) ([]byte, error)

GetCommitted returns only committed data, nothing cached ** Implemented here to satisfy the KVStore interface. Need to improve this

func (*StateStore) IterateKeyRange

func (st *StateStore) IterateKeyRange(start, end []byte, ascending bool, fn func(key []byte, value []byte) bool) bool

IterateKeyRange - iterator non-inclusive

func (*StateStore) RefreshCache

func (st *StateStore) RefreshCache() sdk.Cache

RefreshCache clears existing k/v from the cache

func (*StateStore) Set

func (st *StateStore) Set(key, val []byte)

Set a k/v in the tree

Jump to

Keyboard shortcuts

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