mirror of
https://github.com/aljazceru/lnd-manageJ.git
synced 2026-01-30 19:24:29 +01:00
get channel IDs for channels with peer
This commit is contained in:
@@ -1,23 +1,34 @@
|
||||
package de.cotto.lndmanagej.controller;
|
||||
|
||||
import de.cotto.lndmanagej.grpc.GrpcNodeInfo;
|
||||
import de.cotto.lndmanagej.model.ChannelId;
|
||||
import de.cotto.lndmanagej.model.Pubkey;
|
||||
import de.cotto.lndmanagej.service.NodeService;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/node/")
|
||||
public class NodeController {
|
||||
private final GrpcNodeInfo grpcNodeInfo;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public NodeController(GrpcNodeInfo grpcNodeInfo) {
|
||||
this.grpcNodeInfo = grpcNodeInfo;
|
||||
@RestController
|
||||
@RequestMapping("/api/node/{pubkey}/")
|
||||
public class NodeController {
|
||||
private final NodeService nodeService;
|
||||
|
||||
public NodeController(NodeService nodeService) {
|
||||
this.nodeService = nodeService;
|
||||
}
|
||||
|
||||
@GetMapping("/{pubkey}/alias")
|
||||
@GetMapping("/alias")
|
||||
public String getAlias(@PathVariable Pubkey pubkey) {
|
||||
return grpcNodeInfo.getNode(pubkey).alias();
|
||||
return nodeService.getAlias(pubkey);
|
||||
}
|
||||
|
||||
@GetMapping("/open-channels")
|
||||
public List<Long> getOpenChannelIds(@PathVariable Pubkey pubkey) {
|
||||
return nodeService.getOpenChannelIds(pubkey).stream()
|
||||
.map(ChannelId::shortChannelId)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
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;
|
||||
import de.cotto.lndmanagej.model.Node;
|
||||
import de.cotto.lndmanagej.model.Pubkey;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Component
|
||||
public class NodeService {
|
||||
private final GrpcNodeInfo grpcNodeInfo;
|
||||
private final GrpcChannels grpcChannels;
|
||||
|
||||
public NodeService(GrpcNodeInfo grpcNodeInfo, GrpcChannels grpcChannels) {
|
||||
this.grpcNodeInfo = grpcNodeInfo;
|
||||
this.grpcChannels = grpcChannels;
|
||||
}
|
||||
|
||||
public List<ChannelId> getOpenChannelIds(Pubkey pubkey) {
|
||||
Node node = getNode(pubkey);
|
||||
return grpcChannels.getChannels().stream()
|
||||
.filter(c -> c.getNodes().contains(node))
|
||||
.map(Channel::getId)
|
||||
.sorted()
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public String getAlias(Pubkey pubkey) {
|
||||
return getNode(pubkey).alias();
|
||||
}
|
||||
|
||||
private Node getNode(Pubkey pubkey) {
|
||||
return grpcNodeInfo.getNode(pubkey);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user