diff --git a/main.go b/main.go index 2e3380b..849c580 100644 --- a/main.go +++ b/main.go @@ -6,7 +6,6 @@ import ( "fmt" "os" "sync" - "time" "github.com/decred/vspd/background" "github.com/decred/vspd/database" @@ -14,10 +13,6 @@ import ( "github.com/decred/vspd/webapi" ) -const ( - defaultFeeAddressExpiration = 1 * time.Hour -) - func main() { // Create a context that is cancelled when a shutdown request is received // through an interrupt signal. @@ -89,11 +84,10 @@ func run(ctx context.Context) error { // Create and start webapi server. apiCfg := webapi.Config{ - VSPFee: cfg.VSPFee, - NetParams: cfg.netParams.Params, - FeeAddressExpiration: defaultFeeAddressExpiration, - SupportEmail: cfg.SupportEmail, - VspClosed: cfg.VspClosed, + VSPFee: cfg.VSPFee, + NetParams: cfg.netParams.Params, + SupportEmail: cfg.SupportEmail, + VspClosed: cfg.VspClosed, } err = webapi.Start(ctx, shutdownRequestChannel, &shutdownWg, cfg.Listen, db, dcrd, wallets, cfg.WebServerDebug, apiCfg) diff --git a/webapi/getfeeaddress.go b/webapi/getfeeaddress.go index e813751..eb28924 100644 --- a/webapi/getfeeaddress.go +++ b/webapi/getfeeaddress.go @@ -123,7 +123,7 @@ func feeAddress(c *gin.Context) { sendErrorResponse("fee error", http.StatusInternalServerError, c) return } - ticket.FeeExpiration = now.Add(cfg.FeeAddressExpiration).Unix() + ticket.FeeExpiration = now.Add(feeAddressExpiration).Unix() ticket.FeeAmount = newFee.ToCoin() err = db.UpdateTicket(ticket) @@ -162,7 +162,7 @@ func feeAddress(c *gin.Context) { } now := time.Now() - expire := now.Add(cfg.FeeAddressExpiration).Unix() + expire := now.Add(feeAddressExpiration).Unix() confirmed := rawTicket.Confirmations >= requiredConfs diff --git a/webapi/webapi.go b/webapi/webapi.go index 056a6f5..235e9c2 100644 --- a/webapi/webapi.go +++ b/webapi/webapi.go @@ -19,12 +19,11 @@ import ( ) type Config struct { - VSPFee float64 - NetParams *chaincfg.Params - FeeAccountName string - FeeAddressExpiration time.Duration - SupportEmail string - VspClosed bool + VSPFee float64 + NetParams *chaincfg.Params + FeeAccountName string + SupportEmail string + VspClosed bool } const ( @@ -33,6 +32,9 @@ const ( // requiredConfs is the number of confirmations required to consider a // ticket purchase or a fee transaction to be final. requiredConfs = 6 + // feeAddressExpiration is the length of time a fee returned by /feeaddress + // remains valid. After this time, a new fee must be requested. + feeAddressExpiration = 1 * time.Hour ) var cfg Config