types and store compile

This commit is contained in:
Ethan Buchman
2018-01-12 19:17:17 -08:00
committed by Jae Kwon
parent fcd8e88e65
commit 5e46eea616
6 changed files with 95 additions and 54 deletions
+7 -4
View File
@@ -2,6 +2,8 @@ package types
import (
"context"
"sync"
"github.com/golang/protobuf/proto"
abci "github.com/tendermint/abci/types"
@@ -83,7 +85,7 @@ func (c Context) WithProtoMsg(key interface{}, value proto.Message) Context {
return c.withValue(key, value)
}
func (c Context) WithMultiStore(key *MultiStoreKey, ms MultiStore) Context {
func (c Context) WithMultiStore(key *KVStoreKey, ms MultiStore) Context {
return c.withValue(key, ms)
}
@@ -218,7 +220,7 @@ type thePast struct {
func newThePast() *thePast {
return &thePast{
val: 0,
ver: 0,
ops: nil,
}
}
@@ -238,10 +240,11 @@ func (pst *thePast) version() int {
// Returns false if ver > 0.
// The first operation is version 1.
func (pst *thePast) getOp(ver int) (Op, bool) {
func (pst *thePast) getOp(ver int64) (Op, bool) {
pst.mtx.RLock()
defer pst.mtx.RUnlock()
if len(pst.ops) < ver {
l := int64(len(pst.ops))
if l < ver {
return Op{}, false
} else {
return pst.ops[ver-1], true
+36 -7
View File
@@ -27,8 +27,8 @@ type MultiStore interface {
CacheMultiStore() CacheMultiStore
// Convenience for fetching substores.
GetStore(name string) interface{}
GetKVStore(name string) KVStore
GetStore(SubstoreKey) interface{}
GetKVStore(SubstoreKey) KVStore
}
// From MultiStore.CacheMultiStore()....
@@ -54,10 +54,10 @@ type CommitMultiStore interface {
MultiStore
// Add a substore loader.
SetSubstoreLoader(name string, loader CommitStoreLoader)
SetSubstoreLoader(key SubstoreKey, loader CommitStoreLoader)
// Gets the substore, which is a CommitSubstore.
GetSubstore(name string) CommitStore
GetSubstore(key SubstoreKey) CommitStore
// Load the latest persisted version.
// Called once after all calls to SetSubstoreLoader are complete.
@@ -148,7 +148,7 @@ type CacheWrap interface {
}
//----------------------------------------
// etc
// CommitID
// CommitID contains the tree version number and its merkle root.
type CommitID struct {
@@ -164,5 +164,34 @@ func (cid CommitID) String() string {
return fmt.Sprintf("CommitID{%v:%X}", cid.Hash, cid.Version)
}
// new(KVStoreKey) is a capabilities key.
type KVStoreKey struct{}
//----------------------------------------
// Keys for accessing substores
// SubstoreKey is a key used to index substores.
type SubstoreKey interface {
Name() string
String() string
}
// KVStoreKey is used for accessing substores.
// Only the pointer value should ever be used - it functions as a capabilities key.
type KVStoreKey struct {
name string
}
// NewKVStoreKey returns a new pointer to a KVStoreKey.
// Use a pointer so keys don't collide.
func NewKVStoreKey(name string) *KVStoreKey {
return &KVStoreKey{
name: name,
}
}
func (key *KVStoreKey) Name() string {
return key.name
}
func (key *KVStoreKey) String() string {
return fmt.Sprintf("KVStoreKey{%p, %s}", key, key.name)
}