From 2a476d9589289b24a695e80583032b806f062b70 Mon Sep 17 00:00:00 2001 From: jholdstock Date: Fri, 29 May 2020 13:10:16 +0100 Subject: [PATCH] Validate fee config --- config.go | 10 ++++++++-- docs/api.md | 2 +- webapi/templates/homepage.html | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/config.go b/config.go index 625cacf..3347665 100644 --- a/config.go +++ b/config.go @@ -12,6 +12,7 @@ import ( "strings" "time" + "decred.org/dcrwallet/wallet/txrules" "github.com/decred/dcrd/dcrutil/v3" "github.com/decred/dcrd/hdkeychain/v3" flags "github.com/jessevdk/go-flags" @@ -20,7 +21,7 @@ import ( var ( defaultListen = ":3000" defaultLogLevel = "debug" - defaultVSPFee = 0.05 + defaultVSPFee = 5.0 defaultNetwork = "testnet" defaultHomeDir = dcrutil.AppDataDir("vspd", false) defaultConfigFilename = "vspd.conf" @@ -38,7 +39,7 @@ type config struct { LogLevel string `long:"loglevel" ini-name:"loglevel" description:"Logging level." choice:"trace" choice:"debug" choice:"info" choice:"warn" choice:"error" choice:"critical"` Network string `long:"network" ini-name:"network" description:"Decred network to use." choice:"testnet" choice:"mainnet" choice:"simnet"` FeeXPub string `long:"feexpub" ini-name:"feexpub" description:"Cold wallet xpub used for collecting fees."` - VSPFee float64 `long:"vspfee" ini-name:"vspfee" description:"Fee percentage charged for VSP use. eg. 0.01 (1%), 0.05 (5%)."` + VSPFee float64 `long:"vspfee" ini-name:"vspfee" description:"Fee percentage charged for VSP use. eg. 2.0 (2%), 0.5 (0.5%)."` HomeDir string `long:"homedir" ini-name:"homedir" no-ini:"true" description:"Path to application home directory. Used for storing VSP database and logs."` ConfigFile string `long:"configfile" ini-name:"configfile" no-ini:"true" description:"Path to configuration file."` DcrdHost string `long:"dcrdhost" ini-name:"dcrdhost" description:"The ip:port to establish a JSON-RPC connection with dcrd. Should be the same host where vspd is running."` @@ -255,6 +256,11 @@ func loadConfig() (*config, error) { return nil, errors.New("minimum backupinterval is 30 seconds") } + // Ensure the fee percentage is valid per txrules. + if !txrules.ValidPoolFeeRate(cfg.VSPFee) { + return nil, errors.New("invalid vspfee - should be greater than 0.01 and less than 100.0 ") + } + // Ensure the support email address is set. if cfg.SupportEmail == "" { return nil, errors.New("the supportemail option is not set") diff --git a/docs/api.md b/docs/api.md index 9def105..aa76a5b 100644 --- a/docs/api.md +++ b/docs/api.md @@ -33,7 +33,7 @@ will result in an error. { "timestamp":1590599436, "pubkey":"SjAmrAqH7LScCUwM1qo5O6Cu7aKhrM1ORszgZwD7HmU=", - "feepercentage":0.05, + "feepercentage":3.0, "vspclosed":false, "network":"testnet3" } diff --git a/webapi/templates/homepage.html b/webapi/templates/homepage.html index f2cd992..84b10ce 100644 --- a/webapi/templates/homepage.html +++ b/webapi/templates/homepage.html @@ -44,7 +44,7 @@ - +
Total tickets:{{ .TotalTickets }}
Fee confirmed tickets:{{ .FeeConfirmedTickets }}
VSP Fee:{{ .VSPFee }}
VSP Fee:{{ .VSPFee }}% of vote reward
Network:{{ .Network }}
Support:{{ .SupportEmail }}
Pubkey:{{ printf "%x" .PubKey }}