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

R4R: Implement fee distribution RESTful endpoints #3460

Merged
merged 29 commits into from
Feb 5, 2019
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
d14e919
Factor params query logic out
Jan 30, 2019
9dc2199
REST skeleton
Jan 30, 2019
14f1b07
Start working on params query
Jan 30, 2019
27a8f2c
Implement pool endpoint and querier
Jan 31, 2019
4eac5e8
Implement GET /distribution/delegators/{delegatorAddr}/rewards
Jan 31, 2019
d5939a1
Add delegation query
Jan 31, 2019
50bf781
Refactor, make new client common sub-package
Jan 31, 2019
71d2898
Implement GET /distribution/delegators/{delegatorAddr}/withdraw_address
Jan 31, 2019
effc2e9
WIP, issue is blocked
Feb 1, 2019
094aa52
Update distribution swagger.yaml section for F1
cwgoes Feb 1, 2019
009e927
Replace pool with outstanding_rewards
Feb 1, 2019
fd26e55
Finalize query endpoints
Feb 1, 2019
be16e5c
Implement POST /delegators/{delegatorAddr}/rewards/{validatorAddr}
Feb 4, 2019
9e9e665
Implement /validators/{validatorAddr}/rewards
Feb 1, 2019
32811f9
Factour out logic to prepare multi-msg withdrawal
Feb 1, 2019
1d5cf3f
WIP
Feb 2, 2019
f12c772
all_delegation_rewards -> total_delegation_rewards
Feb 4, 2019
834dd56
rigel/distr-queriers
Feb 4, 2019
bbc8f99
Implement /delegators/{delegatorAddr}/rewards
Feb 2, 2019
bb8767d
Implement cli withdraw-all-rewards command as multi-message tx
Feb 2, 2019
ec34237
Implement /delegators/{delegatorAddr}/withdraw_address
Feb 2, 2019
20826e8
invert abort with ok
Feb 2, 2019
4e23cf3
Clean up
Feb 2, 2019
a285f10
Update PENDING.md
Feb 4, 2019
0e9504c
Clean up rebase leftover, port to new rest package
Feb 4, 2019
d18d7eb
Don't write errors twice when ReadRESTReq() fails
Feb 4, 2019
4291cbe
Update PENDING.md
Feb 4, 2019
045d9f4
Split up QueryRewards
Feb 4, 2019
09239a9
Add tests
Feb 4, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions PENDING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ BREAKING CHANGES
* [\#3284](https://github.com/cosmos/cosmos-sdk/issues/3284) Rename the `name`
field to `from` in the `base_req` body.
* [\#3485](https://github.com/cosmos/cosmos-sdk/pull/3485) Error responses are now JSON objects.
* [\#3477][distribution] endpoint changed "all_delegation_rewards" -> "delegator_total_rewards"

* Gaia CLI (`gaiacli`)
- [#3399](https://github.com/cosmos/cosmos-sdk/pull/3399) Add `gaiad validate-genesis` command to facilitate checking of genesis files
Expand All @@ -25,6 +26,7 @@ BREAKING CHANGES
FEATURES

* Gaia REST API
* [\#2358](https://github.com/cosmos/cosmos-sdk/issues/2358) Add distribution module REST interface

* Gaia CLI (`gaiacli`)
* [\#3429](https://github.com/cosmos/cosmos-sdk/issues/3429) Support querying
Expand All @@ -37,6 +39,7 @@ FEATURES

* SDK
* \#3270 [x/staking] limit number of ongoing unbonding delegations /redelegations per pair/trio
* [\#3477][distribution] new query endpoint "delegator_validators"

* Tendermint

Expand All @@ -53,6 +56,7 @@ IMPROVEMENTS
(auto gas) to work with generate only.

* Gaia CLI (`gaiacli`)
* [\#3476](https://github.com/cosmos/cosmos-sdk/issues/3476) New `withdraw-all-rewards` command to withdraw all delegations rewards for delegators.

* Gaia
* [\#3418](https://github.com/cosmos/cosmos-sdk/issues/3418) Add vesting account
Expand Down
38 changes: 8 additions & 30 deletions client/lcd/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ tags:
- name: ICS23
description: Slashing module APIs
- name: ICS24
description: WIP - Fee distribution module APIs
description: Fee distribution module APIs
- name: version
description: Query app version
schemes:
Expand Down Expand Up @@ -1846,9 +1846,9 @@ paths:
type: string
500:
description: Internal Server Error
/distribution/pool:
/distribution/outstanding_rewards:
get:
summary: Fee distribution pool
summary: Fee distribution outstanding rewards
tags:
- ICS24
produces:
Expand All @@ -1857,7 +1857,9 @@ paths:
200:
description: OK
schema:
$ref: "#/definitions/FeePool"
type: array
items:
$ref: "#/definitions/Coin"
500:
description: Internal Server Error
definitions:
Expand Down Expand Up @@ -2198,7 +2200,7 @@ definitions:
power:
type: string
example: "1000"
accum:
proposer_priority:
type: string
example: "1000"
TextProposal:
Expand Down Expand Up @@ -2367,36 +2369,12 @@ definitions:
type: string
shares_dst:
type: string
FeePool:
type: object
properties:
community_pool:
type: array
items:
$ref: "#/definitions/Coin"
val_accum:
$ref: "#/definitions/TotalAccum"
val_pool:
type: array
items:
$ref: "#/definitions/Coin"
TotalAccum:
type: object
properties:
update_height:
type: integer
accum:
type: string
ValidatorDistInfo:
type: object
properties:
operator_addr:
$ref: "#/definitions/ValidatorAddress"
fee_pool_withdrawal_height:
type: integer
del_accum:
$ref: "#/definitions/TotalAccum"
del_pool:
self_bond_rewards:
type: array
items:
$ref: "#/definitions/Coin"
Expand Down
6 changes: 4 additions & 2 deletions cmd/gaia/cmd/gaiacli/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
at "github.com/cosmos/cosmos-sdk/x/auth"
auth "github.com/cosmos/cosmos-sdk/x/auth/client/rest"
bank "github.com/cosmos/cosmos-sdk/x/bank/client/rest"
dist "github.com/cosmos/cosmos-sdk/x/distribution"
dist "github.com/cosmos/cosmos-sdk/x/distribution/client/rest"
gv "github.com/cosmos/cosmos-sdk/x/gov"
gov "github.com/cosmos/cosmos-sdk/x/gov/client/rest"
sl "github.com/cosmos/cosmos-sdk/x/slashing"
Expand All @@ -35,6 +35,7 @@ import (

authcmd "github.com/cosmos/cosmos-sdk/x/auth/client/cli"
bankcmd "github.com/cosmos/cosmos-sdk/x/bank/client/cli"
distcmd "github.com/cosmos/cosmos-sdk/x/distribution"
distClient "github.com/cosmos/cosmos-sdk/x/distribution/client"
govClient "github.com/cosmos/cosmos-sdk/x/gov/client"
slashingClient "github.com/cosmos/cosmos-sdk/x/slashing/client"
Expand Down Expand Up @@ -65,7 +66,7 @@ func main() {
// TODO: Make the lcd command take a list of ModuleClient
mc := []sdk.ModuleClients{
govClient.NewModuleClient(gv.StoreKey, cdc),
distClient.NewModuleClient(dist.StoreKey, cdc),
distClient.NewModuleClient(distcmd.StoreKey, cdc),
stakingClient.NewModuleClient(st.StoreKey, cdc),
slashingClient.NewModuleClient(sl.StoreKey, cdc),
}
Expand Down Expand Up @@ -161,6 +162,7 @@ func registerRoutes(rs *lcd.RestServer) {
tx.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc)
auth.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, at.StoreKey)
bank.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, rs.KeyBase)
dist.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, distcmd.StoreKey)
staking.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, rs.KeyBase)
slashing.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc, rs.KeyBase)
gov.RegisterRoutes(rs.CliCtx, rs.Mux, rs.Cdc)
Expand Down
21 changes: 12 additions & 9 deletions x/distribution/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ type (
FeeCollectionKeeper = types.FeeCollectionKeeper

// querier param types
QueryValidatorCommissionParams = keeper.QueryValidatorCommissionParams
QueryValidatorSlashesParams = keeper.QueryValidatorSlashesParams
QueryDelegationRewardsParams = keeper.QueryDelegationRewardsParams
QueryValidatorCommissionParams = keeper.QueryValidatorCommissionParams
QueryValidatorSlashesParams = keeper.QueryValidatorSlashesParams
QueryDelegationRewardsParams = keeper.QueryDelegationRewardsParams
QueryDelegatorWithdrawAddrParams = keeper.QueryDelegatorWithdrawAddrParams
)

const (
Expand All @@ -49,12 +50,14 @@ var (
NewMsgWithdrawDelegatorReward = types.NewMsgWithdrawDelegatorReward
NewMsgWithdrawValidatorCommission = types.NewMsgWithdrawValidatorCommission

NewKeeper = keeper.NewKeeper
NewQuerier = keeper.NewQuerier
NewQueryValidatorCommissionParams = keeper.NewQueryValidatorCommissionParams
NewQueryValidatorSlashesParams = keeper.NewQueryValidatorSlashesParams
NewQueryDelegationRewardsParams = keeper.NewQueryDelegationRewardsParams
DefaultParamspace = keeper.DefaultParamspace
NewKeeper = keeper.NewKeeper
NewQuerier = keeper.NewQuerier
NewQueryValidatorCommissionParams = keeper.NewQueryValidatorCommissionParams
NewQueryValidatorSlashesParams = keeper.NewQueryValidatorSlashesParams
NewQueryDelegationRewardsParams = keeper.NewQueryDelegationRewardsParams
NewQueryDelegatorParams = keeper.NewQueryDelegatorParams
NewQueryDelegatorWithdrawAddrParams = keeper.NewQueryDelegatorWithdrawAddrParams
DefaultParamspace = keeper.DefaultParamspace

RegisterCodec = types.RegisterCodec
DefaultGenesisState = types.DefaultGenesisState
Expand Down
69 changes: 8 additions & 61 deletions x/distribution/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
distr "github.com/cosmos/cosmos-sdk/x/distribution"
"github.com/cosmos/cosmos-sdk/x/distribution/client/common"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
)

Expand All @@ -21,34 +22,10 @@ func GetCmdQueryParams(queryRoute string, cdc *codec.Codec) *cobra.Command {
Short: "Query distribution params",
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)

route := fmt.Sprintf("custom/%s/params/community_tax", queryRoute)
retCommunityTax, err := cliCtx.QueryWithData(route, []byte{})
if err != nil {
return err
}

route = fmt.Sprintf("custom/%s/params/base_proposer_reward", queryRoute)
retBaseProposerReward, err := cliCtx.QueryWithData(route, []byte{})
params, err := common.QueryParams(cliCtx, queryRoute)
if err != nil {
return err
}

route = fmt.Sprintf("custom/%s/params/bonus_proposer_reward", queryRoute)
retBonusProposerReward, err := cliCtx.QueryWithData(route, []byte{})
if err != nil {
return err
}

route = fmt.Sprintf("custom/%s/params/withdraw_addr_enabled", queryRoute)
retWithdrawAddrEnabled, err := cliCtx.QueryWithData(route, []byte{})
if err != nil {
return err
}

params := NewPrettyParams(retCommunityTax, retBaseProposerReward,
retBonusProposerReward, retWithdrawAddrEnabled)

return cliCtx.PrintOutput(params)
},
}
Expand Down Expand Up @@ -90,13 +67,7 @@ func GetCmdQueryValidatorCommission(queryRoute string, cdc *codec.Codec) *cobra.
return err
}

bz, err := cdc.MarshalJSON(distr.NewQueryValidatorCommissionParams(validatorAddr))
if err != nil {
return err
}

route := fmt.Sprintf("custom/%s/validator_commission", queryRoute)
res, err := cliCtx.QueryWithData(route, bz)
res, err := common.QueryValidatorCommission(cliCtx, cdc, queryRoute, validatorAddr)
if err != nil {
return err
}
Expand Down Expand Up @@ -159,42 +130,18 @@ func GetCmdQueryDelegatorRewards(queryRoute string, cdc *codec.Codec) *cobra.Com
RunE: func(cmd *cobra.Command, args []string) error {
cliCtx := context.NewCLIContext().WithCodec(cdc)

delegatorAddr, err := sdk.AccAddressFromBech32(args[0])
if err != nil {
return err
}

var (
route string
params distr.QueryDelegationRewardsParams
result sdk.DecCoins
)

if len(args) == 1 {
// query for all rewards
params = distr.NewQueryDelegationRewardsParams(delegatorAddr, nil)
route = fmt.Sprintf("custom/%s/all_delegation_rewards", queryRoute)
} else {
valAddr := ""
if len(args) == 2 {
// query for rewards from a particular validator
validatorAddr, err := sdk.ValAddressFromBech32(args[1])
if err != nil {
return err
}

params = distr.NewQueryDelegationRewardsParams(delegatorAddr, validatorAddr)
route = fmt.Sprintf("custom/%s/delegation_rewards", queryRoute)
}

bz, err := cdc.MarshalJSON(params)
if err != nil {
return err
valAddr = args[1]
}

resp, err := cliCtx.QueryWithData(route, bz)
resp, err := common.QueryRewards(cliCtx, cdc, queryRoute, args[0], valAddr)
if err != nil {
return err
}

var result sdk.DecCoins
cdc.MustUnmarshalJSON(resp, &result)
return cliCtx.PrintOutput(result)
},
Expand Down
35 changes: 34 additions & 1 deletion x/distribution/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
authtxb "github.com/cosmos/cosmos-sdk/x/auth/client/txbuilder"

"github.com/cosmos/cosmos-sdk/x/distribution/client/common"
"github.com/cosmos/cosmos-sdk/x/distribution/types"
)

Expand Down Expand Up @@ -89,7 +90,39 @@ func GetCmdWithdrawRewards(cdc *codec.Codec) *cobra.Command {
return cmd
}

// GetCmdDelegate implements the delegate command.
// command to withdraw all rewards
func GetCmdWithdrawAllRewards(cdc *codec.Codec, queryRoute string) *cobra.Command {
cmd := &cobra.Command{
Use: "withdraw-all-rewards [delegator-addr]",
Short: "withdraw all delegations rewards for a delegator",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {

txBldr := authtxb.NewTxBuilderFromCLI().WithTxEncoder(utils.GetTxEncoder(cdc))
cliCtx := context.NewCLIContext().
WithCodec(cdc).
WithAccountDecoder(cdc)

delAddr := cliCtx.GetFromAddress()
msgs, err := common.WithdrawAllDelegatorRewards(cliCtx, cdc, queryRoute, delAddr)
if err != nil {
return err
}

if cliCtx.GenerateOnly {
return utils.PrintUnsignedStdTx(os.Stdout, txBldr, cliCtx, msgs, false)
}

// build and sign the transaction, then broadcast to Tendermint
return utils.CompleteAndBroadcastTxCLI(txBldr, cliCtx, msgs)
},
}
cmd.Flags().String(flagOnlyFromValidator, "", "only withdraw from this validator address (in bech)")
cmd.Flags().Bool(flagIsValidator, false, "also withdraw validator's commission")
return cmd
}

// command to replace a delegator's withdrawal address
func GetCmdSetWithdrawAddr(cdc *codec.Codec) *cobra.Command {
cmd := &cobra.Command{
Use: "set-withdraw-addr [withdraw-addr]",
Expand Down
Loading