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

Converted balance from sdk.Int to sdk.Coin inside DelegationResponse #4806

Merged
merged 6 commits into from
Aug 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .pending/breaking/rest/_The-balance-field-i
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#4783 The balance field in the DelegationResponse type is now sdk.Coin instead of sdk.Int
4 changes: 2 additions & 2 deletions client/lcd/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2365,8 +2365,8 @@ definitions:
type: string
shares:
type: string
height:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why was this deleted ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the LCD response, it didn't appear to be present inside the response itself. Am I wrong or was it an error?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The entire swagger config needs to be refactored (responses are now: {"height": X, "result": Y})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, can we resolve this and open up another issue?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 mind opening it?

type: integer
balance:
$ref: "#/definitions/Coin"
UnbondingDelegationPair:
type: object
properties:
Expand Down
2 changes: 1 addition & 1 deletion x/staking/keeper/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ func delegationToDelegationResponse(ctx sdk.Context, k Keeper, del types.Delegat
del.DelegatorAddress,
del.ValidatorAddress,
del.Shares,
val.TokensFromShares(del.Shares).TruncateInt(),
sdk.NewCoin(k.BondDenom(ctx), val.TokensFromShares(del.Shares).TruncateInt()),
), nil
}

Expand Down
8 changes: 4 additions & 4 deletions x/staking/keeper/querier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestNewQuerier(t *testing.T) {
func TestQueryParametersPool(t *testing.T) {
cdc := codec.New()
ctx, _, keeper, _ := CreateTestInput(t, false, 1000)
bondDenom := keeper.BondDenom(ctx)
bondDenom := sdk.DefaultBondDenom

res, err := queryParameters(ctx, keeper)
require.Nil(t, err)
Expand Down Expand Up @@ -268,7 +268,7 @@ func TestQueryDelegation(t *testing.T) {

require.Equal(t, delegation.ValidatorAddress, delegationRes.ValidatorAddress)
require.Equal(t, delegation.DelegatorAddress, delegationRes.DelegatorAddress)
require.Equal(t, delegation.Shares.TruncateInt(), delegationRes.Balance)
require.Equal(t, sdk.NewCoin(sdk.DefaultBondDenom, delegation.Shares.TruncateInt()), delegationRes.Balance)

// Query Delegator Delegations
query = abci.RequestQuery{
Expand All @@ -285,7 +285,7 @@ func TestQueryDelegation(t *testing.T) {
require.Len(t, delegatorDelegations, 1)
require.Equal(t, delegation.ValidatorAddress, delegatorDelegations[0].ValidatorAddress)
require.Equal(t, delegation.DelegatorAddress, delegatorDelegations[0].DelegatorAddress)
require.Equal(t, delegation.Shares.TruncateInt(), delegatorDelegations[0].Balance)
require.Equal(t, sdk.NewCoin(sdk.DefaultBondDenom, delegation.Shares.TruncateInt()), delegatorDelegations[0].Balance)

// error unknown request
query.Data = bz[:len(bz)-1]
Expand All @@ -312,7 +312,7 @@ func TestQueryDelegation(t *testing.T) {
require.Len(t, delegatorDelegations, 1)
require.Equal(t, delegation.ValidatorAddress, delegationsRes[0].ValidatorAddress)
require.Equal(t, delegation.DelegatorAddress, delegationsRes[0].DelegatorAddress)
require.Equal(t, delegation.Shares.TruncateInt(), delegationsRes[0].Balance)
require.Equal(t, sdk.NewCoin(sdk.DefaultBondDenom, delegation.Shares.TruncateInt()), delegationsRes[0].Balance)

// Query unbonging delegation
unbondingTokens := sdk.TokensFromConsensusPower(10)
Expand Down
4 changes: 2 additions & 2 deletions x/staking/types/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,10 @@ func (d Redelegations) String() (out string) {
// in addition to shares which is more suitable for client responses.
type DelegationResponse struct {
Delegation
Balance sdk.Int `json:"balance" yaml:"balance"`
Balance sdk.Coin `json:"balance" yaml:"balance"`
}

func NewDelegationResp(d sdk.AccAddress, v sdk.ValAddress, s sdk.Dec, b sdk.Int) DelegationResponse {
func NewDelegationResp(d sdk.AccAddress, v sdk.ValAddress, s sdk.Dec, b sdk.Coin) DelegationResponse {
return DelegationResponse{NewDelegation(d, v, s), b}
}

Expand Down
6 changes: 4 additions & 2 deletions x/staking/types/delegation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,10 @@ func TestRedelegationString(t *testing.T) {

func TestDelegationResponses(t *testing.T) {
cdc := codec.New()
dr1 := NewDelegationResp(sdk.AccAddress(valAddr1), valAddr2, sdk.NewDec(5), sdk.NewInt(5))
dr2 := NewDelegationResp(sdk.AccAddress(valAddr1), valAddr3, sdk.NewDec(5), sdk.NewInt(5))
dr1 := NewDelegationResp(sdk.AccAddress(valAddr1), valAddr2, sdk.NewDec(5),
sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(5)))
dr2 := NewDelegationResp(sdk.AccAddress(valAddr1), valAddr3, sdk.NewDec(5),
sdk.NewCoin(sdk.DefaultBondDenom, sdk.NewInt(5)))
drs := DelegationResponses{dr1, dr2}

bz1, err := json.Marshal(dr1)
Expand Down