state

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2017 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

nolint

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrNotASubTransaction added in v0.7.0

func ErrNotASubTransaction() errors.TMError

func IsNotASubTransactionErr added in v0.7.0

func IsNotASubTransactionErr(err error) bool

func MakeBKey added in v0.7.0

func MakeBKey(key []byte) []byte

MakeBKey prefixes the byte slice for the storage key

func QueueHeadKey added in v0.7.0

func QueueHeadKey() []byte

QueueHeadKey gives us the key for the height at head of the queue

func QueueItemKey added in v0.7.0

func QueueItemKey(i uint64) []byte

QueueItemKey gives us the key to look up one item by sequence

func QueueTailKey added in v0.7.0

func QueueTailKey() []byte

QueueTailKey gives us the key for the height at tail of the queue

func SetKey added in v0.7.0

func SetKey() []byte

SetKey returns the key to get all members of this set

Types

type Bonsai added in v0.7.0

type Bonsai struct {
	Tree *iavl.VersionedTree
	// contains filtered or unexported fields
}

Bonsai is a deformed tree forced to fit in a small pot

func NewBonsai added in v0.7.0

func NewBonsai(tree *iavl.VersionedTree) *Bonsai

NewBonsai wraps a merkle tree and tags it to track children

func (*Bonsai) Checkpoint added in v0.7.0

func (b *Bonsai) Checkpoint() SimpleDB

func (*Bonsai) Commit added in v0.7.0

func (b *Bonsai) Commit(sub SimpleDB) error

func (*Bonsai) Discard added in v0.7.0

func (b *Bonsai) Discard()

Discard will remove reference to this

func (*Bonsai) First added in v0.7.0

func (b *Bonsai) First(start, end []byte) Model

func (*Bonsai) Get added in v0.7.0

func (b *Bonsai) Get(key []byte) []byte

Get matches the signature of KVStore

func (*Bonsai) GetVersionedWithProof added in v0.7.0

func (b *Bonsai) GetVersionedWithProof(key []byte, version uint64) ([]byte, iavl.KeyProof, error)

func (*Bonsai) GetWithProof added in v0.7.0

func (b *Bonsai) GetWithProof(key []byte) ([]byte, iavl.KeyProof, error)

func (*Bonsai) Has added in v0.7.0

func (b *Bonsai) Has(key []byte) bool

Get matches the signature of KVStore

func (*Bonsai) Last added in v0.7.0

func (b *Bonsai) Last(start, end []byte) Model

func (*Bonsai) List added in v0.7.0

func (b *Bonsai) List(start, end []byte, limit int) []Model

func (*Bonsai) Remove added in v0.7.0

func (b *Bonsai) Remove(key []byte) (value []byte)

func (*Bonsai) Set added in v0.7.0

func (b *Bonsai) Set(key, value []byte)

Set matches the signature of KVStore

func (*Bonsai) String added in v0.7.0

func (b *Bonsai) String() string

type ChainState added in v0.7.0

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

ChainState maintains general information for the chain

func NewChainState added in v0.7.0

func NewChainState() *ChainState

NewChainState creates a blank state

func (*ChainState) GetChainID added in v0.7.0

func (s *ChainState) GetChainID(store KVStore) string

GetChainID gets the chain id from the cache or the store

func (*ChainState) SetChainID added in v0.7.0

func (s *ChainState) SetChainID(store KVStore, chainID string)

SetChainID stores the chain id in the store

type KVStore added in v0.7.0

type KVStore interface {
	Set(key, value []byte)
	Get(key []byte) (value []byte)
}

KVStore is a simple interface to get/set data

type KeyList added in v0.7.0

type KeyList [][]byte

KeyList is a sortable list of byte slices

func (KeyList) Equals added in v0.7.0

func (kl KeyList) Equals(kl2 KeyList) bool

Equals checks for if the two lists have the same content... needed as == doesn't work for slices of slices

func (KeyList) Len added in v0.7.0

func (kl KeyList) Len() int

nolint

func (KeyList) Less added in v0.7.0

func (kl KeyList) Less(i, j int) bool

func (KeyList) Swap added in v0.7.0

func (kl KeyList) Swap(i, j int)

type MemKVCache added in v0.7.0

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

MemKVCache is designed to wrap MemKVStore as a cache

func NewMemKVCache added in v0.7.0

func NewMemKVCache(store SimpleDB) *MemKVCache

NewMemKVCache wraps a cache around MemKVStore

You probably don't want to use directly, but rather via MemKVCache.Checkpoint()

func (*MemKVCache) Checkpoint added in v0.7.0

func (c *MemKVCache) Checkpoint() SimpleDB

Checkpoint returns the same state, but where writes are buffered and don't affect the parent

func (*MemKVCache) Commit added in v0.7.0

func (c *MemKVCache) Commit(sub SimpleDB) error

Commit will take all changes from the checkpoint and write them to the parent. Returns an error if this is not a child of this one

func (*MemKVCache) Discard added in v0.7.0

func (c *MemKVCache) Discard()

Discard will remove reference to this

func (*MemKVCache) First added in v0.7.0

func (c *MemKVCache) First(start, end []byte) Model

First is done with List, but could be much more efficient

func (*MemKVCache) Get added in v0.7.0

func (c *MemKVCache) Get(key []byte) (value []byte)

Get gets a key, fulfills KVStore interface

func (*MemKVCache) Has added in v0.7.0

func (c *MemKVCache) Has(key []byte) bool

Has checks existence of a key, fulfills KVStore interface

func (*MemKVCache) Last added in v0.7.0

func (c *MemKVCache) Last(start, end []byte) Model

Last is done with List, but could be much more efficient

func (*MemKVCache) List added in v0.7.0

func (c *MemKVCache) List(start, end []byte, limit int) []Model

List is also inefficiently implemented...

func (*MemKVCache) Remove added in v0.7.0

func (c *MemKVCache) Remove(key []byte) (value []byte)

Remove uses nil value as a flag to delete... not ideal but good enough for testing

func (*MemKVCache) Set added in v0.7.0

func (c *MemKVCache) Set(key []byte, value []byte)

Set sets a key, fulfills KVStore interface

type MemKVStore added in v0.7.0

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

MemKVStore is a simple implementation of SimpleDB. It is only intended for quick testing, not to be used in production or with large data stores.

func NewMemKVStore added in v0.7.0

func NewMemKVStore() *MemKVStore

NewMemKVStore initializes a MemKVStore

func (*MemKVStore) Checkpoint added in v0.7.0

func (m *MemKVStore) Checkpoint() SimpleDB

func (*MemKVStore) Commit added in v0.7.0

func (m *MemKVStore) Commit(sub SimpleDB) error

func (*MemKVStore) Discard added in v0.7.0

func (m *MemKVStore) Discard()

func (*MemKVStore) First added in v0.7.0

func (m *MemKVStore) First(start, end []byte) Model

First iterates through all keys to find the one that matches

func (*MemKVStore) Get added in v0.7.0

func (m *MemKVStore) Get(key []byte) (value []byte)

func (*MemKVStore) Has added in v0.7.0

func (m *MemKVStore) Has(key []byte) (has bool)

func (*MemKVStore) Last added in v0.7.0

func (m *MemKVStore) Last(start, end []byte) Model

func (*MemKVStore) List added in v0.7.0

func (m *MemKVStore) List(start, end []byte, limit int) []Model

func (*MemKVStore) Remove added in v0.7.0

func (m *MemKVStore) Remove(key []byte) (value []byte)

func (*MemKVStore) Set added in v0.7.0

func (m *MemKVStore) Set(key []byte, value []byte)

type Model added in v0.7.0

type Model struct {
	Key   data.Bytes
	Value data.Bytes
}

Model grabs together key and value to allow easier return values

type Queue added in v0.7.0

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

Queue allows us to fill up a range of the db, and grab from either end

func NewQueue added in v0.7.0

func NewQueue(store KVStore) *Queue

NewQueue will load or initialize a queue in this state-space

Generally, you will want to stack.PrefixStore() the space first

func (*Queue) Item added in v0.7.0

func (q *Queue) Item(seq uint64) []byte

Item looks at any element in the queue, without modifying anything

func (*Queue) Pop added in v0.7.0

func (q *Queue) Pop() []byte

Pop gets an element from the end of the queue

func (*Queue) Push added in v0.7.0

func (q *Queue) Push(value []byte) uint64

Push adds an element to the tail of the queue and returns it's location

func (*Queue) Size added in v0.7.0

func (q *Queue) Size() int

Size returns how many elements are in the queue

func (*Queue) Tail added in v0.7.0

func (q *Queue) Tail() uint64

Tail returns the next slot that Push() will use

type Set added in v0.7.0

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

Set allows us to add arbitrary k-v pairs, check existence, as well as iterate through the set (always in key order)

If we had full access to the IAVL tree, this would be completely trivial and redundant

func NewSet added in v0.7.0

func NewSet(store KVStore) *Set

NewSet loads or initializes a span of keys

func (*Set) Exists added in v0.7.0

func (s *Set) Exists(key []byte) bool

Exists checks for the existence of the key in the set

func (*Set) Get added in v0.7.0

func (s *Set) Get(key []byte) []byte

Get returns the element with a key if it exists

func (*Set) List added in v0.7.0

func (s *Set) List() (keys KeyList)

List returns all keys in the set It makes a copy, so we don't modify this in place

func (*Set) Remove added in v0.7.0

func (s *Set) Remove(key []byte)

Remove deletes this key from the set (same as setting value = nil)

func (*Set) Set added in v0.7.0

func (s *Set) Set(key []byte, value []byte)

Set puts a value at a given height. If the value is nil, or an empty slice, remove the key from the list

func (*Set) Size added in v0.7.0

func (s *Set) Size() int

Size returns how many elements are in the set

type SimpleDB added in v0.7.0

type SimpleDB interface {
	KVStore

	Has(key []byte) (has bool)
	Remove(key []byte) (value []byte) // returns old value if there was one

	// Start is inclusive, End is exclusive...
	// Thus List ([]byte{12, 13}, []byte{12, 14}) will return anything with
	// the prefix []byte{12, 13}
	List(start, end []byte, limit int) []Model
	First(start, end []byte) Model
	Last(start, end []byte) Model

	// Checkpoint returns the same state, but where writes
	// are buffered and don't affect the parent
	Checkpoint() SimpleDB

	// Commit will take all changes from the checkpoint and write
	// them to the parent.
	// Returns an error if this is not a child of this one
	Commit(SimpleDB) error

	// Discard will remove reference to this
	Discard()
}

SimpleDB allows us to do some basic range queries on a db

type Span added in v0.7.0

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

Span holds a number of different keys in a large range and allows use to make some basic range queries, like highest between, lowest between... All items are added with an index

This becomes horribly inefficent as len(keys) => 1000+, but by then hopefully we have access to the iavl tree to do this well

TODO: doesn't handle deleting....

func NewSpan added in v0.7.0

func NewSpan(store KVStore) *Span

NewSpan loads or initializes a span of keys

func (*Span) Bottom added in v0.7.0

func (s *Span) Bottom() ([]byte, uint64)

Bottom returns the lowest element in the Span, along with its index

func (*Span) GTE added in v0.7.0

func (s *Span) GTE(h uint64) ([]byte, uint64)

GTE returns the lowest element in the Span that is >= h, along with its index

func (*Span) Get added in v0.7.0

func (s *Span) Get(h uint64) []byte

Get returns the element at h if it exists

func (*Span) LTE added in v0.7.0

func (s *Span) LTE(h uint64) ([]byte, uint64)

LTE returns the highest element in the Span that is <= h, along with its index

func (*Span) Set added in v0.7.0

func (s *Span) Set(h uint64, value []byte)

Set puts a value at a given height

func (*Span) Top added in v0.7.0

func (s *Span) Top() ([]byte, uint64)

Top returns the highest element in the Span, along with its index

type State

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

State represents the app states, separating the commited state (for queries) from the working state (for CheckTx and AppendTx)

func NewState

func NewState(tree *iavl.VersionedTree) State

func (State) Append added in v0.7.0

func (s State) Append() SimpleDB

func (*State) BatchSet added in v0.7.0

func (s *State) BatchSet(key, value []byte)

BatchSet is used for some weird magic in storing the new height

func (State) Check added in v0.7.0

func (s State) Check() SimpleDB

func (*State) Commit

func (s *State) Commit(version uint64) ([]byte, error)

Commit save persistent nodes to the database and re-copies the trees

func (State) Committed added in v0.7.0

func (s State) Committed() *Bonsai

func (State) LatestHash added in v0.7.0

func (s State) LatestHash() []byte

func (State) LatestHeight added in v0.7.0

func (s State) LatestHeight() uint64

func (State) Size added in v0.7.0

func (s State) Size() int

Jump to

Keyboard shortcuts

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