forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge PR cosmos#4101: Return per-validator rewards when querying dele…
…gator rewards
- Loading branch information
1 parent
9cdd1d3
commit 7693708
Showing
11 changed files
with
171 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#3715 query distr rewards returns per-validator | ||
rewards along with rewards total amount. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#3715 Update /distribution/delegators/{delegatorAddr}/rewards GET endpoint | ||
as per new specs. For a given delegation, the endpoint now returns the | ||
comprehensive list of validator-reward tuples along with the grand total. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package types | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
) | ||
|
||
// QueryDelegatorTotalRewardsResponse defines the properties of | ||
// QueryDelegatorTotalRewards query's response. | ||
type QueryDelegatorTotalRewardsResponse struct { | ||
Rewards []DelegationDelegatorReward `json:"rewards"` | ||
Total sdk.DecCoins `json:"total"` | ||
} | ||
|
||
// NewQueryDelegatorTotalRewardsResponse constructs a QueryDelegatorTotalRewardsResponse | ||
func NewQueryDelegatorTotalRewardsResponse(rewards []DelegationDelegatorReward, | ||
total sdk.DecCoins) QueryDelegatorTotalRewardsResponse { | ||
return QueryDelegatorTotalRewardsResponse{Rewards: rewards, Total: total} | ||
} | ||
|
||
func (res QueryDelegatorTotalRewardsResponse) String() string { | ||
out := "Delegator Total Rewards:\n" | ||
out += " Rewards:" | ||
for _, reward := range res.Rewards { | ||
out += fmt.Sprintf(` | ||
ValidatorAddress: %s | ||
Reward: %s`, reward.ValidatorAddress, reward.Reward) | ||
} | ||
out += fmt.Sprintf("\n Total: %s\n", res.Total) | ||
return strings.TrimSpace(out) | ||
} | ||
|
||
// DelegationDelegatorReward defines the properties | ||
// of a delegator's delegation reward. | ||
type DelegationDelegatorReward struct { | ||
ValidatorAddress sdk.ValAddress `json:"validator_address"` | ||
Reward sdk.DecCoins `json:"reward"` | ||
} | ||
|
||
// NewDelegationDelegatorReward constructs a DelegationDelegatorReward. | ||
func NewDelegationDelegatorReward(valAddr sdk.ValAddress, | ||
reward sdk.DecCoins) DelegationDelegatorReward { | ||
return DelegationDelegatorReward{ValidatorAddress: valAddr, Reward: reward} | ||
} |