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: not check empty string #207

Merged
merged 1 commit into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
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