Skip to content

Commit

Permalink
add query for target supply
Browse files Browse the repository at this point in the history
  • Loading branch information
dimiandre committed Sep 1, 2023
1 parent 2e4f4d1 commit 5058bfa
Show file tree
Hide file tree
Showing 5 changed files with 483 additions and 29 deletions.
20 changes: 20 additions & 0 deletions proto/juno/mint/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ service Query {
returns (QueryAnnualProvisionsResponse) {
option (google.api.http).get = "/cosmos/mint/v1beta1/annual_provisions";
}

// TargetSupply current target supply for this phase value.
rpc TargetSupply(QueryTargetSupplyRequest)
returns (QueryTargetSupplyResponse) {
option (google.api.http).get = "/cosmos/mint/v1beta1/target_supply";
}
}

// QueryParamsRequest is the request type for the Query/Params RPC method.
Expand Down Expand Up @@ -61,3 +67,17 @@ message QueryAnnualProvisionsResponse {
(gogoproto.nullable) = false
];
}

// QueryTargetSupplyRequest is the request type for the
// Query/TargetSupply RPC method.
message QueryTargetSupplyRequest {}

// QueryTargetSupplyResponse is the response type for the
// Query/TargetSupply RPC method.
message QueryTargetSupplyResponse {
// target_supply is the target supply for this phase value.
bytes target_supply = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.nullable) = false
];
}
29 changes: 29 additions & 0 deletions x/mint/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func GetQueryCmd() *cobra.Command {
GetCmdQueryParams(),
GetCmdQueryInflation(),
GetCmdQueryAnnualProvisions(),
GetCmqQueryTargetSupply(),
)

return mintingQueryCmd
Expand Down Expand Up @@ -116,3 +117,31 @@ func GetCmdQueryAnnualProvisions() *cobra.Command {

return cmd
}

// GetCmqQueryTargetSupply implements a command to return the current target supply value.
func GetCmqQueryTargetSupply() *cobra.Command {
cmd := &cobra.Command{
Use: "target-supply",
Short: "Query the current target supply for this phase value",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

params := &types.QueryTargetSupplyRequest{}
res, err := queryClient.TargetSupply(cmd.Context(), params)
if err != nil {
return err
}

return clientCtx.PrintString(fmt.Sprintf("%s\n", res.TargetSupply))
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
8 changes: 8 additions & 0 deletions x/mint/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,11 @@ func (k Keeper) AnnualProvisions(c context.Context, _ *types.QueryAnnualProvisio

return &types.QueryAnnualProvisionsResponse{AnnualProvisions: minter.AnnualProvisions}, nil
}

// Target supply returns minter.TargetSupply of the mint module.
func (k Keeper) TargetSupply(c context.Context, _ *types.QueryTargetSupplyRequest) (*types.QueryTargetSupplyResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
minter := k.GetMinter(ctx)

return &types.QueryTargetSupplyResponse{TargetSupply: minter.TargetSupply}, nil
}
Loading

0 comments on commit 5058bfa

Please sign in to comment.