Move feeAddressExpiration into webapi package.
This commit is contained in:
parent
443db9a7b9
commit
0318eded95
14
main.go
14
main.go
@ -6,7 +6,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/decred/vspd/background"
|
"github.com/decred/vspd/background"
|
||||||
"github.com/decred/vspd/database"
|
"github.com/decred/vspd/database"
|
||||||
@ -14,10 +13,6 @@ import (
|
|||||||
"github.com/decred/vspd/webapi"
|
"github.com/decred/vspd/webapi"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
defaultFeeAddressExpiration = 1 * time.Hour
|
|
||||||
)
|
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Create a context that is cancelled when a shutdown request is received
|
// Create a context that is cancelled when a shutdown request is received
|
||||||
// through an interrupt signal.
|
// through an interrupt signal.
|
||||||
@ -89,11 +84,10 @@ func run(ctx context.Context) error {
|
|||||||
|
|
||||||
// Create and start webapi server.
|
// Create and start webapi server.
|
||||||
apiCfg := webapi.Config{
|
apiCfg := webapi.Config{
|
||||||
VSPFee: cfg.VSPFee,
|
VSPFee: cfg.VSPFee,
|
||||||
NetParams: cfg.netParams.Params,
|
NetParams: cfg.netParams.Params,
|
||||||
FeeAddressExpiration: defaultFeeAddressExpiration,
|
SupportEmail: cfg.SupportEmail,
|
||||||
SupportEmail: cfg.SupportEmail,
|
VspClosed: cfg.VspClosed,
|
||||||
VspClosed: cfg.VspClosed,
|
|
||||||
}
|
}
|
||||||
err = webapi.Start(ctx, shutdownRequestChannel, &shutdownWg, cfg.Listen, db,
|
err = webapi.Start(ctx, shutdownRequestChannel, &shutdownWg, cfg.Listen, db,
|
||||||
dcrd, wallets, cfg.WebServerDebug, apiCfg)
|
dcrd, wallets, cfg.WebServerDebug, apiCfg)
|
||||||
|
|||||||
@ -123,7 +123,7 @@ func feeAddress(c *gin.Context) {
|
|||||||
sendErrorResponse("fee error", http.StatusInternalServerError, c)
|
sendErrorResponse("fee error", http.StatusInternalServerError, c)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ticket.FeeExpiration = now.Add(cfg.FeeAddressExpiration).Unix()
|
ticket.FeeExpiration = now.Add(feeAddressExpiration).Unix()
|
||||||
ticket.FeeAmount = newFee.ToCoin()
|
ticket.FeeAmount = newFee.ToCoin()
|
||||||
|
|
||||||
err = db.UpdateTicket(ticket)
|
err = db.UpdateTicket(ticket)
|
||||||
@ -162,7 +162,7 @@ func feeAddress(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
now := time.Now()
|
now := time.Now()
|
||||||
expire := now.Add(cfg.FeeAddressExpiration).Unix()
|
expire := now.Add(feeAddressExpiration).Unix()
|
||||||
|
|
||||||
confirmed := rawTicket.Confirmations >= requiredConfs
|
confirmed := rawTicket.Confirmations >= requiredConfs
|
||||||
|
|
||||||
|
|||||||
@ -19,12 +19,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
VSPFee float64
|
VSPFee float64
|
||||||
NetParams *chaincfg.Params
|
NetParams *chaincfg.Params
|
||||||
FeeAccountName string
|
FeeAccountName string
|
||||||
FeeAddressExpiration time.Duration
|
SupportEmail string
|
||||||
SupportEmail string
|
VspClosed bool
|
||||||
VspClosed bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -33,6 +32,9 @@ const (
|
|||||||
// requiredConfs is the number of confirmations required to consider a
|
// requiredConfs is the number of confirmations required to consider a
|
||||||
// ticket purchase or a fee transaction to be final.
|
// ticket purchase or a fee transaction to be final.
|
||||||
requiredConfs = 6
|
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
|
var cfg Config
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user