diff --git a/.pending/features/gaiacli/3937-Add-command-to-query-community-pool b/.pending/features/gaiacli/3937-Add-command-to-query-community-pool new file mode 100644 index 000000000..d5ec2f09f --- /dev/null +++ b/.pending/features/gaiacli/3937-Add-command-to-query-community-pool @@ -0,0 +1 @@ +#3937 Add command to query community-pool \ No newline at end of file diff --git a/.pending/features/gaiarest/3937-Add-route-to-fetch-community-pool b/.pending/features/gaiarest/3937-Add-route-to-fetch-community-pool new file mode 100644 index 000000000..0cf25bcac --- /dev/null +++ b/.pending/features/gaiarest/3937-Add-route-to-fetch-community-pool @@ -0,0 +1 @@ +#3937 Add route to fetch community-pool \ No newline at end of file diff --git a/.pending/improvements/sdk/3937-Implement-community-pool-querier b/.pending/improvements/sdk/3937-Implement-community-pool-querier new file mode 100644 index 000000000..1862a6786 --- /dev/null +++ b/.pending/improvements/sdk/3937-Implement-community-pool-querier @@ -0,0 +1 @@ +#3937 Implement community pool querier. diff --git a/client/lcd/swagger-ui/swagger.yaml b/client/lcd/swagger-ui/swagger.yaml index 720d5d043..f2e90f0ef 100644 --- a/client/lcd/swagger-ui/swagger.yaml +++ b/client/lcd/swagger-ui/swagger.yaml @@ -1632,6 +1632,22 @@ paths: description: Key password is wrong 500: description: Internal Server Error + /distribution/community_pool: + get: + summary: Community pool parameters + tags: + - ICS24 + produces: + - application/json + responses: + 200: + description: OK + schema: + type: array + items: + $ref: "#/definitions/Coin" + 500: + description: Internal Server Error /distribution/parameters: get: summary: Fee distribution parameters diff --git a/docs/gaia/gaiacli.md b/docs/gaia/gaiacli.md index 6aff38af4..132c4aeed 100644 --- a/docs/gaia/gaiacli.md +++ b/docs/gaia/gaiacli.md @@ -637,6 +637,14 @@ To check the current distribution parameters, run: gaiacli query distr params ``` +#### Query distribution Community Pool + +To query all coins in the community pool which is under Governance control: + +```bash +gaiacli query distr community-pool +``` + #### Query outstanding rewards To check the current outstanding (un-withdrawn) rewards, run: diff --git a/x/distribution/client/cli/query.go b/x/distribution/client/cli/query.go index 4ba5b03b1..7c4c2bcbd 100644 --- a/x/distribution/client/cli/query.go +++ b/x/distribution/client/cli/query.go @@ -163,3 +163,28 @@ $ gaiacli query distr rewards cosmos1gghjut3ccd8ay0zduzj64hwre2fxs9ld75ru9p cosm }, } } + +// GetCmdQueryCommunityPool returns the command for fetching community pool info +func GetCmdQueryCommunityPool(queryRoute string, cdc *codec.Codec) *cobra.Command { + return &cobra.Command{ + Use: "community-pool", + Args: cobra.NoArgs, + Short: "Query the amount of coins in the community pool", + Long: strings.TrimSpace(`Query all coins in the community pool which is under Governance control. + +$ gaiacli query distr community-pool +`), + RunE: func(cmd *cobra.Command, args []string) error { + cliCtx := context.NewCLIContext().WithCodec(cdc) + + res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/community_pool", queryRoute), nil) + if err != nil { + return err + } + + var result sdk.DecCoins + cdc.MustUnmarshalJSON(res, &result) + return cliCtx.PrintOutput(result) + }, + } +} diff --git a/x/distribution/client/module_client.go b/x/distribution/client/module_client.go index 0acb62a72..780b0cabd 100644 --- a/x/distribution/client/module_client.go +++ b/x/distribution/client/module_client.go @@ -31,6 +31,7 @@ func (mc ModuleClient) GetQueryCmd() *cobra.Command { distCmds.GetCmdQueryValidatorCommission(mc.storeKey, mc.cdc), distCmds.GetCmdQueryValidatorSlashes(mc.storeKey, mc.cdc), distCmds.GetCmdQueryDelegatorRewards(mc.storeKey, mc.cdc), + distCmds.GetCmdQueryCommunityPool(mc.storeKey, mc.cdc), )...) return distQueryCmd diff --git a/x/distribution/client/rest/query.go b/x/distribution/client/rest/query.go index a8a6e1326..919574b5e 100644 --- a/x/distribution/client/rest/query.go +++ b/x/distribution/client/rest/query.go @@ -61,6 +61,12 @@ func registerQueryRoutes(cliCtx context.CLIContext, r *mux.Router, paramsHandlerFn(cliCtx, cdc, queryRoute), ).Methods("GET") + // Get the amount held in the community pool + r.HandleFunc( + "/distribution/community_pool", + communityPoolHandler(cliCtx, cdc, queryRoute), + ).Methods("GET") + } // HTTP request handler to query the total rewards balance from all delegations @@ -207,6 +213,26 @@ func paramsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec, } } +func communityPoolHandler(cliCtx context.CLIContext, cdc *codec.Codec, + queryRoute string) http.HandlerFunc { + + return func(w http.ResponseWriter, r *http.Request) { + res, err := cliCtx.QueryWithData(fmt.Sprintf("custom/%s/community_pool", queryRoute), nil) + if err != nil { + rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) + return + } + + var result sdk.DecCoins + if err := cdc.UnmarshalJSON(res, &result); err != nil { + rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) + return + } + + rest.PostProcessResponse(w, cdc, result, cliCtx.Indent) + } +} + // HTTP request handler to query the outstanding rewards func outstandingRewardsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec, queryRoute string) http.HandlerFunc { diff --git a/x/distribution/keeper/querier.go b/x/distribution/keeper/querier.go index 348c8b9a0..ac40700c5 100644 --- a/x/distribution/keeper/querier.go +++ b/x/distribution/keeper/querier.go @@ -20,6 +20,7 @@ const ( QueryDelegatorTotalRewards = "delegator_total_rewards" QueryDelegatorValidators = "delegator_validators" QueryWithdrawAddr = "withdraw_addr" + QueryCommunityPool = "community_pool" ParamCommunityTax = "community_tax" ParamBaseProposerReward = "base_proposer_reward" @@ -54,6 +55,9 @@ func NewQuerier(k Keeper) sdk.Querier { case QueryWithdrawAddr: return queryDelegatorWithdrawAddress(ctx, path[1:], req, k) + case QueryCommunityPool: + return queryCommunityPool(ctx, path[1:], req, k) + default: return nil, sdk.ErrUnknownRequest("unknown distr query endpoint") } @@ -314,3 +318,11 @@ func queryDelegatorWithdrawAddress(ctx sdk.Context, _ []string, req abci.Request return bz, nil } + +func queryCommunityPool(ctx sdk.Context, _ []string, req abci.RequestQuery, k Keeper) ([]byte, sdk.Error) { + bz, err := k.cdc.MarshalJSON(k.GetFeePoolCommunityCoins(ctx)) + if err != nil { + return nil, sdk.ErrInternal(sdk.AppendMsgToErr("could not marshal result to JSON", err.Error())) + } + return bz, nil +} diff --git a/x/distribution/keeper/querier_test.go b/x/distribution/keeper/querier_test.go index 9593f1bff..8ba091bcf 100644 --- a/x/distribution/keeper/querier_test.go +++ b/x/distribution/keeper/querier_test.go @@ -109,6 +109,19 @@ func getQueriedDelegationRewards(t *testing.T, ctx sdk.Context, cdc *codec.Codec return } +func getQueriedCommunityPool(t *testing.T, ctx sdk.Context, cdc *codec.Codec, querier sdk.Querier) (ptr []byte) { + query := abci.RequestQuery{ + Path: strings.Join([]string{custom, types.QuerierRoute, QueryCommunityPool}, ""), + Data: []byte{}, + } + + cp, err := querier(ctx, []string{QueryCommunityPool}, query) + require.Nil(t, err) + require.Nil(t, cdc.UnmarshalJSON(cp, &ptr)) + + return +} + func TestQueries(t *testing.T) { cdc := codec.New() ctx, _, keeper, sk, _ := CreateTestInputDefault(t, false, 100) @@ -169,4 +182,8 @@ func TestQueries(t *testing.T) { keeper.AllocateTokensToValidator(ctx, val, tokens) rewards = getQueriedDelegationRewards(t, ctx, cdc, querier, sdk.AccAddress(valOpAddr1), valOpAddr1) require.Equal(t, sdk.DecCoins{{sdk.DefaultBondDenom, sdk.NewDec(initial / 2)}}, rewards) + + // currently community pool hold nothing so we should return null + communityPool := getQueriedCommunityPool(t, ctx, cdc, querier) + require.Nil(t, communityPool) }