From 50571bb7a930a61b2292e9f8e12e1600f752782e Mon Sep 17 00:00:00 2001 From: Christoph Otter Date: Fri, 25 Aug 2023 16:52:43 +0200 Subject: [PATCH] Add new distribution query types --- types/queries.go | 41 +++++++++++++++++++++++++++++++++++++++++ types/types.go | 17 +++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/types/queries.go b/types/queries.go index 7f9e79e6a..5d5f893a0 100644 --- a/types/queries.go +++ b/types/queries.go @@ -364,7 +364,14 @@ type Delegation struct { } type DistributionQuery struct { + // See DelegatorWithdrawAddress *DelegatorWithdrawAddressQuery `json:"delegator_withdraw_address,omitempty"` + // See + DelegationRewards *DelegationRewardsQuery `json:"delegation_rewards,omitempty"` + // See + DelegationTotalRewards *DelegationTotalRewardsQuery `json:"delegation_total_rewards,omitempty"` + // See + DelegatorValidators *DelegatorValidatorsQuery `json:"delegator_validators,omitempty"` } type DelegatorWithdrawAddressQuery struct { @@ -375,6 +382,40 @@ type DelegatorWithdrawAddressResponse struct { WithdrawAddress string `json:"withdraw_address"` } +type DelegationRewardsQuery struct { + DelegatorAddress string `json:"delegator_address"` + ValidatorAddress string `json:"validator_address"` +} + +// See +type DelegationRewardsResponse struct { + Rewards []DecCoin `json:"rewards"` +} + +type DelegationTotalRewardsQuery struct { + DelegatorAddress string `json:"delegator_address"` +} + +// See +type DelegationTotalRewardsResponse struct { + Rewards []DelegatorReward `json:"rewards"` + Total []DecCoin `json:"total"` +} + +type DelegatorReward struct { + Reward []DecCoin `json:"reward"` + ValidatorAddress string `json:"validator_address"` +} + +type DelegatorValidatorsQuery struct { + DelegatorAddress string `json:"delegator_address"` +} + +// See +type DelegatorValidatorsResponse struct { + Validators []string `json:"validators"` +} + // DelegationResponse is the expected response to DelegationsQuery type DelegationResponse struct { Delegation *FullDelegation `json:"delegation,omitempty"` diff --git a/types/types.go b/types/types.go index cfc3ed857..a8a8548c9 100644 --- a/types/types.go +++ b/types/types.go @@ -94,6 +94,23 @@ type DenomUnit struct { Aliases []string `json:"aliases"` } +// A coin type with decimal amount. +// Modeled after the Cosmos SDK's [DecCoin] type. +// However, in contrast to the Cosmos SDK the `amount` string MUST always have a dot at JSON level, +// see . +// Also if Cosmos SDK choses to migrate away from fixed point decimals +// (as shown [here](https://github.com/cosmos/cosmos-sdk/blob/v0.47.4/x/group/internal/math/dec.go#L13-L21) and discussed [here](https://github.com/cosmos/cosmos-sdk/issues/11783)), +// wasmd needs to truncate the decimal places to 18. +// +// [DecCoin]: (https://github.com/cosmos/cosmos-sdk/blob/v0.47.4/proto/cosmos/base/v1beta1/coin.proto#L28-L38) +type DecCoin struct { + // An amount in the base denom of the distributed token. + // + // Some chains have choosen atto (10^-18) for their token's base denomination. If we used `Decimal` here, we could only store 340282366920938463463.374607431768211455atoken which is 340.28 TOKEN. + Amount string `json:"amount"` + Denom string `json:"denom"` +} + // Simplified version of the cosmos-sdk PageRequest type type PageRequest struct { // Key is a value returned in PageResponse.next_key to begin