add ChannelService

This commit is contained in:
Carsten Otto
2021-11-12 09:22:20 +01:00
parent bf18847a69
commit 70e7683fcb
5 changed files with 77 additions and 25 deletions

View File

@@ -0,0 +1,24 @@
package de.cotto.lndmanagej.service;
import de.cotto.lndmanagej.grpc.GrpcChannels;
import de.cotto.lndmanagej.model.Channel;
import de.cotto.lndmanagej.model.Node;
import org.springframework.stereotype.Component;
import java.util.Set;
import java.util.stream.Collectors;
@Component
public class ChannelService {
private final GrpcChannels grpcChannels;
public ChannelService(GrpcChannels grpcChannels) {
this.grpcChannels = grpcChannels;
}
public Set<Channel> getOpenChannelsWith(Node node) {
return grpcChannels.getChannels().stream()
.filter(c -> c.getNodes().contains(node))
.collect(Collectors.toSet());
}
}

View File

@@ -1,6 +1,5 @@
package de.cotto.lndmanagej.service;
import de.cotto.lndmanagej.grpc.GrpcChannels;
import de.cotto.lndmanagej.grpc.GrpcNodeInfo;
import de.cotto.lndmanagej.model.Channel;
import de.cotto.lndmanagej.model.ChannelId;
@@ -14,17 +13,16 @@ import java.util.stream.Collectors;
@Component
public class NodeService {
private final GrpcNodeInfo grpcNodeInfo;
private final GrpcChannels grpcChannels;
private final ChannelService channelService;
public NodeService(GrpcNodeInfo grpcNodeInfo, GrpcChannels grpcChannels) {
public NodeService(GrpcNodeInfo grpcNodeInfo, ChannelService channelService) {
this.grpcNodeInfo = grpcNodeInfo;
this.grpcChannels = grpcChannels;
this.channelService = channelService;
}
public List<ChannelId> getOpenChannelIds(Pubkey pubkey) {
Node node = getNode(pubkey);
return grpcChannels.getChannels().stream()
.filter(c -> c.getNodes().contains(node))
return channelService.getOpenChannelsWith(node).stream()
.map(Channel::getId)
.sorted()
.collect(Collectors.toList());