mirror of
https://github.com/aljazceru/lnd-manageJ.git
synced 2026-01-24 08:24:20 +01:00
get waiting-close channels
This commit is contained in:
@@ -8,8 +8,10 @@ import de.cotto.lndmanagej.model.ForceClosingChannel;
|
||||
import de.cotto.lndmanagej.model.LocalChannel;
|
||||
import de.cotto.lndmanagej.model.LocalOpenChannel;
|
||||
import de.cotto.lndmanagej.model.Pubkey;
|
||||
import de.cotto.lndmanagej.model.WaitingCloseChannel;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
@@ -21,6 +23,7 @@ public class ChannelService {
|
||||
private final LoadingCache<Object, Set<LocalOpenChannel>> channelsCache;
|
||||
private final LoadingCache<Object, Set<ClosedChannel>> closedChannelsCache;
|
||||
private final LoadingCache<Object, Set<ForceClosingChannel>> forceClosingChannelsCache;
|
||||
private final LoadingCache<Object, Set<WaitingCloseChannel>> waitingCloseChannelsCache;
|
||||
|
||||
public ChannelService(GrpcChannels grpcChannels) {
|
||||
channelsCache = new CacheBuilder()
|
||||
@@ -32,6 +35,9 @@ public class ChannelService {
|
||||
forceClosingChannelsCache = new CacheBuilder()
|
||||
.withExpiryMinutes(CACHE_EXPIRY_MINUTES)
|
||||
.build(grpcChannels::getForceClosingChannels);
|
||||
waitingCloseChannelsCache = new CacheBuilder()
|
||||
.withExpiryMinutes(CACHE_EXPIRY_MINUTES)
|
||||
.build(grpcChannels::getWaitingCloseChannels);
|
||||
}
|
||||
|
||||
public Set<LocalOpenChannel> getOpenChannels() {
|
||||
@@ -46,6 +52,10 @@ public class ChannelService {
|
||||
return forceClosingChannelsCache.getUnchecked("");
|
||||
}
|
||||
|
||||
public Set<WaitingCloseChannel> getWaitingCloseChannels() {
|
||||
return waitingCloseChannelsCache.getUnchecked("");
|
||||
}
|
||||
|
||||
public Set<LocalOpenChannel> getOpenChannelsWith(Pubkey peer) {
|
||||
return getOpenChannels().stream()
|
||||
.filter(c -> peer.equals(c.getRemotePubkey()))
|
||||
@@ -53,13 +63,13 @@ public class ChannelService {
|
||||
}
|
||||
|
||||
public Set<LocalChannel> getAllChannelsWith(Pubkey pubkey) {
|
||||
Stream<LocalOpenChannel> openChannels = getOpenChannelsWith(pubkey).stream();
|
||||
Stream<ForceClosingChannel> forceClosingChannels = getForceClosingChannels().stream()
|
||||
.filter(c -> c.getRemotePubkey().equals(pubkey));
|
||||
Stream<ClosedChannel> closedChannels = getClosedChannels().stream()
|
||||
.filter(c -> c.getRemotePubkey().equals(pubkey));
|
||||
return Stream.of(openChannels, closedChannels, forceClosingChannels).flatMap(s -> s)
|
||||
Set<LocalOpenChannel> openChannels = getOpenChannelsWith(pubkey);
|
||||
Set<WaitingCloseChannel> waitingCloseChannels = getWaitingCloseChannels();
|
||||
Set<ForceClosingChannel> forceClosingChannels = getForceClosingChannels();
|
||||
Set<ClosedChannel> closedChannels = getClosedChannels();
|
||||
return Stream.of(openChannels, closedChannels, waitingCloseChannels, forceClosingChannels)
|
||||
.flatMap(Collection::stream)
|
||||
.filter(c -> c.getRemotePubkey().equals(pubkey))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user