mirror of
https://github.com/aljazceru/lnd-manageJ.git
synced 2026-01-21 15:04:22 +01:00
get closed channels
This commit is contained in:
@@ -3,7 +3,8 @@ package de.cotto.lndmanagej.service;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import de.cotto.lndmanagej.caching.CacheBuilder;
|
||||
import de.cotto.lndmanagej.grpc.GrpcChannels;
|
||||
import de.cotto.lndmanagej.model.LocalChannel;
|
||||
import de.cotto.lndmanagej.model.ClosedChannel;
|
||||
import de.cotto.lndmanagej.model.LocalOpenChannel;
|
||||
import de.cotto.lndmanagej.model.Pubkey;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -12,26 +13,31 @@ import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
public class ChannelService {
|
||||
private static final int MAXIMUM_SIZE = 500;
|
||||
private static final int CACHE_EXPIRY_MINUTES = 1;
|
||||
|
||||
private final LoadingCache<Object, Set<LocalChannel>> channelsCache;
|
||||
private final LoadingCache<Object, Set<LocalOpenChannel>> channelsCache;
|
||||
private final LoadingCache<Object, Set<ClosedChannel>> closedChannelsCache;
|
||||
|
||||
public ChannelService(GrpcChannels grpcChannels) {
|
||||
channelsCache = new CacheBuilder()
|
||||
.withExpiryMinutes(CACHE_EXPIRY_MINUTES)
|
||||
.withMaximumSize(MAXIMUM_SIZE)
|
||||
.build(grpcChannels::getChannels);
|
||||
closedChannelsCache = new CacheBuilder()
|
||||
.withExpiryMinutes(CACHE_EXPIRY_MINUTES)
|
||||
.build(grpcChannels::getClosedChannels);
|
||||
}
|
||||
|
||||
public Set<LocalChannel> getOpenChannels() {
|
||||
public Set<LocalOpenChannel> getOpenChannels() {
|
||||
return channelsCache.getUnchecked("");
|
||||
}
|
||||
|
||||
public Set<LocalChannel> getOpenChannelsWith(Pubkey peer) {
|
||||
public Set<ClosedChannel> getClosedChannels() {
|
||||
return closedChannelsCache.getUnchecked("");
|
||||
}
|
||||
|
||||
public Set<LocalOpenChannel> getOpenChannelsWith(Pubkey peer) {
|
||||
return getOpenChannels().stream()
|
||||
.filter(c -> peer.equals(c.getRemotePubkey()))
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user