Return string for failed rpc connections

This commit is contained in:
jholdstock 2020-06-30 10:48:03 +01:00 committed by David Hill
parent 7f969c6db5
commit c5485a28ec
3 changed files with 13 additions and 13 deletions

View File

@ -159,9 +159,9 @@ func blockConnected() {
log.Errorf("%s: Could not connect to any wallets", funcName)
return
}
if failedConnections > 0 {
if len(failedConnections) > 0 {
log.Errorf("%s: Failed to connect to %d wallet(s), proceeding with only %d",
funcName, failedConnections, len(walletClients))
funcName, len(failedConnections), len(walletClients))
}
for _, ticket := range unconfirmedFees {

View File

@ -42,16 +42,16 @@ func (w *WalletConnect) Close() {
// Clients loops over each wallet and tries to establish a connection. It
// increments a count of failed connections if a connection cannot be
// established, or if the wallet is misconfigured.
func (w *WalletConnect) Clients(ctx context.Context, netParams *chaincfg.Params) ([]*WalletRPC, int) {
func (w *WalletConnect) Clients(ctx context.Context, netParams *chaincfg.Params) ([]*WalletRPC, []string) {
walletClients := make([]*WalletRPC, 0)
failedConnections := 0
failedConnections := make([]string, 0)
for _, connect := range []*client(*w) {
c, newConnection, err := connect.dial(ctx)
if err != nil {
log.Errorf("dcrwallet connection error: %v", err)
failedConnections++
failedConnections = append(failedConnections, connect.addr)
continue
}
@ -67,20 +67,20 @@ func (w *WalletConnect) Clients(ctx context.Context, netParams *chaincfg.Params)
err = c.Call(ctx, "version", &verMap)
if err != nil {
log.Errorf("version check on dcrwallet '%s' failed: %v", c.String(), err)
failedConnections++
failedConnections = append(failedConnections, connect.addr)
continue
}
walletVersion, exists := verMap["dcrwalletjsonrpcapi"]
if !exists {
log.Errorf("version response on dcrwallet '%s' missing 'dcrwalletjsonrpcapi'",
c.String())
failedConnections++
failedConnections = append(failedConnections, connect.addr)
continue
}
if walletVersion.VersionString != requiredWalletVersion {
log.Errorf("dcrwallet '%s' has wrong RPC version: got %s, expected %s",
c.String(), walletVersion.VersionString, requiredWalletVersion)
failedConnections++
failedConnections = append(failedConnections, connect.addr)
continue
}
@ -89,12 +89,12 @@ func (w *WalletConnect) Clients(ctx context.Context, netParams *chaincfg.Params)
err = c.Call(ctx, "getcurrentnet", &netID)
if err != nil {
log.Errorf("getcurrentnet check on dcrwallet '%s' failed: %v", c.String(), err)
failedConnections++
failedConnections = append(failedConnections, connect.addr)
continue
}
if netID != netParams.Net {
log.Errorf("dcrwallet '%s' running on %s, expected %s", c.String(), netID, netParams.Net)
failedConnections++
failedConnections = append(failedConnections, connect.addr)
continue
}
@ -103,7 +103,7 @@ func (w *WalletConnect) Clients(ctx context.Context, netParams *chaincfg.Params)
walletInfo, err := walletRPC.WalletInfo()
if err != nil {
log.Errorf("walletinfo check on dcrwallet '%s' failed: %v", c.String(), err)
failedConnections++
failedConnections = append(failedConnections, connect.addr)
continue
}

View File

@ -100,9 +100,9 @@ func withWalletClients(wallets rpc.WalletConnect) gin.HandlerFunc {
sendError(errInternalError, c)
return
}
if failedConnections > 0 {
if len(failedConnections) > 0 {
log.Errorf("Failed to connect to %d wallet(s), proceeding with only %d",
failedConnections, len(clients))
len(failedConnections), len(clients))
}
c.Set("WalletClients", clients)
}