mirror of
https://github.com/aljazceru/lnd-manageJ.git
synced 2026-01-24 08:24:20 +01:00
get close costs via controller
This commit is contained in:
@@ -28,4 +28,11 @@ public class OnChainCostsController {
|
||||
.orElseThrow(() -> new CostException("Unable to get open costs for channel with ID " + channelId));
|
||||
}
|
||||
|
||||
@GetMapping("/channel/{channelId}/close-costs")
|
||||
public long getCloseCostsForChannel(@PathVariable ChannelId channelId) throws CostException {
|
||||
metrics.mark(MetricRegistry.name(getClass(), "getCloseCostsForChannel"));
|
||||
return onChainCostService.getCloseCosts(channelId).map(Coins::satoshis)
|
||||
.orElseThrow(() -> new CostException("Unable to get close costs for channel with ID " + channelId));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -51,6 +51,12 @@ public class ChannelService {
|
||||
return closedChannelsCache.getUnchecked("");
|
||||
}
|
||||
|
||||
public Optional<ClosedChannel> getClosedChannel(ChannelId channelId) {
|
||||
return getClosedChannels().stream()
|
||||
.filter(c -> channelId.equals(c.getId()))
|
||||
.findFirst();
|
||||
}
|
||||
|
||||
public Set<ForceClosingChannel> getForceClosingChannels() {
|
||||
return forceClosingChannelsCache.getUnchecked("");
|
||||
}
|
||||
|
||||
@@ -43,6 +43,10 @@ public class OnChainCostService {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
public Optional<Coins> getCloseCosts(ChannelId channelId) {
|
||||
return channelService.getClosedChannel(channelId).flatMap(this::getCloseCosts);
|
||||
}
|
||||
|
||||
public Optional<Coins> getCloseCosts(ClosedChannel closedChannel) {
|
||||
if (closedChannel.getOpenInitiator().equals(OpenInitiator.LOCAL)) {
|
||||
return transactionService.getTransaction(closedChannel.getCloseTransactionHash())
|
||||
|
||||
Reference in New Issue
Block a user