move nexthop logic inside the interceptor

This commit is contained in:
Jesse de Wit
2023-06-15 10:50:20 +02:00
parent 898b69f9a7
commit 205d39d715
6 changed files with 87 additions and 39 deletions

View File

@@ -79,18 +79,18 @@ func (c *LndClient) GetInfo() (*lightning.GetInfoResult, error) {
}
func (c *LndClient) IsConnected(destination []byte) (bool, error) {
pubKey := hex.EncodeToString(destination)
pubkey := hex.EncodeToString(destination)
r, err := c.client.ListPeers(context.Background(), &lnrpc.ListPeersRequest{LatestError: true})
r, err := c.client.GetPeerConnected(context.Background(), &lnrpc.GetPeerConnectedRequest{
Pubkey: pubkey,
})
if err != nil {
log.Printf("LND: client.ListPeers() error: %v", err)
return false, fmt.Errorf("LND: client.ListPeers() error: %w", err)
log.Printf("LND: client.GetPeerConnected() error: %v", err)
return false, fmt.Errorf("LND: client.GetPeerConnected() error: %w", err)
}
for _, peer := range r.Peers {
if pubKey == peer.PubKey {
log.Printf("destination online: %x", destination)
return true, nil
}
if r.Connected {
log.Printf("LND: destination online: %x", destination)
return true, nil
}
log.Printf("LND: destination offline: %x", destination)
@@ -230,3 +230,20 @@ func (c *LndClient) getWaitingCloseChannels(nodeID string) ([]*lnrpc.PendingChan
}
return waitingCloseChannels, nil
}
func (c *LndClient) GetPeerId(scid *basetypes.ShortChannelID) ([]byte, error) {
scidu64 := uint64(*scid)
peer, err := c.client.GetPeerIdByScid(context.Background(), &lnrpc.GetPeerIdByScidRequest{
Scid: scidu64,
})
if err != nil {
return nil, err
}
if peer.PeerId == "" {
return nil, nil
}
peerid, _ := hex.DecodeString(peer.PeerId)
return peerid, nil
}