Close RPC connection if server doesnt meet reqs
This commit is contained in:
parent
4139f25670
commit
c308b8a9a6
@ -58,16 +58,19 @@ func (d *DcrdConnect) Client(ctx context.Context, netParams *chaincfg.Params) (*
|
|||||||
var verMap map[string]dcrdtypes.VersionResult
|
var verMap map[string]dcrdtypes.VersionResult
|
||||||
err = c.Call(ctx, "version", &verMap)
|
err = c.Call(ctx, "version", &verMap)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
d.Close()
|
||||||
return nil, fmt.Errorf("dcrd version check failed: %v", err)
|
return nil, fmt.Errorf("dcrd version check failed: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
ver, exists := verMap["dcrdjsonrpcapi"]
|
ver, exists := verMap["dcrdjsonrpcapi"]
|
||||||
if !exists {
|
if !exists {
|
||||||
|
d.Close()
|
||||||
return nil, fmt.Errorf("dcrd version response missing 'dcrdjsonrpcapi'")
|
return nil, fmt.Errorf("dcrd version response missing 'dcrdjsonrpcapi'")
|
||||||
}
|
}
|
||||||
|
|
||||||
sVer := semver{ver.Major, ver.Minor, ver.Patch}
|
sVer := semver{ver.Major, ver.Minor, ver.Patch}
|
||||||
if !semverCompatible(requiredDcrdVersion, sVer) {
|
if !semverCompatible(requiredDcrdVersion, sVer) {
|
||||||
|
d.Close()
|
||||||
return nil, fmt.Errorf("dcrd has incompatible JSON-RPC version: got %s, expected %s",
|
return nil, fmt.Errorf("dcrd has incompatible JSON-RPC version: got %s, expected %s",
|
||||||
sVer, requiredDcrdVersion)
|
sVer, requiredDcrdVersion)
|
||||||
}
|
}
|
||||||
@ -76,9 +79,11 @@ func (d *DcrdConnect) Client(ctx context.Context, netParams *chaincfg.Params) (*
|
|||||||
var netID wire.CurrencyNet
|
var netID wire.CurrencyNet
|
||||||
err = c.Call(ctx, "getcurrentnet", &netID)
|
err = c.Call(ctx, "getcurrentnet", &netID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
d.Close()
|
||||||
return nil, fmt.Errorf("dcrd getcurrentnet check failed: %v", err)
|
return nil, fmt.Errorf("dcrd getcurrentnet check failed: %v", err)
|
||||||
}
|
}
|
||||||
if netID != netParams.Net {
|
if netID != netParams.Net {
|
||||||
|
d.Close()
|
||||||
return nil, fmt.Errorf("dcrd running on %s, expected %s", netID, netParams.Net)
|
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
|
var info dcrdtypes.InfoChainResult
|
||||||
err = c.Call(ctx, "getinfo", &info)
|
err = c.Call(ctx, "getinfo", &info)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
d.Close()
|
||||||
return nil, fmt.Errorf("dcrd getinfo check failed: %v", err)
|
return nil, fmt.Errorf("dcrd getinfo check failed: %v", err)
|
||||||
}
|
}
|
||||||
if !info.TxIndex {
|
if !info.TxIndex {
|
||||||
|
d.Close()
|
||||||
return nil, errors.New("dcrd does not have transaction index enabled (--txindex)")
|
return nil, errors.New("dcrd does not have transaction index enabled (--txindex)")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -68,6 +68,7 @@ func (w *WalletConnect) Clients(ctx context.Context, netParams *chaincfg.Params)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("dcrwallet.Version error (wallet=%s): %v", c.String(), err)
|
log.Errorf("dcrwallet.Version error (wallet=%s): %v", c.String(), err)
|
||||||
failedConnections = append(failedConnections, connect.addr)
|
failedConnections = append(failedConnections, connect.addr)
|
||||||
|
connect.Close()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,6 +77,7 @@ func (w *WalletConnect) Clients(ctx context.Context, netParams *chaincfg.Params)
|
|||||||
log.Errorf("dcrwallet.Version response missing 'dcrwalletjsonrpcapi' (wallet=%s)",
|
log.Errorf("dcrwallet.Version response missing 'dcrwalletjsonrpcapi' (wallet=%s)",
|
||||||
c.String())
|
c.String())
|
||||||
failedConnections = append(failedConnections, connect.addr)
|
failedConnections = append(failedConnections, connect.addr)
|
||||||
|
connect.Close()
|
||||||
continue
|
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",
|
log.Errorf("dcrwallet has incompatible JSON-RPC version (wallet=%s): got %s, expected %s",
|
||||||
c.String(), sVer, requiredWalletVersion)
|
c.String(), sVer, requiredWalletVersion)
|
||||||
failedConnections = append(failedConnections, connect.addr)
|
failedConnections = append(failedConnections, connect.addr)
|
||||||
|
connect.Close()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -93,12 +96,14 @@ func (w *WalletConnect) Clients(ctx context.Context, netParams *chaincfg.Params)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("dcrwallet.GetCurrentNet error (wallet=%s): %v", c.String(), err)
|
log.Errorf("dcrwallet.GetCurrentNet error (wallet=%s): %v", c.String(), err)
|
||||||
failedConnections = append(failedConnections, connect.addr)
|
failedConnections = append(failedConnections, connect.addr)
|
||||||
|
connect.Close()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if netID != netParams.Net {
|
if netID != netParams.Net {
|
||||||
log.Errorf("dcrwallet on wrong network (wallet=%s): running on %s, expected %s",
|
log.Errorf("dcrwallet on wrong network (wallet=%s): running on %s, expected %s",
|
||||||
c.String(), netID, netParams.Net)
|
c.String(), netID, netParams.Net)
|
||||||
failedConnections = append(failedConnections, connect.addr)
|
failedConnections = append(failedConnections, connect.addr)
|
||||||
|
connect.Close()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,6 +113,7 @@ func (w *WalletConnect) Clients(ctx context.Context, netParams *chaincfg.Params)
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("dcrwallet.WalletInfo error (wallet=%s): %v", c.String(), err)
|
log.Errorf("dcrwallet.WalletInfo error (wallet=%s): %v", c.String(), err)
|
||||||
failedConnections = append(failedConnections, connect.addr)
|
failedConnections = append(failedConnections, connect.addr)
|
||||||
|
connect.Close()
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user