From b3f58a9215d7e826cd0eed11e73a74330fa34c44 Mon Sep 17 00:00:00 2001 From: Jack Zampolin Date: Tue, 19 Mar 2019 16:21:59 -0700 Subject: [PATCH 1/9] WIP community pool querier --- x/distribution/client/cli/query.go | 24 ++++++++++++++++++++++++ x/distribution/client/module_client.go | 1 + x/distribution/client/rest/query.go | 24 ++++++++++++++++++++++++ x/distribution/keeper/querier.go | 12 ++++++++++++ 4 files changed, 61 insertions(+) diff --git a/x/distribution/client/cli/query.go b/x/distribution/client/cli/query.go index 4ba5b03b1608..cf4bbdcab94a 100644 --- a/x/distribution/client/cli/query.go +++ b/x/distribution/client/cli/query.go @@ -163,3 +163,27 @@ $ 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 0acb62a72003..780b0cabd8f5 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 a8a6e13263e4..d39178b46c63 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,24 @@ func paramsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec, } } +func communityPoolHandler(cliCtx context.CLIContext, cdc *codec.Codec, queryRoute string) http.HanderFunc { + 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.MustUnmarshalJSON(res, &result); if 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 348c8b9a0e3f..ac40700c52f1 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 +} From 9ddb2f406aed38babd964d7472dc8621abb7387d Mon Sep 17 00:00:00 2001 From: Jack Zampolin Date: Tue, 19 Mar 2019 16:36:37 -0700 Subject: [PATCH 2/9] fix build --- x/distribution/client/cli/query.go | 23 ++++++++++++----------- x/distribution/client/rest/query.go | 6 ++++-- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/x/distribution/client/cli/query.go b/x/distribution/client/cli/query.go index cf4bbdcab94a..bb1654c191cb 100644 --- a/x/distribution/client/cli/query.go +++ b/x/distribution/client/cli/query.go @@ -167,23 +167,24 @@ $ 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, + 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) + 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 - } + 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) + var result sdk.DecCoins + cdc.MustUnmarshalJSON(res, &result) + return cliCtx.PrintOutput(result) + }, } } diff --git a/x/distribution/client/rest/query.go b/x/distribution/client/rest/query.go index d39178b46c63..919574b5eece 100644 --- a/x/distribution/client/rest/query.go +++ b/x/distribution/client/rest/query.go @@ -213,7 +213,9 @@ func paramsHandlerFn(cliCtx context.CLIContext, cdc *codec.Codec, } } -func communityPoolHandler(cliCtx context.CLIContext, cdc *codec.Codec, queryRoute string) http.HanderFunc { +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 { @@ -222,7 +224,7 @@ func communityPoolHandler(cliCtx context.CLIContext, cdc *codec.Codec, queryRout } var result sdk.DecCoins - if err := cdc.MustUnmarshalJSON(res, &result); if err != nil { + if err := cdc.UnmarshalJSON(res, &result); err != nil { rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error()) return } From 82525761a9eb50f9d0047dc33d5f359d4711a5c1 Mon Sep 17 00:00:00 2001 From: Karoly Albert Szabo Date: Wed, 20 Mar 2019 11:57:56 +0100 Subject: [PATCH 3/9] add a test to return null if community holds nothing Signed-off-by: Karoly Albert Szabo --- x/distribution/keeper/querier_test.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/x/distribution/keeper/querier_test.go b/x/distribution/keeper/querier_test.go index 9593f1bff472..d2c192bd4133 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) } From 175bc0641d1a6ce2c2052c5df27a25de978c2fc7 Mon Sep 17 00:00:00 2001 From: Alexander Bezobchuk Date: Wed, 20 Mar 2019 18:29:04 -0700 Subject: [PATCH 4/9] Update x/distribution/client/cli/query.go --- x/distribution/client/cli/query.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/distribution/client/cli/query.go b/x/distribution/client/cli/query.go index bb1654c191cb..7c4c2bcbd737 100644 --- a/x/distribution/client/cli/query.go +++ b/x/distribution/client/cli/query.go @@ -170,7 +170,7 @@ func GetCmdQueryCommunityPool(queryRoute string, cdc *codec.Codec) *cobra.Comman 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 + Long: strings.TrimSpace(`Query all coins in the community pool which is under Governance control. $ gaiacli query distr community-pool `), From 1d28a47d74a8bb18ae81322e6df5b2fad04c18d0 Mon Sep 17 00:00:00 2001 From: Aleksandr Bezobchuk Date: Thu, 21 Mar 2019 10:52:30 -0400 Subject: [PATCH 5/9] Add a pending log entry --- .pending/improvements/sdk/3937-Implement-community-pool-querier | 1 + 1 file changed, 1 insertion(+) create mode 100644 .pending/improvements/sdk/3937-Implement-community-pool-querier 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 000000000000..1862a67862f0 --- /dev/null +++ b/.pending/improvements/sdk/3937-Implement-community-pool-querier @@ -0,0 +1 @@ +#3937 Implement community pool querier. From c15b84521e49240d9368224b21d3b92861c7590f Mon Sep 17 00:00:00 2001 From: frog power 4000 Date: Tue, 26 Mar 2019 09:43:49 -0400 Subject: [PATCH 6/9] Update x/distribution/keeper/querier_test.go Co-Authored-By: alexanderbez --- x/distribution/keeper/querier_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/distribution/keeper/querier_test.go b/x/distribution/keeper/querier_test.go index d2c192bd4133..8f7e1cf05588 100644 --- a/x/distribution/keeper/querier_test.go +++ b/x/distribution/keeper/querier_test.go @@ -111,7 +111,7 @@ func getQueriedDelegationRewards(t *testing.T, ctx sdk.Context, cdc *codec.Codec 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}, "/"), + Path: path.Join(custom, types.QuerierRoute, QueryCommunityPool), Data: []byte{}, } From bc1abf4dc5421ae342d5e4e2a11e29ba623205f4 Mon Sep 17 00:00:00 2001 From: frog power 4000 Date: Tue, 26 Mar 2019 09:43:57 -0400 Subject: [PATCH 7/9] Update x/distribution/keeper/querier_test.go Co-Authored-By: alexanderbez --- x/distribution/keeper/querier_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/distribution/keeper/querier_test.go b/x/distribution/keeper/querier_test.go index 8f7e1cf05588..97a3c503087a 100644 --- a/x/distribution/keeper/querier_test.go +++ b/x/distribution/keeper/querier_test.go @@ -183,7 +183,7 @@ func TestQueries(t *testing.T) { 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 + // currently community pool hold nothing so we should return null communityPool := getQueriedCommunityPool(t, ctx, cdc, querier) require.Nil(t, communityPool) } From 05d628cf911b0c262e95636a3cb11e3f2e9da72c Mon Sep 17 00:00:00 2001 From: Karoly Albert Szabo Date: Wed, 27 Mar 2019 18:00:31 +0100 Subject: [PATCH 8/9] Update docs - Add new route to swagger.yaml - Add community pool command to docs - added pending changes Signed-off-by: Karoly Albert Szabo --- .../3937-Add-command-to-query-community-pool | 1 + .../3937-Add-route-to-fetch-community-pool | 1 + client/lcd/swagger-ui/swagger.yaml | 16 ++++++++++++++++ docs/gaia/gaiacli.md | 8 ++++++++ 4 files changed, 26 insertions(+) create mode 100644 .pending/features/gaiacli/3937-Add-command-to-query-community-pool create mode 100644 .pending/features/gaiarest/3937-Add-route-to-fetch-community-pool 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 000000000000..d5ec2f09fe6c --- /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 000000000000..0cf25bcacb77 --- /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/client/lcd/swagger-ui/swagger.yaml b/client/lcd/swagger-ui/swagger.yaml index 999a2ee03945..afb317672fa5 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 b3a1db42a2c1..3ad6c8f90a3d 100644 --- a/docs/gaia/gaiacli.md +++ b/docs/gaia/gaiacli.md @@ -623,6 +623,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: From 00f6189c6b5887e6dee33268d711ca2938cc720f Mon Sep 17 00:00:00 2001 From: Alessio Treglia Date: Wed, 27 Mar 2019 22:01:30 +0000 Subject: [PATCH 9/9] Fix querier test --- x/distribution/keeper/querier_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x/distribution/keeper/querier_test.go b/x/distribution/keeper/querier_test.go index 97a3c503087a..8ba091bcf47a 100644 --- a/x/distribution/keeper/querier_test.go +++ b/x/distribution/keeper/querier_test.go @@ -111,7 +111,7 @@ func getQueriedDelegationRewards(t *testing.T, ctx sdk.Context, cdc *codec.Codec func getQueriedCommunityPool(t *testing.T, ctx sdk.Context, cdc *codec.Codec, querier sdk.Querier) (ptr []byte) { query := abci.RequestQuery{ - Path: path.Join(custom, types.QuerierRoute, QueryCommunityPool), + Path: strings.Join([]string{custom, types.QuerierRoute, QueryCommunityPool}, ""), Data: []byte{}, }