cwgoes comments addressed
This commit is contained in:
parent
cbbba2cf4f
commit
b2c5814fd0
|
@ -212,8 +212,6 @@ func handleMsgUnbond(ctx sdk.Context, msg MsgUnbond, k Keeper) sdk.Result {
|
||||||
return ErrInsufficientFunds().Result()
|
return ErrInsufficientFunds().Result()
|
||||||
}
|
}
|
||||||
|
|
||||||
// if shares set to special case Max then we're good
|
|
||||||
if msg.Shares != "MAX" {
|
|
||||||
// test getting rational number from decimal provided
|
// test getting rational number from decimal provided
|
||||||
shares, err := sdk.NewRatFromDecimal(msg.Shares)
|
shares, err := sdk.NewRatFromDecimal(msg.Shares)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -221,10 +219,22 @@ func handleMsgUnbond(ctx sdk.Context, msg MsgUnbond, k Keeper) sdk.Result {
|
||||||
}
|
}
|
||||||
|
|
||||||
// test that there are enough shares to unbond
|
// test that there are enough shares to unbond
|
||||||
|
if msg.Shares == "MAX" {
|
||||||
|
if !bond.Shares.GT(sdk.ZeroRat) {
|
||||||
|
return ErrNotEnoughBondShares(msg.Shares).Result()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
if !bond.Shares.GT(shares) {
|
if !bond.Shares.GT(shares) {
|
||||||
return ErrNotEnoughBondShares(msg.Shares).Result()
|
return ErrNotEnoughBondShares(msg.Shares).Result()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// get candidate
|
||||||
|
candidate, found := k.GetCandidate(ctx, msg.CandidateAddr)
|
||||||
|
if !found {
|
||||||
|
return ErrNoCandidateForAddress().Result()
|
||||||
|
}
|
||||||
|
|
||||||
if ctx.IsCheckTx() {
|
if ctx.IsCheckTx() {
|
||||||
return sdk.Result{
|
return sdk.Result{
|
||||||
GasUsed: GasUnbond,
|
GasUsed: GasUnbond,
|
||||||
|
@ -244,17 +254,9 @@ func handleMsgUnbond(ctx sdk.Context, msg MsgUnbond, k Keeper) sdk.Result {
|
||||||
}
|
}
|
||||||
|
|
||||||
// subtract bond tokens from delegator bond
|
// subtract bond tokens from delegator bond
|
||||||
if bond.Shares.LT(shares) { // bond shares < msg shares
|
|
||||||
return ErrInsufficientFunds().Result()
|
|
||||||
}
|
|
||||||
bond.Shares = bond.Shares.Sub(shares)
|
bond.Shares = bond.Shares.Sub(shares)
|
||||||
|
|
||||||
// get pubKey candidate
|
// remove the bond
|
||||||
candidate, found := k.GetCandidate(ctx, msg.CandidateAddr)
|
|
||||||
if !found {
|
|
||||||
return ErrNoCandidateForAddress().Result()
|
|
||||||
}
|
|
||||||
|
|
||||||
revokeCandidacy := false
|
revokeCandidacy := false
|
||||||
if bond.Shares.IsZero() {
|
if bond.Shares.IsZero() {
|
||||||
|
|
||||||
|
@ -265,7 +267,6 @@ func handleMsgUnbond(ctx sdk.Context, msg MsgUnbond, k Keeper) sdk.Result {
|
||||||
revokeCandidacy = true
|
revokeCandidacy = true
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove the bond
|
|
||||||
k.removeDelegatorBond(ctx, bond)
|
k.removeDelegatorBond(ctx, bond)
|
||||||
} else {
|
} else {
|
||||||
k.setDelegatorBond(ctx, bond)
|
k.setDelegatorBond(ctx, bond)
|
||||||
|
@ -276,7 +277,7 @@ func handleMsgUnbond(ctx sdk.Context, msg MsgUnbond, k Keeper) sdk.Result {
|
||||||
returnCoins := sdk.Coins{{k.GetParams(ctx).BondDenom, returnAmount}}
|
returnCoins := sdk.Coins{{k.GetParams(ctx).BondDenom, returnAmount}}
|
||||||
k.coinKeeper.AddCoins(ctx, bond.DelegatorAddr, returnCoins)
|
k.coinKeeper.AddCoins(ctx, bond.DelegatorAddr, returnCoins)
|
||||||
|
|
||||||
// lastly if an revoke candidate if necessary
|
// revoke candidate if necessary
|
||||||
if revokeCandidacy {
|
if revokeCandidacy {
|
||||||
|
|
||||||
// change the share types to unbonded if they were not already
|
// change the share types to unbonded if they were not already
|
||||||
|
|
Loading…
Reference in New Issue