Skip to content

Commit

Permalink
feat: return voting power weights at pool query (#71)
Browse files Browse the repository at this point in the history
* return voting power weight when we return pool query

* fix naming
  • Loading branch information
beer-1 authored Feb 1, 2024
1 parent 5d7f18a commit c808514
Show file tree
Hide file tree
Showing 5 changed files with 736 additions and 650 deletions.
5 changes: 5 additions & 0 deletions proto/initia/mstaking/v1/staking.proto
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,11 @@ message Pool {
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"bonded_tokens\""
];
repeated cosmos.base.v1beta1.DecCoin voting_power_weights = 3 [
(gogoproto.moretags) = "yaml:\"voting_power_weights\"",
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins",
(gogoproto.nullable) = false
];
}

// Infraction indicates the infraction a validator commited.
Expand Down
5 changes: 5 additions & 0 deletions x/mstaking/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,10 +376,15 @@ func (q Querier) DelegatorValidators(ctx context.Context, req *types.QueryDelega
func (q Querier) Pool(ctx context.Context, _ *types.QueryPoolRequest) (*types.QueryPoolResponse, error) {
bondedPool := q.GetBondedPool(ctx)
notBondedPool := q.GetNotBondedPool(ctx)
powerWeights, err := q.GetVotingPowerWeights(ctx)
if err != nil {
return nil, err
}

pool := types.NewPool(
q.bankKeeper.GetAllBalances(ctx, notBondedPool.GetAddress()),
q.bankKeeper.GetAllBalances(ctx, bondedPool.GetAddress()),
powerWeights,
)

return &types.QueryPoolResponse{Pool: pool}, nil
Expand Down
5 changes: 3 additions & 2 deletions x/mstaking/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,9 @@ func Test_grpcPool(t *testing.T) {
require.NoError(t, err)

require.Equal(t, res.Pool, types.Pool{
NotBondedTokens: sdk.NewCoins(),
BondedTokens: sdk.NewCoins(sdk.NewCoin(bondDenom, math.NewInt(2_000_000))),
NotBondedTokens: sdk.NewCoins(),
BondedTokens: sdk.NewCoins(sdk.NewCoin(bondDenom, math.NewInt(2_000_000))),
VotingPowerWeights: sdk.NewDecCoins(sdk.NewDecCoin(bondDenom, math.OneInt())),
})
}

Expand Down
7 changes: 4 additions & 3 deletions x/mstaking/types/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ const (
)

// NewPool creates a new Pool instance used for queries
func NewPool(notBonded, bonded sdk.Coins) Pool {
func NewPool(notBonded, bonded sdk.Coins, votingPowerWeights sdk.DecCoins) Pool {
return Pool{
NotBondedTokens: notBonded,
BondedTokens: bonded,
NotBondedTokens: notBonded,
BondedTokens: bonded,
VotingPowerWeights: votingPowerWeights,
}
}
Loading

0 comments on commit c808514

Please sign in to comment.