forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
querier.go
36 lines (29 loc) · 927 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
32
33
34
35
36
package slashing
import (
abci "github.com/tendermint/tendermint/abci/types"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
)
// Query endpoints supported by the slashing querier
const (
QueryParameters = "parameters"
)
// NewQuerier creates a new querier for slashing clients.
func NewQuerier(k Keeper, cdc *codec.Codec) sdk.Querier {
return func(ctx sdk.Context, path []string, req abci.RequestQuery) ([]byte, sdk.Error) {
switch path[0] {
case QueryParameters:
return queryParams(ctx, cdc, k)
default:
return nil, sdk.ErrUnknownRequest("unknown staking query endpoint")
}
}
}
func queryParams(ctx sdk.Context, cdc *codec.Codec, k Keeper) ([]byte, sdk.Error) {
params := k.GetParams(ctx)
res, err := codec.MarshalJSONIndent(cdc, params)
if err != nil {
return nil, sdk.ErrInternal(sdk.AppendMsgToErr("failed to marshal JSON", err.Error()))
}
return res, nil
}