diff --git a/config.go b/config.go index 9de4e8932..5b04010e0 100644 --- a/config.go +++ b/config.go @@ -974,6 +974,25 @@ func loadConfig(ctx context.Context) (*config, []string, error) { } } + // If either VSP pubkey or URL are specified, validate VSP options. + if cfg.VSPOpts.PubKey != "" || cfg.VSPOpts.URL != "" { + if cfg.VSPOpts.PubKey == "" { + err := errors.New("vsp pubkey can not be null") + fmt.Fprintln(os.Stderr, err) + return loadConfigError(err) + } + if cfg.VSPOpts.URL == "" { + err := errors.New("vsp URL can not be null") + fmt.Fprintln(os.Stderr, err) + return loadConfigError(err) + } + if cfg.VSPOpts.MaxFee.Amount == 0 { + err := errors.New("vsp max fee must be greater than zero") + fmt.Fprintln(os.Stderr, err) + return loadConfigError(err) + } + } + // Expand environment variable and leading ~ for filepaths. cfg.CAFile.Value = cleanAndExpandPath(cfg.CAFile.Value) cfg.RPCCert.Value = cleanAndExpandPath(cfg.RPCCert.Value) diff --git a/internal/rpc/jsonrpc/methods.go b/internal/rpc/jsonrpc/methods.go index b81f0be21..a5fd3e038 100644 --- a/internal/rpc/jsonrpc/methods.go +++ b/internal/rpc/jsonrpc/methods.go @@ -3424,29 +3424,14 @@ func (s *Server) purchaseTicket(ctx context.Context, icmd interface{}) (interfac } var vspClient *vsp.Client - if s.cfg.VSPHost != "" || s.cfg.VSPPubKey != "" { - vspHost := s.cfg.VSPHost - vspPubKey := s.cfg.VSPPubKey - vspMaxFee := s.cfg.VSPMaxFee - if vspPubKey == "" { - return nil, rpcErrorf(dcrjson.ErrRPCInvalidParameter, - "vsp pubkey can not be null") - } - if vspHost == "" { - return nil, rpcErrorf(dcrjson.ErrRPCInvalidParameter, - "vsp host can not be null") - } - if vspMaxFee == 0 { - return nil, rpcErrorf(dcrjson.ErrRPCInvalidParameter, - "vsp max fee must be greater than zero") - } + if s.cfg.VSPHost != "" { cfg := vsp.Config{ - URL: vspHost, - PubKey: vspPubKey, + URL: s.cfg.VSPHost, + PubKey: s.cfg.VSPPubKey, Dialer: s.cfg.Dial, Wallet: w, Policy: vsp.Policy{ - MaxFee: vspMaxFee, + MaxFee: s.cfg.VSPMaxFee, FeeAcct: account, ChangeAcct: changeAccount, },