forked from bandprotocol/bandchain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
querier.go
83 lines (63 loc) · 2.2 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
package keeper
import (
commontypes "github.com/GeoDB-Limited/odincore/chain/x/common/types"
"github.com/GeoDB-Limited/odincore/chain/x/mint/internal/types"
abci "github.com/tendermint/tendermint/abci/types"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
// NewQuerier returns a minting Querier handler.
func NewQuerier(k Keeper) sdk.Querier {
return func(ctx sdk.Context, path []string, _ abci.RequestQuery) ([]byte, error) {
switch path[0] {
case types.QueryParameters:
return queryParams(ctx, k)
case types.QueryInflation:
return queryInflation(ctx, k)
case types.QueryAnnualProvisions:
return queryAnnualProvisions(ctx, k)
case types.QueryEthIntegrationAddress:
return queryEthIntegrationAddress(ctx, k)
case types.QueryTreasuryPool:
return queryTreasuryPool(ctx, k)
default:
return nil, sdkerrors.Wrapf(sdkerrors.ErrUnknownRequest, "unknown query path: %s", path[0])
}
}
}
func queryParams(ctx sdk.Context, k Keeper) ([]byte, error) {
params := k.GetParams(ctx)
res, err := codec.MarshalJSONIndent(k.cdc, params)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error())
}
return res, nil
}
func queryInflation(ctx sdk.Context, k Keeper) ([]byte, error) {
minter := k.GetMinter(ctx)
res, err := codec.MarshalJSONIndent(k.cdc, minter.Inflation)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error())
}
return res, nil
}
func queryAnnualProvisions(ctx sdk.Context, k Keeper) ([]byte, error) {
minter := k.GetMinter(ctx)
res, err := codec.MarshalJSONIndent(k.cdc, minter.AnnualProvisions)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error())
}
return res, nil
}
func queryEthIntegrationAddress(ctx sdk.Context, k Keeper) ([]byte, error) {
params := k.GetParams(ctx)
res, err := codec.MarshalJSONIndent(k.cdc, params.EthIntegrationAddress)
if err != nil {
return nil, sdkerrors.Wrap(sdkerrors.ErrJSONMarshal, err.Error())
}
return res, nil
}
func queryTreasuryPool(ctx sdk.Context, k Keeper) ([]byte, error) {
return commontypes.QueryOK(types.ModuleCdc, k.GetMintPool(ctx).TreasuryPool)
}