include closed channel IDs in node details

This commit is contained in:
Carsten Otto
2021-11-21 22:24:40 +01:00
parent e4dfd5911d
commit 1428db620d
6 changed files with 47 additions and 2 deletions

View File

@@ -44,7 +44,13 @@ public class NodeController {
public NodeDetailsDto getDetails(@PathVariable Pubkey pubkey) {
mark("getDetails");
Node node = nodeService.getNode(pubkey);
return new NodeDetailsDto(pubkey, node.alias(), getChannelIdsForPubkey(pubkey), node.online());
return new NodeDetailsDto(
pubkey,
node.alias(),
getChannelIdsForPubkey(pubkey),
getClosedChannelIdsForPubkey(pubkey),
node.online()
);
}
@GetMapping("/open-channels")
@@ -61,6 +67,13 @@ public class NodeController {
.collect(Collectors.toList());
}
private List<ChannelId> getClosedChannelIdsForPubkey(Pubkey pubkey) {
return channelService.getClosedChannelsWith(pubkey).stream()
.map(Channel::getId)
.sorted()
.collect(Collectors.toList());
}
private void mark(String getDetails) {
metrics.mark(MetricRegistry.name(getClass(), getDetails));
}

View File

@@ -11,6 +11,7 @@ public record NodeDetailsDto(
@JsonSerialize(using = ToStringSerializer.class) Pubkey node,
String alias,
List<ChannelId> channels,
List<ChannelId> closedChannels,
boolean online
) {
}

View File

@@ -95,6 +95,12 @@ public class ChannelService {
.collect(Collectors.toSet());
}
public Set<ClosedChannel> getClosedChannelsWith(Pubkey peer) {
return getClosedChannels().stream()
.filter(c -> peer.equals(c.getRemotePubkey()))
.collect(Collectors.toSet());
}
public Set<LocalChannel> getAllChannelsWith(Pubkey peer) {
return getAllLocalChannels()
.filter(c -> peer.equals(c.getRemotePubkey()))