-
Notifications
You must be signed in to change notification settings - Fork 206
/
grpc_query.go
87 lines (72 loc) · 2.78 KB
/
grpc_query.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
84
85
86
87
package keeper
import (
"context"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/NibiruChain/nibiru/x/common/denoms"
"github.com/NibiruChain/nibiru/x/inflation/types"
)
// querier implements the module's gRPC "QueryServer" interface
type querier struct {
Keeper
}
// NewQuerier returns an implementation of the [types.QueryServer] interface
// for the provided [Keeper].
func NewQuerier(keeper Keeper) types.QueryServer {
return &querier{Keeper: keeper}
}
var _ types.QueryServer = querier{}
// Params is a gRPC query for the module parameters
func (q querier) Params(c context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
params := q.GetParams(ctx)
return &types.QueryParamsResponse{Params: params}, nil
}
// Period returns the current period of the inflation module.
func (k Keeper) Period(
c context.Context,
_ *types.QueryPeriodRequest,
) (*types.QueryPeriodResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
period := k.CurrentPeriod.Peek(ctx)
return &types.QueryPeriodResponse{Period: period}, nil
}
// EpochMintProvision returns the EpochMintProvision of the inflation module.
func (k Keeper) EpochMintProvision(
c context.Context,
_ *types.QueryEpochMintProvisionRequest,
) (*types.QueryEpochMintProvisionResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
epochMintProvision := k.GetEpochMintProvision(ctx)
coin := sdk.NewDecCoinFromDec(denoms.NIBI, epochMintProvision)
return &types.QueryEpochMintProvisionResponse{EpochMintProvision: coin}, nil
}
// SkippedEpochs returns the number of skipped Epochs of the inflation module.
func (k Keeper) SkippedEpochs(
c context.Context,
_ *types.QuerySkippedEpochsRequest,
) (*types.QuerySkippedEpochsResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
skippedEpochs := k.NumSkippedEpochs.Peek(ctx)
return &types.QuerySkippedEpochsResponse{SkippedEpochs: skippedEpochs}, nil
}
// InflationRate returns the inflation rate for the current period.
func (k Keeper) InflationRate(
c context.Context,
_ *types.QueryInflationRateRequest,
) (*types.QueryInflationRateResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
inflationRate := k.GetInflationRate(ctx, denoms.NIBI)
return &types.QueryInflationRateResponse{InflationRate: inflationRate}, nil
}
// CirculatingSupply returns the total supply in circulation excluding the team
// allocation in the first year
func (k Keeper) CirculatingSupply(
c context.Context,
_ *types.QueryCirculatingSupplyRequest,
) (*types.QueryCirculatingSupplyResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
circulatingSupply := k.GetCirculatingSupply(ctx, denoms.NIBI)
circulatingToDec := sdk.NewDecFromInt(circulatingSupply)
coin := sdk.NewDecCoinFromDec(denoms.NIBI, circulatingToDec)
return &types.QueryCirculatingSupplyResponse{CirculatingSupply: coin}, nil
}