From e26c8db19932bdb7224f17ac465b83b5147766a8 Mon Sep 17 00:00:00 2001 From: jholdstock Date: Thu, 14 Sep 2023 11:52:47 +0100 Subject: [PATCH] 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. --- cmd/vspd/config.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/cmd/vspd/config.go b/cmd/vspd/config.go index efaf05e..d1ea646 100644 --- a/cmd/vspd/config.go +++ b/cmd/vspd/config.go @@ -7,6 +7,7 @@ package main import ( "errors" "fmt" + "math" "net" "os" "os/user" @@ -15,7 +16,6 @@ import ( "strings" "time" - "decred.org/dcrwallet/v3/wallet/txrules" "github.com/decred/dcrd/dcrutil/v4" "github.com/decred/dcrd/hdkeychain/v3" "github.com/decred/slog" @@ -293,8 +293,16 @@ func loadConfig() (*vspdConfig, error) { 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. - 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") }