include waiting close and pending force closing channel IDs in node details

This commit is contained in:
Carsten Otto
2021-11-21 22:43:53 +01:00
parent 1428db620d
commit 1deff486a8
6 changed files with 84 additions and 13 deletions

View File

@@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@RestController
@@ -47,8 +48,10 @@ public class NodeController {
return new NodeDetailsDto(
pubkey,
node.alias(),
getChannelIdsForPubkey(pubkey),
getClosedChannelIdsForPubkey(pubkey),
toSortedList(channelService.getOpenChannelsWith(pubkey)),
toSortedList(channelService.getClosedChannelsWith(pubkey)),
toSortedList(channelService.getWaitingCloseChannelsFor(pubkey)),
toSortedList(channelService.getForceClosingChannelsFor(pubkey)),
node.online()
);
}
@@ -56,19 +59,12 @@ public class NodeController {
@GetMapping("/open-channels")
public ChannelsForNodeDto getOpenChannelIdsForPubkey(@PathVariable Pubkey pubkey) {
mark("getOpenChannelIdsForPubkey");
List<ChannelId> channels = getChannelIdsForPubkey(pubkey);
List<ChannelId> channels = toSortedList(channelService.getOpenChannelsWith(pubkey));
return new ChannelsForNodeDto(pubkey, channels);
}
private List<ChannelId> getChannelIdsForPubkey(Pubkey pubkey) {
return channelService.getOpenChannelsWith(pubkey).stream()
.map(Channel::getId)
.sorted()
.collect(Collectors.toList());
}
private List<ChannelId> getClosedChannelIdsForPubkey(Pubkey pubkey) {
return channelService.getClosedChannelsWith(pubkey).stream()
private List<ChannelId> toSortedList(Set<? extends Channel> channels) {
return channels.stream()
.map(Channel::getId)
.sorted()
.collect(Collectors.toList());

View File

@@ -12,6 +12,8 @@ public record NodeDetailsDto(
String alias,
List<ChannelId> channels,
List<ChannelId> closedChannels,
List<ChannelId> waitingCloseChannels,
List<ChannelId> pendingForceClosingChannels,
boolean online
) {
}

View File

@@ -101,6 +101,18 @@ public class ChannelService {
.collect(Collectors.toSet());
}
public Set<WaitingCloseChannel> getWaitingCloseChannelsFor(Pubkey peer) {
return getWaitingCloseChannels().stream()
.filter(c -> peer.equals(c.getRemotePubkey()))
.collect(Collectors.toSet());
}
public Set<ForceClosingChannel> getForceClosingChannelsFor(Pubkey peer) {
return getForceClosingChannels().stream()
.filter(c -> peer.equals(c.getRemotePubkey()))
.collect(Collectors.toSet());
}
public Set<LocalChannel> getAllChannelsWith(Pubkey peer) {
return getAllLocalChannels()
.filter(c -> peer.equals(c.getRemotePubkey()))