New store query prefixes (ref #979)
This commit is contained in:
parent
a240554695
commit
8c1c40b89a
|
@ -285,15 +285,10 @@ func (app *BaseApp) InitChain(req abci.RequestInitChain) (res abci.ResponseInitC
|
|||
// Implements ABCI.
|
||||
// Delegates to CommitMultiStore if it implements Queryable
|
||||
func (app *BaseApp) Query(req abci.RequestQuery) (res abci.ResponseQuery) {
|
||||
queryable, ok := app.cms.(sdk.Queryable)
|
||||
if !ok {
|
||||
msg := "application doesn't support queries"
|
||||
return sdk.ErrUnknownRequest(msg).QueryResult()
|
||||
}
|
||||
// Special prefix backslash for special queries
|
||||
path := req.Path
|
||||
if strings.HasPrefix(path, "\\") {
|
||||
query := path[1:]
|
||||
// "/app" prefix for special application queries
|
||||
if strings.HasPrefix(path, "/app") {
|
||||
query := path[4:]
|
||||
var result sdk.Result
|
||||
switch query {
|
||||
case "simulate":
|
||||
|
@ -312,7 +307,18 @@ func (app *BaseApp) Query(req abci.RequestQuery) (res abci.ResponseQuery) {
|
|||
Value: value,
|
||||
}
|
||||
}
|
||||
return queryable.Query(req)
|
||||
// "/store" prefix for store queries
|
||||
if strings.HasPrefix(path, "/store") {
|
||||
queryable, ok := app.cms.(sdk.Queryable)
|
||||
if !ok {
|
||||
msg := "multistore doesn't support queries"
|
||||
return sdk.ErrUnknownRequest(msg).QueryResult()
|
||||
}
|
||||
req.Path = req.Path[6:] // slice off "/store"
|
||||
return queryable.Query(req)
|
||||
}
|
||||
msg := "unknown query path"
|
||||
return sdk.ErrUnknownRequest(msg).QueryResult()
|
||||
}
|
||||
|
||||
// Implements ABCI
|
||||
|
|
|
@ -167,7 +167,7 @@ func TestInitChainer(t *testing.T) {
|
|||
}
|
||||
|
||||
query := abci.RequestQuery{
|
||||
Path: "/main/key",
|
||||
Path: "/store/main/key",
|
||||
Data: key,
|
||||
}
|
||||
|
||||
|
@ -308,7 +308,7 @@ func TestQuery(t *testing.T) {
|
|||
})
|
||||
|
||||
query := abci.RequestQuery{
|
||||
Path: "/main/key",
|
||||
Path: "/store/main/key",
|
||||
Data: key,
|
||||
}
|
||||
|
||||
|
|
|
@ -58,8 +58,7 @@ func (ctx CoreContext) QuerySubspace(cdc *wire.Codec, subspace []byte, storeName
|
|||
|
||||
// Query from Tendermint with the provided storename and path
|
||||
func (ctx CoreContext) query(key cmn.HexBytes, storeName, endPath string) (res []byte, err error) {
|
||||
|
||||
path := fmt.Sprintf("/%s/%s", storeName, endPath)
|
||||
path := fmt.Sprintf("/store/%s/key", storeName)
|
||||
node, err := ctx.GetNode()
|
||||
if err != nil {
|
||||
return res, err
|
||||
|
|
|
@ -31,10 +31,9 @@ func TestInitApp(t *testing.T) {
|
|||
app.InitChain(req)
|
||||
app.Commit()
|
||||
|
||||
// XXX test failing
|
||||
// make sure we can query these values
|
||||
query := abci.RequestQuery{
|
||||
Path: "/main/key",
|
||||
Path: "/store/main/key",
|
||||
Data: []byte("foo"),
|
||||
}
|
||||
qres := app.Query(query)
|
||||
|
@ -70,7 +69,7 @@ func TestDeliverTx(t *testing.T) {
|
|||
|
||||
// make sure we can query these values
|
||||
query := abci.RequestQuery{
|
||||
Path: "/main/key",
|
||||
Path: "/store/main/key",
|
||||
Data: []byte(key),
|
||||
}
|
||||
qres := app.Query(query)
|
||||
|
|
Loading…
Reference in New Issue