identify node by pubkey

This commit is contained in:
Carsten Otto
2021-11-12 09:41:17 +01:00
parent 9c2afa0abc
commit 3459f2ad8d
7 changed files with 41 additions and 22 deletions

View File

@@ -3,6 +3,7 @@ package de.cotto.lndmanagej.service;
import de.cotto.lndmanagej.grpc.GrpcChannels;
import de.cotto.lndmanagej.model.Channel;
import de.cotto.lndmanagej.model.Node;
import de.cotto.lndmanagej.model.Pubkey;
import org.springframework.stereotype.Component;
import java.util.Set;
@@ -16,9 +17,14 @@ public class ChannelService {
this.grpcChannels = grpcChannels;
}
public Set<Channel> getOpenChannelsWith(Node node) {
public Set<Channel> getOpenChannelsWith(Pubkey peer) {
Node peerNode = Node.forPubkey(peer);
return getOpenChannelsWith(peerNode);
}
public Set<Channel> getOpenChannelsWith(Node peer) {
return grpcChannels.getChannels().stream()
.filter(c -> c.getNodes().contains(node))
.filter(c -> c.getNodes().contains(peer))
.collect(Collectors.toSet());
}
}

View File

@@ -40,9 +40,8 @@ public class NodeService {
.build(loader);
}
public List<ChannelId> getOpenChannelIds(Pubkey pubkey) {
Node node = getNode(pubkey);
return channelService.getOpenChannelsWith(node).stream()
public List<ChannelId> getOpenChannelIds(Pubkey peer) {
return channelService.getOpenChannelsWith(peer).stream()
.map(Channel::getId)
.sorted()
.collect(Collectors.toList());