download transactions for open channels in background

This commit is contained in:
Carsten Otto
2021-11-16 22:18:13 +01:00
parent f50d91251f
commit 8186a342fa
4 changed files with 132 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
package de.cotto.lndmanagej.service;
import de.cotto.lndmanagej.model.Channel;
import de.cotto.lndmanagej.model.ChannelPoint;
import de.cotto.lndmanagej.transactions.service.TransactionService;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import java.util.concurrent.TimeUnit;
@Component
public class TransactionBackgroundLoader {
private final ChannelService channelService;
private final TransactionService transactionService;
public TransactionBackgroundLoader(ChannelService channelService, TransactionService transactionService) {
this.channelService = channelService;
this.transactionService = transactionService;
}
@Scheduled(fixedDelay = 5, timeUnit = TimeUnit.MINUTES)
public void loadTransactionForOneChannel() {
channelService.getOpenChannels().stream()
.map(Channel::getChannelPoint)
.map(ChannelPoint::getTransactionHash)
.filter(transactionService::isUnknown)
.findAny()
.ifPresent(transactionService::getTransaction);
}
}