Skip to content

Commit

Permalink
renamed token-balances to denom-owners
Browse files Browse the repository at this point in the history
  • Loading branch information
gsk967 committed Apr 24, 2024
1 parent 503e571 commit 57336fc
Show file tree
Hide file tree
Showing 5 changed files with 132 additions and 612 deletions.
31 changes: 6 additions & 25 deletions proto/umee/ugov/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "google/protobuf/timestamp.proto";
import "cosmos/base/query/v1beta1/pagination.proto";
import "amino/amino.proto";
import "cosmos/bank/v1beta1/query.proto";

import "umee/ugov/v1/ugov.proto";

Expand Down Expand Up @@ -37,42 +37,23 @@ service Query {
option (google.api.http).get = "/umee/ugov/v1/inflation_cycle_end";
}

// Token Balances queries for all account addresses that own a particular token
// DenomOwners queries for all account addresses that own a particular token
// denomination.
rpc TokenBalances(QueryTokenBalances) returns (QueryTokenBalancesResponse){
option (google.api.http).get = "/umee/ugov/v1/token_balances";
rpc DenomOwners(QueryDenomOwners) returns (cosmos.bank.v1beta1.QueryDenomOwnersResponse){
option (google.api.http).get = "/umee/ugov/v1/denom_owners";
}
}

// which queries for a paginated set of all account holders of a particular
// QueryDenomOwners which queries for a paginated set of all account holders of a particular
// denomination.
message QueryTokenBalances{
message QueryDenomOwners{
// denom defines the coin denomination to query all account holders for.
string denom = 1;
int64 height = 2;
// pagination defines an optional pagination for the request.
cosmos.base.query.v1beta1.PageRequest pagination = 3;
}

// QueryDenomOwnersResponse defines the RPC response of a TokenBalances RPC query.
message QueryTokenBalancesResponse {
repeated TokenBalance token_balances = 1;
// pagination defines the pagination in the response.
cosmos.base.query.v1beta1.PageResponse pagination = 2;
}

// TokenBalance defines structure representing an account that owns or holds a
// particular denominated token. It contains the account address and account
// balance of the denominated token.
//
message TokenBalance {
// address defines the address that owns a particular denomination.
string address = 1 [(cosmos_proto.scalar) = "cosmos.AddressString"];

// balance is the balance of the denominated coin for an account.
cosmos.base.v1beta1.Coin balance = 2 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];
}

// QueryMinGasPrice is a request type.
message QueryMinGasPrice {}

Expand Down
12 changes: 6 additions & 6 deletions x/ugov/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func GetQueryCmd() *cobra.Command {
QueryInflationParams(),
QueryInflationCyleEnd(),
QueryEmergencyGroup(),
QueryTokenBalances(),
QueryDenomOwners(),

Check warning on line 28 in x/ugov/client/cli/query.go

View check run for this annotation

Codecov / codecov/patch

x/ugov/client/cli/query.go#L28

Added line #L28 was not covered by tests
)

return cmd
Expand Down Expand Up @@ -123,10 +123,10 @@ func QueryInflationCyleEnd() *cobra.Command {
return cmd
}

// QueryTokenBalances creates the Query/TokenBalances CLI.
func QueryTokenBalances() *cobra.Command {
// QueryDenomOwners creates the Query/DenomOwners CLI.
func QueryDenomOwners() *cobra.Command {
cmd := &cobra.Command{
Use: "token-balances [denom]",
Use: "denom-owners [denom]",
Args: cobra.ExactArgs(1),
Short: "Queries for all account addresses that own a particular token denomination.",
RunE: func(cmd *cobra.Command, args []string) error {
Expand All @@ -139,7 +139,7 @@ func QueryTokenBalances() *cobra.Command {
return err

Check warning on line 139 in x/ugov/client/cli/query.go

View check run for this annotation

Codecov / codecov/patch

x/ugov/client/cli/query.go#L137-L139

Added lines #L137 - L139 were not covered by tests
}
queryClient := ugov.NewQueryClient(clientCtx)
resp, err := queryClient.TokenBalances(cmd.Context(), &ugov.QueryTokenBalances{
resp, err := queryClient.DenomOwners(cmd.Context(), &ugov.QueryDenomOwners{
Denom: args[0],
Pagination: pageReq,
})
Expand All @@ -148,7 +148,7 @@ func QueryTokenBalances() *cobra.Command {
}

flags.AddQueryFlagsToCmd(cmd)
flags.AddPaginationFlagsToCmd(cmd, "token-balances")
flags.AddPaginationFlagsToCmd(cmd, "denom-owners")

Check warning on line 151 in x/ugov/client/cli/query.go

View check run for this annotation

Codecov / codecov/patch

x/ugov/client/cli/query.go#L150-L151

Added lines #L150 - L151 were not covered by tests

return cmd

Check warning on line 153 in x/ugov/client/cli/query.go

View check run for this annotation

Codecov / codecov/patch

x/ugov/client/cli/query.go#L153

Added line #L153 was not covered by tests
}
19 changes: 3 additions & 16 deletions x/ugov/keeper/query_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,15 @@ func (q Querier) InflationCycleEnd(ctx context.Context, _ *ugov.QueryInflationCy
return &ugov.QueryInflationCycleEndResponse{End: &cycleEndTime}, nil
}

// TokenBalances implements ugov.QueryServer.
func (q Querier) TokenBalances(ctx context.Context, req *ugov.QueryTokenBalances) (*ugov.QueryTokenBalancesResponse,
// DenomOwners implements ugov.QueryServer.
func (q Querier) DenomOwners(ctx context.Context, req *ugov.QueryDenomOwners) (*banktypes.QueryDenomOwnersResponse,
error) {
sdkCtx := sdk.UnwrapSDKContext(ctx)
if req.Height != 0 {
sdkCtx = sdkCtx.WithBlockHeight(req.Height)

Check warning on line 60 in x/ugov/keeper/query_server.go

View check run for this annotation

Codecov / codecov/patch

x/ugov/keeper/query_server.go#L57-L60

Added lines #L57 - L60 were not covered by tests
}
resp, err := q.BankKeeper.DenomOwners(sdk.WrapSDKContext(sdkCtx), &banktypes.QueryDenomOwnersRequest{
return q.BankKeeper.DenomOwners(sdk.WrapSDKContext(sdkCtx), &banktypes.QueryDenomOwnersRequest{
Denom: req.Denom,
Pagination: req.Pagination,
})

Check warning on line 65 in x/ugov/keeper/query_server.go

View check run for this annotation

Codecov / codecov/patch

x/ugov/keeper/query_server.go#L62-L65

Added lines #L62 - L65 were not covered by tests
if err != nil {
return nil, err
}

tb := make([]*ugov.TokenBalance, 0)
for _, v := range resp.DenomOwners {
tb = append(tb, &ugov.TokenBalance{
Address: v.Address,
Balance: v.Balance,
})
}

return &ugov.QueryTokenBalancesResponse{Pagination: resp.Pagination, TokenBalances: tb}, nil
}
Loading

0 comments on commit 57336fc

Please sign in to comment.