generated from okp4/template-oss
-
Notifications
You must be signed in to change notification settings - Fork 119
/
query.go
43 lines (34 loc) 路 1.06 KB
/
query.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package wasm
import (
"encoding/json"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/axone-protocol/axoned/v8/x/logic/keeper"
"github.com/axone-protocol/axoned/v8/x/logic/types"
)
// LogicQuerier ease the bridge between the logic module with the wasm CustomQuerier to allow wasm contracts to query
// the logic module.
type LogicQuerier struct {
k *keeper.Keeper
}
// MakeLogicQuerier creates a new LogicQuerier based on the logic keeper.
func MakeLogicQuerier(keeper *keeper.Keeper) LogicQuerier {
return LogicQuerier{
k: keeper,
}
}
// Ask is a proxy method with the gRPC request, returning the result in the json format.
func (querier LogicQuerier) Ask(ctx sdk.Context, query AskQuery) ([]byte, error) {
grpcResp, err := querier.k.Ask(ctx, &types.QueryServiceAskRequest{
Program: query.Program,
Query: query.Query,
Limit: query.Limit,
})
if err != nil {
return nil, err
}
resp := new(AskResponse)
resp.from(*grpcResp)
raw, err := json.Marshal(resp)
querier.k.Logger(ctx).Debug("response to wasm ask", "json", string(raw))
return raw, err
}