Skip to content

Commit

Permalink
fix issues with zero fee
Browse files Browse the repository at this point in the history
  • Loading branch information
harish551 committed Jan 29, 2024
1 parent b80a68c commit 4fd8282
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
8 changes: 4 additions & 4 deletions x/streampay/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,11 @@ func (m msgServer) StreamSend(goCtx context.Context, msg *types.MsgStreamSend) (
if !msg.PaymentFee.Equal(requiredFeeAmount) {
return nil, errorsmod.Wrap(types.ErrInvalidStreamPaymentFee, "fee coin didn't match with stream coin")
}

if err := m.distributionKeeper.FundCommunityPool(ctx, sdk.NewCoins(requiredFeeAmount), sender); err != nil {
return nil, err
if requiredFeeAmount.Amount.GTE(sdk.NewInt(1)) {
if err := m.distributionKeeper.FundCommunityPool(ctx, sdk.NewCoins(requiredFeeAmount), sender); err != nil {
return nil, err
}
}

streamPaymentId, err := m.Keeper.CreateStreamPayment(
ctx,
sender, recipient,
Expand Down
4 changes: 2 additions & 2 deletions x/streampay/types/messages.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ func (msg MsgStreamSend) ValidateBasic() error {
if err != nil {
return err
}
if err := validateAmount(msg.Amount); err != nil {
if err := validateStreamAmount(msg.Amount); err != nil {
return err
}
if err := validateAmount(msg.PaymentFee); err != nil {
if err := validateFeeAmount(msg.PaymentFee); err != nil {
return err
}
if err := ValidateDuration(msg.Duration); err != nil {
Expand Down
14 changes: 12 additions & 2 deletions x/streampay/types/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func validateStreamPayment(streamPayment StreamPayment) error {
if _, err := sdk.AccAddressFromBech32(streamPayment.Recipient); err != nil {
return err
}
if err := validateAmount(streamPayment.TotalAmount); err != nil {
if err := validateStreamAmount(streamPayment.TotalAmount); err != nil {
return err
}
if err := ValidateTimestamp(streamPayment.StartTime); err != nil {
Expand All @@ -28,7 +28,7 @@ func validateStreamPayment(streamPayment StreamPayment) error {
return validateStreamType(streamPayment.StreamType)
}

func validateAmount(amount sdk.Coin) error {
func validateStreamAmount(amount sdk.Coin) error {
if !amount.IsValid() || amount.IsNil() || amount.Amount.LTE(sdk.ZeroInt()) {
return errorsmod.Wrapf(
ErrInvalidAmount,
Expand All @@ -38,6 +38,16 @@ func validateAmount(amount sdk.Coin) error {
return nil
}

func validateFeeAmount(amount sdk.Coin) error {
if !amount.IsValid() || amount.IsNil() || amount.Amount.LT(sdk.ZeroInt()) {
return errorsmod.Wrapf(
ErrInvalidAmount,
fmt.Sprintf("fee amount %s is not valid", amount.String()),
)
}
return nil
}

func validateStreamType(_type StreamType) error {
if !(_type == TypeDelayed || _type == TypeContinuous || _type == TypePeriodic) {
return errorsmod.Wrapf(
Expand Down

0 comments on commit 4fd8282

Please sign in to comment.