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

FIX: ODEX-320. optimize the error reminder #12

Merged
merged 2 commits into from
Apr 14, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
16 changes: 9 additions & 7 deletions x/staking/keeper/delegation.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ func (k Keeper) UpdateProxy(ctx sdk.Context, delegator types.Delegator, tokens s
// Delegate handles the process of delegating
func (k Keeper) Delegate(ctx sdk.Context, delAddr sdk.AccAddress, token sdk.DecCoin) sdk.Error {

delQuantity := token.Amount

if delQuantity.LT(k.ParamsMinDelegation(ctx)) {
return types.ErrInvaildQuantity(types.DefaultCodespace, delQuantity.String())
delQuantity, minDelLimit := token.Amount, k.ParamsMinDelegation(ctx)
if delQuantity.LT(minDelLimit) {
return types.ErrInsufficientQuantity(types.DefaultCodespace, delQuantity.String(), minDelLimit.String())
}

// 1.transfer account's okt into bondPool
Expand Down Expand Up @@ -67,10 +66,13 @@ func (k Keeper) Undelegate(ctx sdk.Context, delAddr sdk.AccAddress, token sdk.De
if !found {
return time.Time{}, types.ErrNoDelegationVote(types.DefaultCodespace, delAddr.String())
}
quantity := token.Amount
if quantity.LT(k.ParamsMinDelegation(ctx)) || delegator.Tokens.LT(quantity) {
return time.Time{}, types.ErrInvaildQuantity(types.DefaultCodespace, quantity.String())
quantity, minDelLimit := token.Amount, k.ParamsMinDelegation(ctx)
if quantity.LT(minDelLimit) {
return time.Time{}, types.ErrInsufficientQuantity(types.DefaultCodespace, quantity.String(), minDelLimit.String())
} else if delegator.Tokens.LT(quantity) {
return time.Time{}, types.ErrInsufficientDelegation(types.DefaultCodespace, quantity.String(), delegator.Tokens.String())
}

// 1.some okt transfer bondPool into unbondPool
k.bondedTokensToNotBonded(ctx, token)

Expand Down
12 changes: 9 additions & 3 deletions x/staking/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,16 @@ func ErrNotInDelegating(codespace sdk.CodespaceType, addr string) sdk.Error {
"failed. the addr %s is not in the status of undelegating", addr)
}

// ErrInvaildQuantity returns an error when the quantity is invalid
func ErrInvaildQuantity(codespace sdk.CodespaceType, quantity string) sdk.Error {
// ErrInsufficientDelegation returns an error when the delegation left is not enough for unbonding
func ErrInsufficientDelegation(codespace sdk.CodespaceType, quantity, delLeft string) sdk.Error {
return sdk.NewError(codespace, CodeInvalidDelegation,
"failed. the quantity %s is invaild", quantity)
"failed. insufficient delegation. [delegation left]:%s, [quantity to unbond]:%s", delLeft, quantity)
}

// ErrInsufficientQuantity returns an error when the quantity is less than the min delegation limit
func ErrInsufficientQuantity(codespace sdk.CodespaceType, quantity, minLimit string) sdk.Error {
return sdk.NewError(codespace, CodeInvalidDelegation,
"failed. insufficient quantity. [min limit]:%s, [quantity]:%s", minLimit, quantity)
}

// ErrInsufficientMinSelfDelegation returns an error when the msd is not enough
Expand Down