-
Notifications
You must be signed in to change notification settings - Fork 182
/
querier.go
31 lines (27 loc) · 978 Bytes
/
querier.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
package params
import (
"fmt"
"github.com/okex/exchain/libs/cosmos-sdk/codec"
sdk "github.com/okex/exchain/libs/cosmos-sdk/types"
sdkerrors "github.com/okex/exchain/libs/cosmos-sdk/types/errors"
abci "github.com/okex/exchain/libs/tendermint/abci/types"
"github.com/okex/exchain/x/params/types"
)
// NewQuerier returns all query handlers
func NewQuerier(keeper Keeper) sdk.Querier {
return func(ctx sdk.Context, path []string, req abci.RequestQuery) ([]byte, sdk.Error) {
switch path[0] {
case types.QueryParams:
return queryParams(ctx, req, keeper)
default:
return nil, sdk.ErrUnknownRequest("unknown params query endpoint")
}
}
}
func queryParams(ctx sdk.Context, _ abci.RequestQuery, keeper Keeper) ([]byte, sdk.Error) {
bz, err := codec.MarshalJSONIndent(keeper.cdc, keeper.GetParams(ctx))
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, fmt.Sprintf("could not marshal result to JSON %s", err.Error()))
}
return bz, nil
}