compute sweep costs

This commit is contained in:
Carsten Otto
2021-12-10 16:23:05 +01:00
parent 3c0fca7d5c
commit df38fdf3e1
27 changed files with 311 additions and 46 deletions

View File

@@ -40,4 +40,10 @@ public class OnChainCostsController {
.orElseThrow(() -> new CostException("Unable to get close costs for channel with ID " + channelId));
}
@Timed
@GetMapping("/channel/{channelId}/sweep-costs")
public long getSweepCostsForChannel(@PathVariable ChannelId channelId) throws CostException {
return onChainCostService.getSweepCostsForChannelId(channelId).map(Coins::satoshis)
.orElseThrow(() -> new CostException("Unable to get sweep costs for channel with ID " + channelId));
}
}

View File

@@ -2,10 +2,15 @@ package de.cotto.lndmanagej.controller.dto;
import de.cotto.lndmanagej.model.OnChainCosts;
public record OnChainCostsDto(String openCosts, String closeCosts) {
public record OnChainCostsDto(String openCosts, String closeCosts, String sweepCosts) {
public static OnChainCostsDto createFromModel(OnChainCosts onChainCosts) {
long openSatoshi = onChainCosts.open().satoshis();
long closeSatoshi = onChainCosts.close().satoshis();
return new OnChainCostsDto(String.valueOf(openSatoshi), String.valueOf(closeSatoshi));
long sweepSatoshi = onChainCosts.sweep().satoshis();
return new OnChainCostsDto(
String.valueOf(openSatoshi),
String.valueOf(closeSatoshi),
String.valueOf(sweepSatoshi)
);
}
}