Add vspclosedmsg config.

If vspclosed is set to true, the provided message will be displayed on the webpage and returned by the status API endpoint.
This commit is contained in:
Jamie Holdstock 2021-06-08 17:00:08 +08:00 committed by Jamie Holdstock
parent 4db50a4439
commit d1a838bf7f
9 changed files with 26 additions and 5 deletions

View File

@ -62,6 +62,7 @@ type config struct {
SupportEmail string `long:"supportemail" ini-name:"supportemail" description:"Email address for users in need of support."` SupportEmail string `long:"supportemail" ini-name:"supportemail" description:"Email address for users in need of support."`
BackupInterval time.Duration `long:"backupinterval" ini-name:"backupinterval" description:"Time period between automatic database backups. Valid time units are {s,m,h}. Minimum 30 seconds."` BackupInterval time.Duration `long:"backupinterval" ini-name:"backupinterval" description:"Time period between automatic database backups. Valid time units are {s,m,h}. Minimum 30 seconds."`
VspClosed bool `long:"vspclosed" ini-name:"vspclosed" description:"Closed prevents the VSP from accepting new tickets."` VspClosed bool `long:"vspclosed" ini-name:"vspclosed" description:"Closed prevents the VSP from accepting new tickets."`
VspClosedMsg string `long:"vspclosedmsg" ini-name:"vspclosedmsg" description:"A short message displayed on the webpage and returned by the status API endpoint if vspdclosed is true."`
AdminPass string `long:"adminpass" ini-name:"adminpass" description:"Password for accessing admin page."` AdminPass string `long:"adminpass" ini-name:"adminpass" description:"Password for accessing admin page."`
Designation string `long:"designation" ini-name:"designation" description:"Short name for the VSP. Customizes the logo in the top toolbar."` Designation string `long:"designation" ini-name:"designation" description:"Short name for the VSP. Customizes the logo in the top toolbar."`
@ -292,6 +293,11 @@ func loadConfig() (*config, error) {
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")
} }
// If VSP is not closed, ignore any provided closure message.
if !cfg.VspClosed {
cfg.VspClosedMsg = ""
}
// Ensure the support email address is set. // Ensure the support email address is set.
if cfg.SupportEmail == "" { if cfg.SupportEmail == "" {
return nil, errors.New("the supportemail option is not set") return nil, errors.New("the supportemail option is not set")
@ -409,7 +415,7 @@ func loadConfig() (*config, error) {
// If database already exists, return error. // If database already exists, return error.
if fileExists(cfg.dbPath) { if fileExists(cfg.dbPath) {
return nil, fmt.Errorf("database already initialized at %s, "+ return nil, fmt.Errorf("database already initialized at %s, "+
"--feexpub option is not needed.", cfg.dbPath) "--feexpub option is not needed", cfg.dbPath)
} }
// Ensure provided value is a valid key for the selected network. // Ensure provided value is a valid key for the selected network.
@ -431,7 +437,7 @@ func loadConfig() (*config, error) {
// If database does not exist, return error. // If database does not exist, return error.
if !fileExists(cfg.dbPath) { if !fileExists(cfg.dbPath) {
return nil, fmt.Errorf("no database exists in %s. Run vspd with the"+ return nil, fmt.Errorf("no database exists in %s. Run vspd with the"+
" --feexpub option to initialize one.", dataDir) " --feexpub option to initialize one", dataDir)
} }
} }

View File

@ -49,6 +49,7 @@ when a VSP is closed will result in an error.
"pubkey":"SjAmrAqH7LScCUwM1qo5O6Cu7aKhrM1ORszgZwD7HmU=", "pubkey":"SjAmrAqH7LScCUwM1qo5O6Cu7aKhrM1ORszgZwD7HmU=",
"feepercentage":3.0, "feepercentage":3.0,
"vspclosed":false, "vspclosed":false,
"vspclosedmsg": "",
"network":"testnet3", "network":"testnet3",
"vspdversion":"1.0.0-pre", "vspdversion":"1.0.0-pre",
"voting":10, "voting":10,

View File

@ -151,6 +151,7 @@ webserverdebug = false
supportemail = example@test.com supportemail = example@test.com
backupinterval = 3m0s backupinterval = 3m0s
vspclosed = false vspclosed = false
vspclosedmsg = Your tickets are no longer welcome here. Please go away.
adminpass=12345 adminpass=12345
designation = harness designation = harness
EOF EOF

View File

@ -90,6 +90,7 @@ func run(ctx context.Context) error {
BlockExplorerURL: cfg.netParams.BlockExplorerURL, BlockExplorerURL: cfg.netParams.BlockExplorerURL,
SupportEmail: cfg.SupportEmail, SupportEmail: cfg.SupportEmail,
VspClosed: cfg.VspClosed, VspClosed: cfg.VspClosed,
VspClosedMsg: cfg.VspClosedMsg,
AdminPass: cfg.AdminPass, AdminPass: cfg.AdminPass,
Debug: cfg.WebServerDebug, Debug: cfg.WebServerDebug,
Designation: cfg.Designation, Designation: cfg.Designation,

View File

@ -30,6 +30,7 @@ type vspStats struct {
UpdateTime string UpdateTime string
SupportEmail string SupportEmail string
VspClosed bool VspClosed bool
VspClosedMsg string
Debug bool Debug bool
Designation string Designation string
BlockHeight uint32 BlockHeight uint32
@ -61,6 +62,7 @@ func initVSPStats() {
Network: cfg.NetParams.Name, Network: cfg.NetParams.Name,
SupportEmail: cfg.SupportEmail, SupportEmail: cfg.SupportEmail,
VspClosed: cfg.VspClosed, VspClosed: cfg.VspClosed,
VspClosedMsg: cfg.VspClosedMsg,
Debug: cfg.Debug, Debug: cfg.Debug,
Designation: cfg.Designation, Designation: cfg.Designation,
VspdVersion: cfg.VspdVersion, VspdVersion: cfg.VspdVersion,

View File

@ -5,9 +5,16 @@
{{ if .VspStats.VspClosed }} {{ if .VspStats.VspClosed }}
<div class="alert alert-danger"> <div class="alert alert-danger">
<h4 class="alert-heading">This Voting Service Provider is closed</h4> <h4 class="alert-heading mb-3">
A closed VSP will still vote on tickets with already paid fees, but will not accept new any tickets. This Voting Service Provider is closed
Visit <a href="https://decred.org/vsp/" class="alert-link" target="_blank" rel="noopener noreferrer">decred.org</a> to find a new VSP. </h4>
<p>
{{ .VspStats.VspClosedMsg }}
</p>
<p>
A closed VSP will still vote on tickets with already paid fees, but will not accept new any tickets.
Visit <a href="https://decred.org/vsp/" class="alert-link" target="_blank" rel="noopener noreferrer">decred.org</a> to find a new VSP.
</p>
</div> </div>
{{ end }} {{ end }}

View File

@ -10,6 +10,7 @@ type vspInfoResponse struct {
PubKey []byte `json:"pubkey"` PubKey []byte `json:"pubkey"`
FeePercentage float64 `json:"feepercentage"` FeePercentage float64 `json:"feepercentage"`
VspClosed bool `json:"vspclosed"` VspClosed bool `json:"vspclosed"`
VspClosedMsg string `json:"vspclosedmsg"`
Network string `json:"network"` Network string `json:"network"`
VspdVersion string `json:"vspdversion"` VspdVersion string `json:"vspdversion"`
Voting int64 `json:"voting"` Voting int64 `json:"voting"`

View File

@ -21,6 +21,7 @@ func vspInfo(c *gin.Context) {
FeePercentage: cfg.VSPFee, FeePercentage: cfg.VSPFee,
Network: cfg.NetParams.Name, Network: cfg.NetParams.Name,
VspClosed: cfg.VspClosed, VspClosed: cfg.VspClosed,
VspClosedMsg: cfg.VspClosedMsg,
VspdVersion: version.String(), VspdVersion: version.String(),
Voting: cachedStats.Voting, Voting: cachedStats.Voting,
Voted: cachedStats.Voted, Voted: cachedStats.Voted,

View File

@ -31,6 +31,7 @@ type Config struct {
FeeAccountName string FeeAccountName string
SupportEmail string SupportEmail string
VspClosed bool VspClosed bool
VspClosedMsg string
AdminPass string AdminPass string
Debug bool Debug bool
Designation string Designation string