get close costs via controller

This commit is contained in:
Carsten Otto
2021-11-19 13:02:08 +01:00
parent d63d2c0604
commit 1e397c926c
7 changed files with 74 additions and 9 deletions

View File

@@ -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));
}
}

View File

@@ -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("");
}

View File

@@ -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())