generated from okp4/template-oss
-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(logic): simplify wasm custom query integration
- Loading branch information
Showing
1 changed file
with
42 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package wasm | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/okp4/okp4d/x/logic/keeper" | ||
"github.com/okp4/okp4d/x/logic/types" | ||
) | ||
|
||
// AskQuery contains parameters to the Ask gRPC logic query, it is redefined to prevent eventual breaking change in the | ||
// logic module definitions with wasm usages. | ||
type AskQuery struct { | ||
Program string `json:"program"` | ||
Query string `json:"query"` | ||
} | ||
|
||
// 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 one, returning the result in the json format. | ||
func (querier LogicQuerier) Ask(ctx sdk.Context, query *AskQuery) ([]byte, error) { | ||
resp, err := querier.k.Ask(ctx, &types.QueryServiceAskRequest{ | ||
Program: query.Program, | ||
Query: query.Query, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return json.Marshal(resp) | ||
} |