Skip to content

Commit

Permalink
Add new distribution query types
Browse files Browse the repository at this point in the history
  • Loading branch information
chipshort committed Aug 30, 2023
1 parent a70996d commit 50571bb
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
41 changes: 41 additions & 0 deletions types/queries.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,14 @@ type Delegation struct {
}

type DistributionQuery struct {
// See <https://github.com/cosmos/cosmos-sdk/blob/c74e2887b0b73e81d48c2f33e6b1020090089ee0/proto/cosmos/distribution/v1beta1/query.proto#L222-L230>
DelegatorWithdrawAddress *DelegatorWithdrawAddressQuery `json:"delegator_withdraw_address,omitempty"`
// See <https://github.com/cosmos/cosmos-sdk/blob/c74e2887b0b73e81d48c2f33e6b1020090089ee0/proto/cosmos/distribution/v1beta1/query.proto#L157-L167>
DelegationRewards *DelegationRewardsQuery `json:"delegation_rewards,omitempty"`
// See <https://github.com/cosmos/cosmos-sdk/blob/c74e2887b0b73e81d48c2f33e6b1020090089ee0/proto/cosmos/distribution/v1beta1/query.proto#L180-L187>
DelegationTotalRewards *DelegationTotalRewardsQuery `json:"delegation_total_rewards,omitempty"`
// See <https://github.com/cosmos/cosmos-sdk/blob/b0acf60e6c39f7ab023841841fc0b751a12c13ff/proto/cosmos/distribution/v1beta1/query.proto#L202-L210>
DelegatorValidators *DelegatorValidatorsQuery `json:"delegator_validators,omitempty"`
}

type DelegatorWithdrawAddressQuery struct {
Expand All @@ -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 <https://github.com/cosmos/cosmos-sdk/blob/c74e2887b0b73e81d48c2f33e6b1020090089ee0/proto/cosmos/distribution/v1beta1/query.proto#L169-L178>
type DelegationRewardsResponse struct {
Rewards []DecCoin `json:"rewards"`
}

type DelegationTotalRewardsQuery struct {
DelegatorAddress string `json:"delegator_address"`
}

// See <https://github.com/cosmos/cosmos-sdk/blob/c74e2887b0b73e81d48c2f33e6b1020090089ee0/proto/cosmos/distribution/v1beta1/query.proto#L189-L200>
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 <https://github.com/cosmos/cosmos-sdk/blob/b0acf60e6c39f7ab023841841fc0b751a12c13ff/proto/cosmos/distribution/v1beta1/query.proto#L212-L220>
type DelegatorValidatorsResponse struct {
Validators []string `json:"validators"`
}

// DelegationResponse is the expected response to DelegationsQuery
type DelegationResponse struct {
Delegation *FullDelegation `json:"delegation,omitempty"`
Expand Down
17 changes: 17 additions & 0 deletions types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/cosmos/cosmos-sdk/issues/10863>.
// 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
Expand Down

0 comments on commit 50571bb

Please sign in to comment.