cosmos-sdk/stack/prefixstore.go

32 lines
723 B
Go
Raw Normal View History

2017-07-10 13:57:18 -07:00
package stack
import "github.com/tendermint/basecoin/state"
type prefixStore struct {
prefix []byte
store state.KVStore
}
var _ state.KVStore = prefixStore{}
func (p prefixStore) Set(key, value []byte) {
key = append(key, p.prefix...)
p.store.Set(key, value)
}
func (p prefixStore) Get(key []byte) (value []byte) {
key = append(key, p.prefix...)
return p.store.Get(key)
}
// stateSpace will unwrap any prefixStore and then add the prefix
func stateSpace(store state.KVStore, app string) state.KVStore {
// unwrap one-level if wrapped
if pstore, ok := store.(prefixStore); ok {
store = pstore.store
}
// wrap it with the prefix
prefix := append([]byte(app), byte(0))
return prefixStore{prefix, store}
}