-
Notifications
You must be signed in to change notification settings - Fork 102
/
grpc_query.go
82 lines (62 loc) · 2.14 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
package keeper
import (
"context"
sdk "github.com/cosmos/cosmos-sdk/types"
nexus "github.com/axelarnetwork/axelar-core/x/nexus/exported"
"github.com/axelarnetwork/axelar-core/x/reward/types"
"github.com/axelarnetwork/utils/slices"
)
var _ types.QueryServiceServer = Querier{}
// Querier implements the grpc queries for the nexus module
type Querier struct {
keeper Keeper
minter types.Minter
nexus types.Nexus
}
// NewGRPCQuerier creates a new nexus Querier
func NewGRPCQuerier(k Keeper, m types.Minter, n types.Nexus) Querier {
return Querier{
keeper: k,
minter: m,
nexus: n,
}
}
// InflationRate returns the Axelar network inflation
func (q Querier) InflationRate(c context.Context, req *types.InflationRateRequest) (*types.InflationRateResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
params := q.keeper.GetParams(ctx)
baseInflation := q.minter.GetMinter(ctx).Inflation
keyManagementInflation := params.KeyMgmtRelativeInflationRate.Mul(baseInflation)
validator := sdk.ValAddress{}
if req.Validator != "" {
var err error
validator, err = sdk.ValAddressFromBech32(req.Validator)
if err != nil {
return nil, err
}
}
chains := slices.Filter(q.nexus.GetChains(ctx), func(chain nexus.Chain) bool {
if !q.nexus.IsChainActivated(ctx, chain) {
return false
}
maintainers := q.nexus.GetChainMaintainers(ctx, chain)
// If no validator is specified, check if there are any maintainers to get the max network inflation rate
if len(validator) == 0 {
return len(maintainers) > 0
}
return slices.Any(maintainers, func(maintainer sdk.ValAddress) bool { return validator.Equals(maintainer) })
})
chainMaintainerInflation := params.ExternalChainVotingInflationRate.MulInt64(int64(len(chains)))
inflation := baseInflation.Add(keyManagementInflation).Add(chainMaintainerInflation)
return &types.InflationRateResponse{
InflationRate: inflation,
}, nil
}
// Params returns the reward module params
func (q Querier) Params(c context.Context, req *types.ParamsRequest) (*types.ParamsResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
params := q.keeper.GetParams(ctx)
return &types.ParamsResponse{
Params: params,
}, nil
}