x/staking: wrap denom error (#6718)

This commit is contained in:
Federico Kunze 2020-07-14 16:38:35 +02:00 committed by GitHub
parent 5dfc4a2ec9
commit eb72ee042a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 12 additions and 8 deletions

View File

@ -59,8 +59,9 @@ func handleMsgCreateValidator(ctx sdk.Context, msg *types.MsgCreateValidator, k
return nil, types.ErrValidatorPubKeyExists return nil, types.ErrValidatorPubKeyExists
} }
if msg.Value.Denom != k.BondDenom(ctx) { bondDenom := k.BondDenom(ctx)
return nil, types.ErrBadDenom if msg.Value.Denom != bondDenom {
return nil, sdkerrors.Wrapf(types.ErrBadDenom, "got %s, expected %s", msg.Value.Denom, bondDenom)
} }
if _, err := msg.Description.EnsureLength(); err != nil { if _, err := msg.Description.EnsureLength(); err != nil {
@ -186,8 +187,9 @@ func handleMsgDelegate(ctx sdk.Context, msg *types.MsgDelegate, k keeper.Keeper)
return nil, types.ErrNoValidatorFound return nil, types.ErrNoValidatorFound
} }
if msg.Amount.Denom != k.BondDenom(ctx) { bondDenom := k.BondDenom(ctx)
return nil, types.ErrBadDenom if msg.Amount.Denom != bondDenom {
return nil, sdkerrors.Wrapf(types.ErrBadDenom, "got %s, expected %s", msg.Amount.Denom, bondDenom)
} }
// NOTE: source funds are always unbonded // NOTE: source funds are always unbonded
@ -229,8 +231,9 @@ func handleMsgUndelegate(ctx sdk.Context, msg *types.MsgUndelegate, k keeper.Kee
return nil, err return nil, err
} }
if msg.Amount.Denom != k.BondDenom(ctx) { bondDenom := k.BondDenom(ctx)
return nil, types.ErrBadDenom if msg.Amount.Denom != bondDenom {
return nil, sdkerrors.Wrapf(types.ErrBadDenom, "got %s, expected %s", msg.Amount.Denom, bondDenom)
} }
completionTime, err := k.Undelegate(ctx, msg.DelegatorAddress, msg.ValidatorAddress, shares) completionTime, err := k.Undelegate(ctx, msg.DelegatorAddress, msg.ValidatorAddress, shares)
@ -278,8 +281,9 @@ func handleMsgBeginRedelegate(ctx sdk.Context, msg *types.MsgBeginRedelegate, k
return nil, err return nil, err
} }
if msg.Amount.Denom != k.BondDenom(ctx) { bondDenom := k.BondDenom(ctx)
return nil, types.ErrBadDenom if msg.Amount.Denom != bondDenom {
return nil, sdkerrors.Wrapf(types.ErrBadDenom, "got %s, expected %s", msg.Amount.Denom, bondDenom)
} }
completionTime, err := k.BeginRedelegation( completionTime, err := k.BeginRedelegation(