From c37a7452f462529e07e78c8102a59fb6f1865657 Mon Sep 17 00:00:00 2001 From: Jesse de Wit Date: Fri, 23 Jun 2023 11:30:40 +0200 Subject: [PATCH] Improve cln IsConnected --- cln/cln_client.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/cln/cln_client.go b/cln/cln_client.go index c81674d8..6bb6bbb4 100644 --- a/cln/cln_client.go +++ b/cln/cln_client.go @@ -5,6 +5,7 @@ import ( "fmt" "log" "path/filepath" + "strings" "time" "github.com/breez/lspd/basetypes" @@ -59,17 +60,19 @@ func (c *ClnClient) GetInfo() (*lightning.GetInfoResult, error) { func (c *ClnClient) IsConnected(destination []byte) (bool, error) { pubKey := hex.EncodeToString(destination) - peers, err := c.client.ListPeers() + peer, err := c.client.GetPeer(pubKey) if err != nil { - log.Printf("CLN: client.ListPeers() error: %v", err) - return false, fmt.Errorf("CLN: client.ListPeers() error: %w", err) + if strings.Contains(err.Error(), "not found") { + return false, nil + } + + log.Printf("CLN: client.GetPeer(%v) error: %v", pubKey, err) + return false, fmt.Errorf("CLN: client.GetPeer(%v) error: %w", pubKey, err) } - for _, peer := range peers { - if pubKey == peer.Id && peer.Connected { - log.Printf("destination online: %x", destination) - return true, nil - } + if peer.Connected { + log.Printf("CLN: destination online: %x", destination) + return true, nil } log.Printf("CLN: destination offline: %x", destination)