-
Notifications
You must be signed in to change notification settings - Fork 0
/
querier.go
40 lines (32 loc) · 1.13 KB
/
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
37
38
39
40
/*
Copyright [2019] - [2021], PERSISTENCE TECHNOLOGIES PTE. LTD. and the persistenceCore contributors
SPDX-License-Identifier: Apache-2.0
*/
package keeper
import (
abci "github.com/tendermint/tendermint/abci/types"
"cosmossdk.io/errors"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
"github.com/incubus-network/fanfury-sdk/v2/x/halving/types"
)
// NewQuerier returns a halving Querier handler.
func NewQuerier(k Keeper, legacyQuerierCdc *codec.LegacyAmino) sdk.Querier {
return func(ctx sdk.Context, path []string, _ abci.RequestQuery) ([]byte, error) {
switch path[0] {
case types.QueryParameters:
return queryParams(ctx, k, legacyQuerierCdc)
default:
return nil, errors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown query path: %s", path[0])
}
}
}
func queryParams(ctx sdk.Context, k Keeper, legacyQuerierCdc *codec.LegacyAmino) ([]byte, error) {
params := k.GetParams(ctx)
res, err := codec.MarshalJSONIndent(legacyQuerierCdc, params)
if err != nil {
return nil, errors.Wrap(sdkerrors.ErrJSONMarshal, err.Error())
}
return res, nil
}