Implement client functionality for the community pool (#3939)
Fixes: #3937
This commit is contained in:
parent
f635b1cd14
commit
38b7c0705c
|
@ -0,0 +1 @@
|
|||
#3937 Add command to query community-pool
|
|
@ -0,0 +1 @@
|
|||
#3937 Add route to fetch community-pool
|
|
@ -0,0 +1 @@
|
|||
#3937 Implement community pool querier.
|
|
@ -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
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue