Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: added denom-owners grpc_web api and cli query #2508

Merged
merged 10 commits into from
Apr 29, 2024
1 change: 1 addition & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,7 @@ func New(
app.UIbcQuotaKeeperB = uibcquota.NewBuilder(
appCodec, keys[uibc.StoreKey],
app.LeverageKeeper, uibcoracle.FromUmeeAvgPriceOracle(app.OracleKeeper), app.UGovKeeperB.EmergencyGroup,
app.BankKeeper,
)

/**********
Expand Down
10 changes: 10 additions & 0 deletions proto/umee/uibc/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
import "google/protobuf/timestamp.proto";
import "cosmos/bank/v1beta1/query.proto";

import "umee/uibc/v1/quota.proto";
import "umee/uibc/v1/uibc.proto";

Expand Down Expand Up @@ -40,6 +42,14 @@ service Query {
rpc QuotaExpires(QueryQuotaExpires) returns (QueryQuotaExpiresResponse) {
option (google.api.http).get = "/umee/uibc/v1/quota_expires";
}

// DenomOwners queries for all account addresses that own a particular token
// denomination.
// For historical state data, height have to pass as a grpc headers request here
// check here: https://docs.cosmos.network/v0.50/user/run-node/interact-node#query-for-historical-state-using-grpcurl
rpc DenomOwners(cosmos.bank.v1beta1.QueryDenomOwnersRequest) returns (cosmos.bank.v1beta1.QueryDenomOwnersResponse){
option (google.api.http).get = "/umee/uibc/v1/denom_owners";
}
}

// QueryAllInflows defines request type for query the inflow quota of registered denoms.
Expand Down
1 change: 1 addition & 0 deletions x/ugov/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/umee-network/umee/v6/x/ugov"
)

Expand Down
1 change: 1 addition & 0 deletions x/ugov/keeper/query_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
context "context"

sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/umee-network/umee/v6/x/ugov"
)

Expand Down
33 changes: 33 additions & 0 deletions x/uibc/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
"github.com/spf13/cobra"

"github.com/umee-network/umee/v6/util/cli"
"github.com/umee-network/umee/v6/x/uibc"
)
Expand All @@ -25,6 +27,7 @@
GetOutflows(),
GetInflows(),
GetQuotaExpireTime(),
QueryDenomOwners(),

Check warning on line 30 in x/uibc/client/cli/query.go

View check run for this annotation

Codecov / codecov/patch

x/uibc/client/cli/query.go#L30

Added line #L30 was not covered by tests
)

return cmd
Expand Down Expand Up @@ -130,3 +133,33 @@
flags.AddQueryFlagsToCmd(cmd)
return cmd
}

// QueryDenomOwners creates the Query/DenomOwners CLI.
func QueryDenomOwners() *cobra.Command {
cmd := &cobra.Command{
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 {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err

Check warning on line 146 in x/uibc/client/cli/query.go

View check run for this annotation

Codecov / codecov/patch

x/uibc/client/cli/query.go#L138-L146

Added lines #L138 - L146 were not covered by tests
}
pageReq, err := client.ReadPageRequest(cmd.Flags())
if err != nil {
return err

Check warning on line 150 in x/uibc/client/cli/query.go

View check run for this annotation

Codecov / codecov/patch

x/uibc/client/cli/query.go#L148-L150

Added lines #L148 - L150 were not covered by tests
}
queryClient := uibc.NewQueryClient(clientCtx)
resp, err := queryClient.DenomOwners(cmd.Context(), &banktypes.QueryDenomOwnersRequest{
Denom: args[0],
Pagination: pageReq,
})
return cli.PrintOrErr(resp, err, clientCtx)

Check warning on line 157 in x/uibc/client/cli/query.go

View check run for this annotation

Codecov / codecov/patch

x/uibc/client/cli/query.go#L152-L157

Added lines #L152 - L157 were not covered by tests
},
}

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

Check warning on line 162 in x/uibc/client/cli/query.go

View check run for this annotation

Codecov / codecov/patch

x/uibc/client/cli/query.go#L161-L162

Added lines #L161 - L162 were not covered by tests

return cmd

Check warning on line 164 in x/uibc/client/cli/query.go

View check run for this annotation

Codecov / codecov/patch

x/uibc/client/cli/query.go#L164

Added line #L164 was not covered by tests
}
6 changes: 6 additions & 0 deletions x/uibc/expected_keepers.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package uibc

import (
context "context"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/bank/types"

Expand All @@ -12,6 +14,10 @@ type BankKeeper interface {
GetDenomMetaData(ctx sdk.Context, denom string) (types.Metadata, bool)
SetDenomMetaData(ctx sdk.Context, denomMetaData types.Metadata)
IterateAllDenomMetaData(ctx sdk.Context, cb func(types.Metadata) bool)
DenomOwners(
goCtx context.Context,
req *types.QueryDenomOwnersRequest,
) (*types.QueryDenomOwnersResponse, error)
}

type Leverage interface {
Expand Down
137 changes: 93 additions & 44 deletions x/uibc/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading