get all channels for peer

This commit is contained in:
Carsten Otto
2021-11-15 19:20:30 +01:00
parent 19e664ff35
commit 4d5ba9d2d8
10 changed files with 82 additions and 4 deletions

View File

@@ -63,6 +63,16 @@ public class LegacyController {
.collect(Collectors.joining(NEWLINE));
}
@GetMapping("/node/{pubkey}/all-channels")
public String getAllChannelIdsForPubkey(@PathVariable Pubkey pubkey) {
mark("getAllChannelIdsForPubkey");
return channelService.getAllChannelsWith(pubkey).stream()
.map(Channel::getId)
.sorted()
.map(ChannelId::toString)
.collect(Collectors.joining(NEWLINE));
}
@GetMapping("/open-channels")
public String getOpenChannelIds() {
mark("getOpenChannelIds");

View File

@@ -4,6 +4,7 @@ import com.google.common.cache.LoadingCache;
import de.cotto.lndmanagej.caching.CacheBuilder;
import de.cotto.lndmanagej.grpc.GrpcChannels;
import de.cotto.lndmanagej.model.ClosedChannel;
import de.cotto.lndmanagej.model.LocalChannel;
import de.cotto.lndmanagej.model.LocalOpenChannel;
import de.cotto.lndmanagej.model.Pubkey;
import de.cotto.lndmanagej.model.UnresolvedClosedChannel;
@@ -12,6 +13,7 @@ import org.springframework.stereotype.Component;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
@Component
public class ChannelService {
@@ -61,4 +63,12 @@ public class ChannelService {
.filter(c -> peer.equals(c.getRemotePubkey()))
.collect(Collectors.toSet());
}
public Set<LocalChannel> getAllChannelsWith(Pubkey pubkey) {
Stream<LocalOpenChannel> openChannels = getOpenChannelsWith(pubkey).stream();
Stream<ClosedChannel> closedChannels = getClosedChannels().stream()
.filter(c -> c.getRemotePubkey().equals(pubkey));
return Stream.concat(openChannels, closedChannels)
.collect(Collectors.toSet());
}
}