Skip to content

Commit

Permalink
Validate VSP configs on startup.
Browse files Browse the repository at this point in the history
  • Loading branch information
jholdstock authored and jrick committed Apr 24, 2023
1 parent a19dcb4 commit 6cc8d05
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
19 changes: 19 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
23 changes: 4 additions & 19 deletions internal/rpc/jsonrpc/methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down

0 comments on commit 6cc8d05

Please sign in to comment.