diff --git a/rpc/dcrd.go b/rpc/dcrd.go index ba598ea..49f4474 100644 --- a/rpc/dcrd.go +++ b/rpc/dcrd.go @@ -58,16 +58,19 @@ func (d *DcrdConnect) Client(ctx context.Context, netParams *chaincfg.Params) (* var verMap map[string]dcrdtypes.VersionResult err = c.Call(ctx, "version", &verMap) if err != nil { + d.Close() return nil, fmt.Errorf("dcrd version check failed: %v", err) } ver, exists := verMap["dcrdjsonrpcapi"] if !exists { + d.Close() return nil, fmt.Errorf("dcrd version response missing 'dcrdjsonrpcapi'") } sVer := semver{ver.Major, ver.Minor, ver.Patch} if !semverCompatible(requiredDcrdVersion, sVer) { + d.Close() return nil, fmt.Errorf("dcrd has incompatible JSON-RPC version: got %s, expected %s", sVer, requiredDcrdVersion) } @@ -76,9 +79,11 @@ func (d *DcrdConnect) Client(ctx context.Context, netParams *chaincfg.Params) (* var netID wire.CurrencyNet err = c.Call(ctx, "getcurrentnet", &netID) if err != nil { + d.Close() return nil, fmt.Errorf("dcrd getcurrentnet check failed: %v", err) } if netID != netParams.Net { + d.Close() return nil, fmt.Errorf("dcrd running on %s, expected %s", netID, netParams.Net) } @@ -86,9 +91,11 @@ func (d *DcrdConnect) Client(ctx context.Context, netParams *chaincfg.Params) (* var info dcrdtypes.InfoChainResult err = c.Call(ctx, "getinfo", &info) if err != nil { + d.Close() return nil, fmt.Errorf("dcrd getinfo check failed: %v", err) } if !info.TxIndex { + d.Close() return nil, errors.New("dcrd does not have transaction index enabled (--txindex)") } diff --git a/rpc/dcrwallet.go b/rpc/dcrwallet.go index 07c9399..b5de45e 100644 --- a/rpc/dcrwallet.go +++ b/rpc/dcrwallet.go @@ -68,6 +68,7 @@ func (w *WalletConnect) Clients(ctx context.Context, netParams *chaincfg.Params) if err != nil { log.Errorf("dcrwallet.Version error (wallet=%s): %v", c.String(), err) failedConnections = append(failedConnections, connect.addr) + connect.Close() continue } @@ -76,6 +77,7 @@ func (w *WalletConnect) Clients(ctx context.Context, netParams *chaincfg.Params) log.Errorf("dcrwallet.Version response missing 'dcrwalletjsonrpcapi' (wallet=%s)", c.String()) failedConnections = append(failedConnections, connect.addr) + connect.Close() continue } @@ -84,6 +86,7 @@ func (w *WalletConnect) Clients(ctx context.Context, netParams *chaincfg.Params) log.Errorf("dcrwallet has incompatible JSON-RPC version (wallet=%s): got %s, expected %s", c.String(), sVer, requiredWalletVersion) failedConnections = append(failedConnections, connect.addr) + connect.Close() continue } @@ -93,12 +96,14 @@ func (w *WalletConnect) Clients(ctx context.Context, netParams *chaincfg.Params) if err != nil { log.Errorf("dcrwallet.GetCurrentNet error (wallet=%s): %v", c.String(), err) failedConnections = append(failedConnections, connect.addr) + connect.Close() continue } if netID != netParams.Net { log.Errorf("dcrwallet on wrong network (wallet=%s): running on %s, expected %s", c.String(), netID, netParams.Net) failedConnections = append(failedConnections, connect.addr) + connect.Close() continue } @@ -108,6 +113,7 @@ func (w *WalletConnect) Clients(ctx context.Context, netParams *chaincfg.Params) if err != nil { log.Errorf("dcrwallet.WalletInfo error (wallet=%s): %v", c.String(), err) failedConnections = append(failedConnections, connect.addr) + connect.Close() continue }