mirror of
https://github.com/aljazceru/lnd-manageJ.git
synced 2026-01-22 15:35:10 +01:00
add basic fee report
This commit is contained in:
@@ -5,6 +5,7 @@ import de.cotto.lndmanagej.controller.dto.BalanceInformationDto;
|
||||
import de.cotto.lndmanagej.controller.dto.ChannelDetailsDto;
|
||||
import de.cotto.lndmanagej.controller.dto.ChannelDto;
|
||||
import de.cotto.lndmanagej.controller.dto.ClosedChannelDetailsDto;
|
||||
import de.cotto.lndmanagej.controller.dto.FeeReportDto;
|
||||
import de.cotto.lndmanagej.controller.dto.ObjectMapperConfiguration;
|
||||
import de.cotto.lndmanagej.controller.dto.OnChainCostsDto;
|
||||
import de.cotto.lndmanagej.controller.dto.PoliciesDto;
|
||||
@@ -19,6 +20,7 @@ import de.cotto.lndmanagej.model.Policies;
|
||||
import de.cotto.lndmanagej.model.Pubkey;
|
||||
import de.cotto.lndmanagej.service.BalanceService;
|
||||
import de.cotto.lndmanagej.service.ChannelService;
|
||||
import de.cotto.lndmanagej.service.FeeService;
|
||||
import de.cotto.lndmanagej.service.NodeService;
|
||||
import de.cotto.lndmanagej.service.OnChainCostService;
|
||||
import de.cotto.lndmanagej.service.PolicyService;
|
||||
@@ -31,8 +33,9 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/channel/{channelId}")
|
||||
@Import(ObjectMapperConfiguration.class)
|
||||
@SuppressWarnings("PMD.ExcessiveImports")
|
||||
@RequestMapping("/api/channel/{channelId}")
|
||||
public class ChannelController {
|
||||
private final ChannelService channelService;
|
||||
private final NodeService nodeService;
|
||||
@@ -40,6 +43,7 @@ public class ChannelController {
|
||||
private final BalanceService balanceService;
|
||||
private final OnChainCostService onChainCostService;
|
||||
private final PolicyService policyService;
|
||||
private final FeeService feeService;
|
||||
|
||||
public ChannelController(
|
||||
ChannelService channelService,
|
||||
@@ -47,14 +51,16 @@ public class ChannelController {
|
||||
BalanceService balanceService,
|
||||
OnChainCostService onChainCostService,
|
||||
PolicyService policyService,
|
||||
FeeService feeService,
|
||||
Metrics metrics
|
||||
) {
|
||||
this.channelService = channelService;
|
||||
this.nodeService = nodeService;
|
||||
this.balanceService = balanceService;
|
||||
this.onChainCostService = onChainCostService;
|
||||
this.metrics = metrics;
|
||||
this.policyService = policyService;
|
||||
this.feeService = feeService;
|
||||
this.metrics = metrics;
|
||||
}
|
||||
|
||||
@GetMapping("/")
|
||||
@@ -83,7 +89,8 @@ public class ChannelController {
|
||||
getBalanceInformation(channelId),
|
||||
getOnChainCosts(channelId),
|
||||
getPoliciesForChannel(localChannel),
|
||||
getCloseDetailsForChannel(localChannel)
|
||||
getCloseDetailsForChannel(localChannel),
|
||||
getFeeReportDto(localChannel.getId())
|
||||
);
|
||||
}
|
||||
|
||||
@@ -112,6 +119,17 @@ public class ChannelController {
|
||||
return new ClosedChannelDetailsDto(closedChannel.getCloseInitiator(), closedChannel.getCloseHeight());
|
||||
}
|
||||
|
||||
@GetMapping("/fee-report")
|
||||
public FeeReportDto getFeeReport(@PathVariable ChannelId channelId) {
|
||||
mark("getFeeReport");
|
||||
return getFeeReportDto(channelId);
|
||||
}
|
||||
|
||||
private FeeReportDto getFeeReportDto(ChannelId channelId) {
|
||||
Coins earned = feeService.getEarnedFeesForChannel(channelId);
|
||||
return new FeeReportDto(earned);
|
||||
}
|
||||
|
||||
private PoliciesDto getPoliciesForChannel(@Nullable LocalChannel channel) {
|
||||
if (channel == null || channel.getStatus().openCloseStatus() != OpenCloseStatus.OPEN) {
|
||||
return PoliciesDto.EMPTY;
|
||||
|
||||
@@ -22,14 +22,16 @@ public record ChannelDetailsDto(
|
||||
BalanceInformationDto balance,
|
||||
OnChainCostsDto onChainCosts,
|
||||
PoliciesDto policies,
|
||||
ClosedChannelDetailsDto closeDetails
|
||||
ClosedChannelDetailsDto closeDetails,
|
||||
FeeReportDto feeReport
|
||||
) {
|
||||
public ChannelDetailsDto(
|
||||
ChannelDto channelDto,
|
||||
String remoteAlias,
|
||||
BalanceInformation balanceInformation,
|
||||
OnChainCostsDto onChainCosts,
|
||||
PoliciesDto policies
|
||||
PoliciesDto policies,
|
||||
FeeReportDto feeReport
|
||||
) {
|
||||
this(
|
||||
channelDto.channelIdShort(),
|
||||
@@ -47,7 +49,8 @@ public record ChannelDetailsDto(
|
||||
BalanceInformationDto.createFrom(balanceInformation),
|
||||
onChainCosts,
|
||||
policies,
|
||||
channelDto.closeDetails()
|
||||
channelDto.closeDetails(),
|
||||
feeReport
|
||||
);
|
||||
}
|
||||
|
||||
@@ -57,14 +60,16 @@ public record ChannelDetailsDto(
|
||||
BalanceInformation balanceInformation,
|
||||
OnChainCostsDto onChainCosts,
|
||||
PoliciesDto policies,
|
||||
ClosedChannelDetailsDto closeDetails
|
||||
ClosedChannelDetailsDto closeDetails,
|
||||
FeeReportDto feeReport
|
||||
) {
|
||||
this(
|
||||
new ChannelDto(localChannel, closeDetails),
|
||||
remoteAlias,
|
||||
balanceInformation,
|
||||
onChainCosts,
|
||||
policies
|
||||
policies,
|
||||
feeReport
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
package de.cotto.lndmanagej.controller.dto;
|
||||
|
||||
import de.cotto.lndmanagej.model.Coins;
|
||||
|
||||
public record FeeReportDto(String earned) {
|
||||
public FeeReportDto(Coins earned) {
|
||||
this(String.valueOf(earned.milliSatoshis()));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user