Update cli to properly query into app state-space
This commit is contained in:
+18
-9
@@ -20,26 +20,35 @@ func (p prefixStore) Get(key []byte) (value []byte) {
|
||||
}
|
||||
|
||||
// stateSpace will unwrap any prefixStore and then add the prefix
|
||||
//
|
||||
// this can be used by the middleware and dispatcher to isolate one space,
|
||||
// then unwrap and isolate another space
|
||||
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 := makePrefix(app)
|
||||
return PrefixedStore(app, store)
|
||||
}
|
||||
|
||||
// PrefixedStore allows one to create an isolated state-space for a given
|
||||
// app prefix, but it cannot easily be unwrapped
|
||||
//
|
||||
// This is useful for tests or utilities that have access to the global
|
||||
// state to check individual app spaces. Individual apps should not be able
|
||||
// to use this to read each other's space
|
||||
func PrefixedStore(app string, store state.KVStore) state.KVStore {
|
||||
prefix := append([]byte(app), byte(0))
|
||||
return prefixStore{prefix, store}
|
||||
}
|
||||
|
||||
func makePrefix(app string) []byte {
|
||||
return append([]byte(app), byte(0))
|
||||
}
|
||||
|
||||
// PrefixedKey gives us the absolute path to a key that is embedded in an
|
||||
// application-specific state-space.
|
||||
// PrefixedKey returns the absolute path to a given key in a particular
|
||||
// app's state-space
|
||||
//
|
||||
// This is useful for tests or utilities that have access to the global
|
||||
// state to check individual app spaces. Individual apps should not be able
|
||||
// to use this to read each other's space
|
||||
func PrefixedKey(app string, key []byte) []byte {
|
||||
return append(makePrefix(app), key...)
|
||||
prefix := append([]byte(app), byte(0))
|
||||
return append(prefix, key...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user