vspd: Copy VSP fee validation func from wallet.

This is such a trivial func that there is no need to import it from
wallet, it can just be copied into this project.
This commit is contained in:
jholdstock 2023-09-14 11:52:47 +01:00 committed by Jamie Holdstock
parent d1766c362e
commit e26c8db199

View File

@ -7,6 +7,7 @@ package main
import ( import (
"errors" "errors"
"fmt" "fmt"
"math"
"net" "net"
"os" "os"
"os/user" "os/user"
@ -15,7 +16,6 @@ import (
"strings" "strings"
"time" "time"
"decred.org/dcrwallet/v3/wallet/txrules"
"github.com/decred/dcrd/dcrutil/v4" "github.com/decred/dcrd/dcrutil/v4"
"github.com/decred/dcrd/hdkeychain/v3" "github.com/decred/dcrd/hdkeychain/v3"
"github.com/decred/slog" "github.com/decred/slog"
@ -293,8 +293,16 @@ func loadConfig() (*vspdConfig, error) {
return nil, errors.New("minimum backupinterval is 30 seconds") return nil, errors.New("minimum backupinterval is 30 seconds")
} }
// validPoolFeeRate tests to see if a pool fee is a valid percentage from
// 0.01% to 100.00%.
validPoolFeeRate := func(feeRate float64) bool {
poolFeeRateTest := feeRate * 100
poolFeeRateTest = math.Floor(poolFeeRateTest)
return poolFeeRateTest >= 1.0 && poolFeeRateTest <= 10000.0
}
// Ensure the fee percentage is valid per txrules. // Ensure the fee percentage is valid per txrules.
if !txrules.ValidPoolFeeRate(cfg.VSPFee) { if !validPoolFeeRate(cfg.VSPFee) {
return nil, errors.New("invalid vspfee - should be greater than 0.01 and less than 100.0") return nil, errors.New("invalid vspfee - should be greater than 0.01 and less than 100.0")
} }