Skip to content

Commit

Permalink
fix: not check empty string (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
simlecode committed Jul 22, 2022
1 parent 044daef commit 808d182
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
15 changes: 1 addition & 14 deletions api/messager_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package api

import (
"context"
"github.com/filecoin-project/go-state-types/abi"
"time"

"github.com/filecoin-project/go-address"
Expand Down Expand Up @@ -108,19 +107,7 @@ func (m MessageImp) UpdateFilledMessageByID(ctx context.Context, id string) (str
}

func (m MessageImp) ReplaceMessage(ctx context.Context, id string, auto bool, maxFeeStr string, gasLimit int64, gasPremiumStr string, gasFeecapStr string) (cid.Cid, error) {
maxFee, err := venusTypes.ParseFIL(maxFeeStr)
if err != nil {
return cid.Undef, err
}
gasPremium, err := venusTypes.BigFromString(gasPremiumStr)
if err != nil {
return cid.Undef, err
}
gasFeecap, err := venusTypes.BigFromString(gasFeecapStr)
if err != nil {
return cid.Undef, err
}
return m.MessageSrv.ReplaceMessage(ctx, id, auto, abi.TokenAmount(maxFee), gasLimit, gasPremium, gasFeecap)
return m.MessageSrv.ReplaceMessage(ctx, id, auto, maxFeeStr, gasLimit, gasPremiumStr, gasFeecapStr)
}

func (m MessageImp) RepublishMessage(ctx context.Context, id string) error {
Expand Down
21 changes: 18 additions & 3 deletions service/message_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ func (ms *MessageService) UpdateFilledMessageByID(ctx context.Context, id string
return id, ms.updateFilledMessage(ctx, msg)
}

func (ms *MessageService) ReplaceMessage(ctx context.Context, id string, auto bool, maxFee abi.TokenAmount, gasLimit int64, gasPremium abi.TokenAmount, gasFeecap abi.TokenAmount) (cid.Cid, error) {
func (ms *MessageService) ReplaceMessage(ctx context.Context, id string, auto bool, maxFeeStr string, gasLimit int64, gasPremiumStr, gasFeecapStr string) (cid.Cid, error) {
msg, err := ms.GetMessageByUid(ctx, id)
if err != nil {
return cid.Undef, fmt.Errorf("found message %v", err)
Expand All @@ -850,8 +850,13 @@ func (ms *MessageService) ReplaceMessage(ctx context.Context, id string, auto bo
if auto {
minRBF := computeMinRBF(msg.GasPremium)

mss := &venusTypes.MessageSendSpec{
MaxFee: maxFee,
mss := &venusTypes.MessageSendSpec{}
if len(maxFeeStr) > 0 {
maxFee, err := venusTypes.ParseFIL(maxFeeStr)
if err != nil {
return cid.Undef, err
}
mss.MaxFee = big.Int(maxFee)
}

// msg.GasLimit = 0 // TODO: need to fix the way we estimate gas limits to account for the messages already being in the mempool
Expand Down Expand Up @@ -884,6 +889,16 @@ func (ms *MessageService) ReplaceMessage(ctx context.Context, id string, auto bo
if gasLimit > 0 {
msg.GasLimit = gasLimit
}

gasPremium, err := venusTypes.BigFromString(gasPremiumStr)
if err != nil {
return cid.Undef, fmt.Errorf("parse gas premium failed: %v", err)
}
gasFeecap, err := venusTypes.BigFromString(gasFeecapStr)
if err != nil {
return cid.Undef, fmt.Errorf("parse gas feecap failed: %v", err)
}

if big.Cmp(gasPremium, big.Zero()) <= 0 {
return cid.Undef, fmt.Errorf("gas premium(%s) must bigger than zero", gasPremium)
}
Expand Down

0 comments on commit 808d182

Please sign in to comment.