mirror of
https://github.com/aljazceru/lnd-manageJ.git
synced 2026-01-22 15:35:10 +01:00
compute channel details in service
lots of refactoring, changes API
This commit is contained in:
@@ -11,59 +11,43 @@ import de.cotto.lndmanagej.controller.dto.PoliciesDto;
|
||||
import de.cotto.lndmanagej.model.BalanceInformation;
|
||||
import de.cotto.lndmanagej.model.ChannelId;
|
||||
import de.cotto.lndmanagej.model.ClosedChannel;
|
||||
import de.cotto.lndmanagej.model.FeeReport;
|
||||
import de.cotto.lndmanagej.model.LocalChannel;
|
||||
import de.cotto.lndmanagej.model.OpenCloseStatus;
|
||||
import de.cotto.lndmanagej.model.Policies;
|
||||
import de.cotto.lndmanagej.model.Pubkey;
|
||||
import de.cotto.lndmanagej.service.BalanceService;
|
||||
import de.cotto.lndmanagej.service.ChannelDetailsService;
|
||||
import de.cotto.lndmanagej.service.ChannelService;
|
||||
import de.cotto.lndmanagej.service.FeeService;
|
||||
import de.cotto.lndmanagej.service.NodeService;
|
||||
import de.cotto.lndmanagej.service.OffChainCostService;
|
||||
import de.cotto.lndmanagej.service.OnChainCostService;
|
||||
import de.cotto.lndmanagej.service.PolicyService;
|
||||
import de.cotto.lndmanagej.service.RebalanceService;
|
||||
import org.springframework.context.annotation.Import;
|
||||
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;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
@RestController
|
||||
@Import(ObjectMapperConfiguration.class)
|
||||
@SuppressWarnings("PMD.ExcessiveImports")
|
||||
@RequestMapping("/api/channel/{channelId}")
|
||||
public class ChannelController {
|
||||
private final ChannelService channelService;
|
||||
private final NodeService nodeService;
|
||||
private final BalanceService balanceService;
|
||||
private final OnChainCostService onChainCostService;
|
||||
private final PolicyService policyService;
|
||||
private final FeeService feeService;
|
||||
private final OffChainCostService offChainCostService;
|
||||
private final RebalanceService rebalanceService;
|
||||
private final ChannelDetailsService channelDetailsService;
|
||||
|
||||
public ChannelController(
|
||||
ChannelService channelService,
|
||||
NodeService nodeService,
|
||||
BalanceService balanceService,
|
||||
OnChainCostService onChainCostService,
|
||||
PolicyService policyService,
|
||||
FeeService feeService,
|
||||
OffChainCostService offChainCostService,
|
||||
RebalanceService rebalanceService
|
||||
ChannelDetailsService channelDetailsService
|
||||
) {
|
||||
this.channelService = channelService;
|
||||
this.nodeService = nodeService;
|
||||
this.balanceService = balanceService;
|
||||
this.onChainCostService = onChainCostService;
|
||||
this.policyService = policyService;
|
||||
this.feeService = feeService;
|
||||
this.offChainCostService = offChainCostService;
|
||||
this.rebalanceService = rebalanceService;
|
||||
this.channelDetailsService = channelDetailsService;
|
||||
}
|
||||
|
||||
@Timed
|
||||
@@ -73,8 +57,7 @@ public class ChannelController {
|
||||
if (localChannel == null) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
ClosedChannelDetailsDto closeDetailsForChannel = getCloseDetailsForChannel(localChannel);
|
||||
return new ChannelDto(localChannel, closeDetailsForChannel);
|
||||
return new ChannelDto(localChannel);
|
||||
}
|
||||
|
||||
@Timed
|
||||
@@ -84,20 +67,7 @@ public class ChannelController {
|
||||
if (localChannel == null) {
|
||||
throw new NotFoundException();
|
||||
}
|
||||
Pubkey remotePubkey = localChannel.getRemotePubkey();
|
||||
String remoteAlias = nodeService.getAlias(remotePubkey);
|
||||
return new ChannelDetailsDto(
|
||||
localChannel,
|
||||
remoteAlias,
|
||||
getBalanceInformation(channelId),
|
||||
onChainCostService.getOnChainCostsForChannelId(channelId),
|
||||
offChainCostService.getOffChainCostsForChannel(channelId),
|
||||
getPoliciesForChannel(localChannel),
|
||||
getCloseDetailsForChannel(localChannel),
|
||||
getFeeReportFromService(localChannel.getId()),
|
||||
rebalanceService.getRebalanceAmountFromChannel(localChannel.getId()),
|
||||
rebalanceService.getRebalanceAmountToChannel(localChannel.getId())
|
||||
);
|
||||
return ChannelDetailsDto.createFromModel(channelDetailsService.getDetails(localChannel));
|
||||
}
|
||||
|
||||
@Timed
|
||||
@@ -112,7 +82,10 @@ public class ChannelController {
|
||||
@GetMapping("/policies")
|
||||
public PoliciesDto getPolicies(@PathVariable ChannelId channelId) {
|
||||
LocalChannel localChannel = channelService.getLocalChannel(channelId).orElse(null);
|
||||
return getPoliciesForChannel(localChannel);
|
||||
if (localChannel == null || localChannel.getStatus().openCloseStatus() != OpenCloseStatus.OPEN) {
|
||||
return PoliciesDto.createFromModel(Policies.UNKNOWN);
|
||||
}
|
||||
return PoliciesDto.createFromModel(policyService.getPolicies(localChannel.getId()));
|
||||
}
|
||||
|
||||
@Timed
|
||||
@@ -128,27 +101,7 @@ public class ChannelController {
|
||||
@Timed
|
||||
@GetMapping("/fee-report")
|
||||
public FeeReportDto getFeeReport(@PathVariable ChannelId channelId) {
|
||||
return FeeReportDto.createFromModel(getFeeReportFromService(channelId));
|
||||
return FeeReportDto.createFromModel(feeService.getFeeReportForChannel(channelId));
|
||||
}
|
||||
|
||||
private FeeReport getFeeReportFromService(ChannelId channelId) {
|
||||
return feeService.getFeeReportForChannel(channelId);
|
||||
}
|
||||
|
||||
private PoliciesDto getPoliciesForChannel(@Nullable LocalChannel channel) {
|
||||
if (channel == null || channel.getStatus().openCloseStatus() != OpenCloseStatus.OPEN) {
|
||||
return PoliciesDto.EMPTY;
|
||||
}
|
||||
Policies policies = policyService.getPolicies(channel.getId());
|
||||
return PoliciesDto.createFromModel(policies);
|
||||
}
|
||||
|
||||
private BalanceInformation getBalanceInformation(ChannelId channelId) {
|
||||
return balanceService.getBalanceInformation(channelId)
|
||||
.orElse(BalanceInformation.EMPTY);
|
||||
}
|
||||
|
||||
private ClosedChannelDetailsDto getCloseDetailsForChannel(LocalChannel localChannel) {
|
||||
return ClosedChannelDetailsDto.createFromModel(localChannel);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,20 +6,16 @@ import de.cotto.lndmanagej.controller.dto.ChannelsForNodeDto;
|
||||
import de.cotto.lndmanagej.controller.dto.FeeReportDto;
|
||||
import de.cotto.lndmanagej.controller.dto.NodeDetailsDto;
|
||||
import de.cotto.lndmanagej.controller.dto.ObjectMapperConfiguration;
|
||||
import de.cotto.lndmanagej.controller.dto.OffChainCostsDto;
|
||||
import de.cotto.lndmanagej.controller.dto.OnChainCostsDto;
|
||||
import de.cotto.lndmanagej.model.BalanceInformation;
|
||||
import de.cotto.lndmanagej.model.Channel;
|
||||
import de.cotto.lndmanagej.model.ChannelId;
|
||||
import de.cotto.lndmanagej.model.Node;
|
||||
import de.cotto.lndmanagej.model.OffChainCosts;
|
||||
import de.cotto.lndmanagej.model.OnChainCosts;
|
||||
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.OffChainCostService;
|
||||
import de.cotto.lndmanagej.service.OnChainCostService;
|
||||
import de.cotto.lndmanagej.service.RebalanceService;
|
||||
import org.springframework.context.annotation.Import;
|
||||
@@ -38,7 +34,6 @@ public class NodeController {
|
||||
private final NodeService nodeService;
|
||||
private final ChannelService channelService;
|
||||
private final OnChainCostService onChainCostService;
|
||||
private final OffChainCostService offChainCostService;
|
||||
private final BalanceService balanceService;
|
||||
private final FeeService feeService;
|
||||
private final RebalanceService rebalanceService;
|
||||
@@ -47,7 +42,6 @@ public class NodeController {
|
||||
NodeService nodeService,
|
||||
ChannelService channelService,
|
||||
OnChainCostService onChainCostService,
|
||||
OffChainCostService offChainCostService,
|
||||
BalanceService balanceService,
|
||||
FeeService feeService,
|
||||
RebalanceService rebalanceService
|
||||
@@ -55,7 +49,6 @@ public class NodeController {
|
||||
this.nodeService = nodeService;
|
||||
this.channelService = channelService;
|
||||
this.onChainCostService = onChainCostService;
|
||||
this.offChainCostService = offChainCostService;
|
||||
this.balanceService = balanceService;
|
||||
this.feeService = feeService;
|
||||
this.rebalanceService = rebalanceService;
|
||||
@@ -72,7 +65,6 @@ public class NodeController {
|
||||
public NodeDetailsDto getDetails(@PathVariable Pubkey pubkey) {
|
||||
Node node = nodeService.getNode(pubkey);
|
||||
OnChainCosts onChainCosts = onChainCostService.getOnChainCostsForPeer(pubkey);
|
||||
OffChainCosts offChainCosts = offChainCostService.getOffChainCostsForPeer(pubkey);
|
||||
BalanceInformation balanceInformation = balanceService.getBalanceInformationForPeer(pubkey);
|
||||
return new NodeDetailsDto(
|
||||
pubkey,
|
||||
@@ -81,13 +73,11 @@ public class NodeController {
|
||||
toSortedList(channelService.getClosedChannelsWith(pubkey)),
|
||||
toSortedList(channelService.getWaitingCloseChannelsWith(pubkey)),
|
||||
toSortedList(channelService.getForceClosingChannelsWith(pubkey)),
|
||||
OnChainCostsDto.createFromModel(onChainCosts),
|
||||
OffChainCostsDto.createFromModel(offChainCosts),
|
||||
BalanceInformationDto.createFromModel(balanceInformation),
|
||||
onChainCosts,
|
||||
balanceInformation,
|
||||
node.online(),
|
||||
getFeeReportDto(pubkey),
|
||||
String.valueOf(rebalanceService.getRebalanceAmountFromPeer(pubkey).milliSatoshis()),
|
||||
String.valueOf(rebalanceService.getRebalanceAmountToPeer(pubkey).milliSatoshis())
|
||||
feeService.getFeeReportForPeer(pubkey),
|
||||
rebalanceService.getReportForPeer(pubkey)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -114,10 +104,6 @@ public class NodeController {
|
||||
@Timed
|
||||
@GetMapping("/fee-report")
|
||||
public FeeReportDto getFeeReport(@PathVariable Pubkey pubkey) {
|
||||
return getFeeReportDto(pubkey);
|
||||
}
|
||||
|
||||
private FeeReportDto getFeeReportDto(Pubkey pubkey) {
|
||||
return FeeReportDto.createFromModel(feeService.getFeeReportForPeer(pubkey));
|
||||
}
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ package de.cotto.lndmanagej.controller;
|
||||
import com.codahale.metrics.annotation.Timed;
|
||||
import de.cotto.lndmanagej.model.ChannelId;
|
||||
import de.cotto.lndmanagej.model.Pubkey;
|
||||
import de.cotto.lndmanagej.service.OffChainCostService;
|
||||
import de.cotto.lndmanagej.service.RebalanceService;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
@@ -13,59 +12,57 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@RestController
|
||||
@RequestMapping("/api/")
|
||||
public class RebalancesController {
|
||||
private final OffChainCostService offChainCostService;
|
||||
private final RebalanceService rebalanceService;
|
||||
|
||||
public RebalancesController(OffChainCostService offChainCostService, RebalanceService rebalanceService) {
|
||||
this.offChainCostService = offChainCostService;
|
||||
public RebalancesController(RebalanceService rebalanceService) {
|
||||
this.rebalanceService = rebalanceService;
|
||||
}
|
||||
|
||||
@Timed
|
||||
@GetMapping("/node/{pubkey}/rebalance-source-costs")
|
||||
public long getRebalanceSourceCostsForPeer(@PathVariable Pubkey pubkey) {
|
||||
return offChainCostService.getRebalanceSourceCostsForPeer(pubkey).milliSatoshis();
|
||||
return rebalanceService.getSourceCostsForPeer(pubkey).milliSatoshis();
|
||||
}
|
||||
|
||||
@Timed
|
||||
@GetMapping("/node/{pubkey}/rebalance-source-amount")
|
||||
public long getRebalanceSourceAmountForPeer(@PathVariable Pubkey pubkey) {
|
||||
return rebalanceService.getRebalanceAmountFromPeer(pubkey).milliSatoshis();
|
||||
return rebalanceService.getAmountFromPeer(pubkey).milliSatoshis();
|
||||
}
|
||||
|
||||
@Timed
|
||||
@GetMapping("/channel/{channelId}/rebalance-source-costs")
|
||||
public long getRebalanceSourceCostsForChannel(@PathVariable ChannelId channelId) {
|
||||
return offChainCostService.getRebalanceSourceCostsForChannel(channelId).milliSatoshis();
|
||||
return rebalanceService.getSourceCostsForChannel(channelId).milliSatoshis();
|
||||
}
|
||||
|
||||
@Timed
|
||||
@GetMapping("/channel/{channelId}/rebalance-source-amount")
|
||||
public long getRebalanceSourceAmountForChannel(@PathVariable ChannelId channelId) {
|
||||
return rebalanceService.getRebalanceAmountFromChannel(channelId).milliSatoshis();
|
||||
return rebalanceService.getAmountFromChannel(channelId).milliSatoshis();
|
||||
}
|
||||
|
||||
@Timed
|
||||
@GetMapping("/node/{pubkey}/rebalance-target-costs")
|
||||
public long getRebalanceTargetCostsForPeer(@PathVariable Pubkey pubkey) {
|
||||
return offChainCostService.getRebalanceTargetCostsForPeer(pubkey).milliSatoshis();
|
||||
return rebalanceService.getTargetCostsForPeer(pubkey).milliSatoshis();
|
||||
}
|
||||
|
||||
@Timed
|
||||
@GetMapping("/node/{pubkey}/rebalance-target-amount")
|
||||
public long getRebalanceTargetAmountForPeer(@PathVariable Pubkey pubkey) {
|
||||
return rebalanceService.getRebalanceAmountToPeer(pubkey).milliSatoshis();
|
||||
return rebalanceService.getAmountToPeer(pubkey).milliSatoshis();
|
||||
}
|
||||
|
||||
@Timed
|
||||
@GetMapping("/channel/{channelId}/rebalance-target-costs")
|
||||
public long getRebalanceTargetCostsForChannel(@PathVariable ChannelId channelId) {
|
||||
return offChainCostService.getRebalanceTargetCostsForChannel(channelId).milliSatoshis();
|
||||
return rebalanceService.getTargetCostsForChannel(channelId).milliSatoshis();
|
||||
}
|
||||
|
||||
@Timed
|
||||
@GetMapping("/channel/{channelId}/rebalance-target-amount")
|
||||
public long getRebalanceTargetAmountForChannel(@PathVariable ChannelId channelId) {
|
||||
return rebalanceService.getRebalanceAmountToChannel(channelId).milliSatoshis();
|
||||
return rebalanceService.getAmountToChannel(channelId).milliSatoshis();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,15 @@
|
||||
package de.cotto.lndmanagej.controller.dto;
|
||||
|
||||
import de.cotto.lndmanagej.model.BalanceInformation;
|
||||
import de.cotto.lndmanagej.model.ChannelDetails;
|
||||
import de.cotto.lndmanagej.model.ChannelPoint;
|
||||
import de.cotto.lndmanagej.model.Coins;
|
||||
import de.cotto.lndmanagej.model.FeeReport;
|
||||
import de.cotto.lndmanagej.model.LocalChannel;
|
||||
import de.cotto.lndmanagej.model.OffChainCosts;
|
||||
import de.cotto.lndmanagej.model.OnChainCosts;
|
||||
import de.cotto.lndmanagej.model.OpenInitiator;
|
||||
import de.cotto.lndmanagej.model.Policies;
|
||||
import de.cotto.lndmanagej.model.Pubkey;
|
||||
import de.cotto.lndmanagej.model.RebalanceReport;
|
||||
|
||||
public record ChannelDetailsDto(
|
||||
String channelIdShort,
|
||||
@@ -25,23 +26,19 @@ public record ChannelDetailsDto(
|
||||
ChannelStatusDto status,
|
||||
BalanceInformationDto balance,
|
||||
OnChainCostsDto onChainCosts,
|
||||
OffChainCostsDto offChainCosts,
|
||||
PoliciesDto policies,
|
||||
ClosedChannelDetailsDto closeDetails,
|
||||
FeeReportDto feeReport,
|
||||
String rebalanceSourceAmount,
|
||||
String rebalanceTargetAmount
|
||||
RebalanceReportDto rebalanceReport
|
||||
) {
|
||||
public ChannelDetailsDto(
|
||||
ChannelDto channelDto,
|
||||
String remoteAlias,
|
||||
BalanceInformation balanceInformation,
|
||||
OnChainCosts onChainCosts,
|
||||
OffChainCosts offChainCosts,
|
||||
PoliciesDto policies,
|
||||
Policies policies,
|
||||
FeeReport feeReport,
|
||||
Coins rebalanceSourceAmount,
|
||||
Coins rebalanceTargetAmount
|
||||
RebalanceReport rebalanceReport
|
||||
) {
|
||||
this(
|
||||
channelDto.channelIdShort(),
|
||||
@@ -58,38 +55,42 @@ public record ChannelDetailsDto(
|
||||
channelDto.status(),
|
||||
BalanceInformationDto.createFromModel(balanceInformation),
|
||||
OnChainCostsDto.createFromModel(onChainCosts),
|
||||
OffChainCostsDto.createFromModel(offChainCosts),
|
||||
policies,
|
||||
PoliciesDto.createFromModel(policies),
|
||||
channelDto.closeDetails(),
|
||||
FeeReportDto.createFromModel(feeReport),
|
||||
String.valueOf(rebalanceSourceAmount.milliSatoshis()),
|
||||
String.valueOf(rebalanceTargetAmount.milliSatoshis())
|
||||
RebalanceReportDto.createFromModel(rebalanceReport)
|
||||
);
|
||||
}
|
||||
|
||||
@SuppressWarnings("PMD.ExcessiveParameterList")
|
||||
public ChannelDetailsDto(
|
||||
LocalChannel localChannel,
|
||||
String remoteAlias,
|
||||
BalanceInformation balanceInformation,
|
||||
OnChainCosts onChainCosts,
|
||||
OffChainCosts offChainCosts,
|
||||
PoliciesDto policies,
|
||||
ClosedChannelDetailsDto closeDetails,
|
||||
Policies policies,
|
||||
FeeReport feeReport,
|
||||
Coins rebalanceSourceAmount,
|
||||
Coins rebalanceTargetAmount
|
||||
RebalanceReport rebalanceReport
|
||||
) {
|
||||
this(
|
||||
new ChannelDto(localChannel, closeDetails),
|
||||
new ChannelDto(localChannel),
|
||||
remoteAlias,
|
||||
balanceInformation,
|
||||
onChainCosts,
|
||||
offChainCosts,
|
||||
policies,
|
||||
feeReport,
|
||||
rebalanceSourceAmount,
|
||||
rebalanceTargetAmount
|
||||
rebalanceReport
|
||||
);
|
||||
}
|
||||
|
||||
public static ChannelDetailsDto createFromModel(ChannelDetails channelDetails) {
|
||||
return new ChannelDetailsDto(
|
||||
channelDetails.localChannel(),
|
||||
channelDetails.remoteAlias(),
|
||||
channelDetails.balanceInformation(),
|
||||
channelDetails.onChainCosts(),
|
||||
channelDetails.policies(),
|
||||
channelDetails.feeReport(),
|
||||
channelDetails.rebalanceReport()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ public record ChannelDto(
|
||||
OpenInitiator openInitiator,
|
||||
ClosedChannelDetailsDto closeDetails
|
||||
) {
|
||||
public ChannelDto(LocalChannel localChannel, ClosedChannelDetailsDto closeDetails) {
|
||||
public ChannelDto(LocalChannel localChannel) {
|
||||
this(
|
||||
String.valueOf(localChannel.getId().getShortChannelId()),
|
||||
localChannel.getId().getCompactForm(),
|
||||
@@ -32,7 +32,7 @@ public record ChannelDto(
|
||||
String.valueOf(localChannel.getTotalReceived().satoshis()),
|
||||
ChannelStatusDto.createFromModel(localChannel.getStatus()),
|
||||
localChannel.getOpenInitiator(),
|
||||
closeDetails
|
||||
ClosedChannelDetailsDto.createFromModel(localChannel)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,8 +2,12 @@ package de.cotto.lndmanagej.controller.dto;
|
||||
|
||||
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||
import de.cotto.lndmanagej.model.BalanceInformation;
|
||||
import de.cotto.lndmanagej.model.ChannelId;
|
||||
import de.cotto.lndmanagej.model.FeeReport;
|
||||
import de.cotto.lndmanagej.model.OnChainCosts;
|
||||
import de.cotto.lndmanagej.model.Pubkey;
|
||||
import de.cotto.lndmanagej.model.RebalanceReport;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -15,11 +19,37 @@ public record NodeDetailsDto(
|
||||
List<ChannelId> waitingCloseChannels,
|
||||
List<ChannelId> pendingForceClosingChannels,
|
||||
OnChainCostsDto onChainCosts,
|
||||
OffChainCostsDto offChainCosts,
|
||||
BalanceInformationDto balance,
|
||||
boolean online,
|
||||
FeeReportDto feeReport,
|
||||
String rebalanceSourceAmount,
|
||||
String rebalanceTargetAmount
|
||||
RebalanceReportDto rebalanceReport
|
||||
) {
|
||||
@SuppressWarnings("PMD.ExcessiveParameterList")
|
||||
public NodeDetailsDto(
|
||||
Pubkey pubkey,
|
||||
String alias,
|
||||
List<ChannelId> channels,
|
||||
List<ChannelId> closedChannels,
|
||||
List<ChannelId> waitingCloseChannels,
|
||||
List<ChannelId> pendingForceClosingChannels,
|
||||
OnChainCosts onChainCosts,
|
||||
BalanceInformation balanceInformation,
|
||||
boolean online,
|
||||
FeeReport feeReport,
|
||||
RebalanceReport rebalanceReport
|
||||
) {
|
||||
this(
|
||||
pubkey,
|
||||
alias,
|
||||
channels,
|
||||
closedChannels,
|
||||
waitingCloseChannels,
|
||||
pendingForceClosingChannels,
|
||||
OnChainCostsDto.createFromModel(onChainCosts),
|
||||
BalanceInformationDto.createFromModel(balanceInformation),
|
||||
online,
|
||||
FeeReportDto.createFromModel(feeReport),
|
||||
RebalanceReportDto.createFromModel(rebalanceReport)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +0,0 @@
|
||||
package de.cotto.lndmanagej.controller.dto;
|
||||
|
||||
import de.cotto.lndmanagej.model.Coins;
|
||||
import de.cotto.lndmanagej.model.OffChainCosts;
|
||||
|
||||
public record OffChainCostsDto(String rebalanceSource, String rebalanceTarget) {
|
||||
public OffChainCostsDto(Coins rebalanceSource, Coins rebalanceTarget) {
|
||||
this(
|
||||
String.valueOf(rebalanceSource.milliSatoshis()),
|
||||
String.valueOf(rebalanceTarget.milliSatoshis())
|
||||
);
|
||||
}
|
||||
|
||||
public static OffChainCostsDto createFromModel(OffChainCosts offChainCosts) {
|
||||
return new OffChainCostsDto(offChainCosts.rebalanceSource(), offChainCosts.rebalanceTarget());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,9 +6,6 @@ public record PoliciesDto(
|
||||
PolicyDto local,
|
||||
PolicyDto remote
|
||||
) {
|
||||
public static final PoliciesDto EMPTY =
|
||||
new PoliciesDto(PolicyDto.EMPTY, PolicyDto.EMPTY);
|
||||
|
||||
public static PoliciesDto createFromModel(Policies policies) {
|
||||
return new PoliciesDto(
|
||||
PolicyDto.createFromModel(policies.local()),
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
package de.cotto.lndmanagej.controller.dto;
|
||||
|
||||
import de.cotto.lndmanagej.model.Coins;
|
||||
import de.cotto.lndmanagej.model.RebalanceReport;
|
||||
|
||||
public record RebalanceReportDto(String sourceCosts, String sourceAmount, String targetCosts, String targetAmount) {
|
||||
public RebalanceReportDto(Coins sourceCost, Coins sourceAmount, Coins targetCost, Coins targetAmount) {
|
||||
this(
|
||||
toMilliSatoshisString(sourceCost),
|
||||
toMilliSatoshisString(sourceAmount),
|
||||
toMilliSatoshisString(targetCost),
|
||||
toMilliSatoshisString(targetAmount)
|
||||
);
|
||||
}
|
||||
|
||||
public static RebalanceReportDto createFromModel(RebalanceReport rebalanceReport) {
|
||||
return new RebalanceReportDto(
|
||||
rebalanceReport.sourceCost(),
|
||||
rebalanceReport.sourceAmount(),
|
||||
rebalanceReport.targetCost(),
|
||||
rebalanceReport.targetAmount()
|
||||
);
|
||||
}
|
||||
|
||||
private static String toMilliSatoshisString(Coins coins) {
|
||||
return String.valueOf(coins.milliSatoshis());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user