mirror of
https://github.com/aljazceru/lnd-manageJ.git
synced 2026-01-28 10:24:24 +01:00
get all channels for peer
This commit is contained in:
@@ -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");
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user