mirror of
https://github.com/aljazceru/lnd-manageJ.git
synced 2026-01-24 08:24:20 +01:00
load more transaction details in background
This commit is contained in:
@@ -3,7 +3,7 @@ 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.ClosedChannel;
|
||||
import de.cotto.lndmanagej.model.CoopClosedChannel;
|
||||
import de.cotto.lndmanagej.model.ForceClosingChannel;
|
||||
import de.cotto.lndmanagej.model.LocalChannel;
|
||||
import de.cotto.lndmanagej.model.LocalOpenChannel;
|
||||
@@ -21,7 +21,7 @@ public class ChannelService {
|
||||
private static final int CACHE_EXPIRY_MINUTES = 1;
|
||||
|
||||
private final LoadingCache<Object, Set<LocalOpenChannel>> channelsCache;
|
||||
private final LoadingCache<Object, Set<ClosedChannel>> closedChannelsCache;
|
||||
private final LoadingCache<Object, Set<CoopClosedChannel>> closedChannelsCache;
|
||||
private final LoadingCache<Object, Set<ForceClosingChannel>> forceClosingChannelsCache;
|
||||
private final LoadingCache<Object, Set<WaitingCloseChannel>> waitingCloseChannelsCache;
|
||||
|
||||
@@ -44,7 +44,7 @@ public class ChannelService {
|
||||
return channelsCache.getUnchecked("");
|
||||
}
|
||||
|
||||
public Set<ClosedChannel> getClosedChannels() {
|
||||
public Set<CoopClosedChannel> getClosedChannels() {
|
||||
return closedChannelsCache.getUnchecked("");
|
||||
}
|
||||
|
||||
@@ -66,8 +66,8 @@ public class ChannelService {
|
||||
Set<LocalOpenChannel> openChannels = getOpenChannelsWith(pubkey);
|
||||
Set<WaitingCloseChannel> waitingCloseChannels = getWaitingCloseChannels();
|
||||
Set<ForceClosingChannel> forceClosingChannels = getForceClosingChannels();
|
||||
Set<ClosedChannel> closedChannels = getClosedChannels();
|
||||
return Stream.of(openChannels, closedChannels, waitingCloseChannels, forceClosingChannels)
|
||||
Set<CoopClosedChannel> coopClosedChannels = getClosedChannels();
|
||||
return Stream.of(openChannels, coopClosedChannels, waitingCloseChannels, forceClosingChannels)
|
||||
.flatMap(Collection::stream)
|
||||
.filter(c -> c.getRemotePubkey().equals(pubkey))
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
@@ -2,10 +2,14 @@ package de.cotto.lndmanagej.service;
|
||||
|
||||
import de.cotto.lndmanagej.model.Channel;
|
||||
import de.cotto.lndmanagej.model.ChannelPoint;
|
||||
import de.cotto.lndmanagej.model.ClosedChannel;
|
||||
import de.cotto.lndmanagej.transactions.service.TransactionService;
|
||||
import org.springframework.scheduling.annotation.Scheduled;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.MINUTES;
|
||||
|
||||
@Component
|
||||
@@ -20,11 +24,34 @@ public class TransactionBackgroundLoader {
|
||||
|
||||
@Scheduled(fixedDelay = 5, timeUnit = MINUTES)
|
||||
public void loadTransactionForOneChannel() {
|
||||
channelService.getOpenChannels().stream()
|
||||
.map(Channel::getChannelPoint)
|
||||
.map(ChannelPoint::getTransactionHash)
|
||||
getTransactionHashes()
|
||||
.filter(transactionService::isUnknown)
|
||||
.findAny()
|
||||
.ifPresent(transactionService::getTransaction);
|
||||
}
|
||||
|
||||
private Stream<String> getTransactionHashes() {
|
||||
Stream<String> openTransactionHashes = getOpenTransactionHashes();
|
||||
Stream<String> closeTransactionHashes = getCloseTransactionHashes();
|
||||
return Stream.concat(openTransactionHashes, closeTransactionHashes);
|
||||
}
|
||||
|
||||
private Stream<String> getOpenTransactionHashes() {
|
||||
return Stream.of(
|
||||
channelService.getOpenChannels(),
|
||||
channelService.getClosedChannels(),
|
||||
channelService.getForceClosingChannels(),
|
||||
channelService.getWaitingCloseChannels()
|
||||
)
|
||||
.flatMap(Collection::stream)
|
||||
.map(Channel::getChannelPoint)
|
||||
.map(ChannelPoint::getTransactionHash);
|
||||
}
|
||||
|
||||
private Stream<String> getCloseTransactionHashes() {
|
||||
return Stream.of(channelService.getClosedChannels(), channelService.getForceClosingChannels())
|
||||
.flatMap(Collection::stream)
|
||||
.map(ClosedChannel::getCloseTransactionHash);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user