mirror of
https://github.com/aljazceru/lnd-manageJ.git
synced 2026-01-24 08:24:20 +01:00
include balance and onchain costs in channel details
This commit is contained in:
@@ -3,12 +3,17 @@ package de.cotto.lndmanagej.controller;
|
||||
import com.codahale.metrics.MetricRegistry;
|
||||
import de.cotto.lndmanagej.controller.dto.ChannelDetailsDto;
|
||||
import de.cotto.lndmanagej.controller.dto.ObjectMapperConfiguration;
|
||||
import de.cotto.lndmanagej.controller.dto.OnChainCostsDto;
|
||||
import de.cotto.lndmanagej.metrics.Metrics;
|
||||
import de.cotto.lndmanagej.model.BalanceInformation;
|
||||
import de.cotto.lndmanagej.model.ChannelId;
|
||||
import de.cotto.lndmanagej.model.Coins;
|
||||
import de.cotto.lndmanagej.model.LocalChannel;
|
||||
import de.cotto.lndmanagej.model.Pubkey;
|
||||
import de.cotto.lndmanagej.service.BalanceService;
|
||||
import de.cotto.lndmanagej.service.ChannelService;
|
||||
import de.cotto.lndmanagej.service.NodeService;
|
||||
import de.cotto.lndmanagej.service.OnChainCostService;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
@@ -22,10 +27,20 @@ public class ChannelDetailsController {
|
||||
private final ChannelService channelService;
|
||||
private final NodeService nodeService;
|
||||
private final Metrics metrics;
|
||||
private final BalanceService balanceService;
|
||||
private final OnChainCostService onChainCostService;
|
||||
|
||||
public ChannelDetailsController(ChannelService channelService, NodeService nodeService, Metrics metrics) {
|
||||
public ChannelDetailsController(
|
||||
ChannelService channelService,
|
||||
NodeService nodeService,
|
||||
BalanceService balanceService,
|
||||
OnChainCostService onChainCostService,
|
||||
Metrics metrics
|
||||
) {
|
||||
this.channelService = channelService;
|
||||
this.nodeService = nodeService;
|
||||
this.balanceService = balanceService;
|
||||
this.onChainCostService = onChainCostService;
|
||||
this.metrics = metrics;
|
||||
}
|
||||
|
||||
@@ -38,7 +53,22 @@ public class ChannelDetailsController {
|
||||
}
|
||||
Pubkey remotePubkey = localChannel.getRemotePubkey();
|
||||
String remoteAlias = nodeService.getAlias(remotePubkey);
|
||||
boolean privateChannel = localChannel.isPrivateChannel();
|
||||
return new ChannelDetailsDto(localChannel.getId(), remotePubkey, remoteAlias, privateChannel);
|
||||
return new ChannelDetailsDto(
|
||||
localChannel,
|
||||
remoteAlias,
|
||||
getBalanceInformation(channelId),
|
||||
getOnChainCosts(channelId)
|
||||
);
|
||||
}
|
||||
|
||||
private BalanceInformation getBalanceInformation(ChannelId channelId) {
|
||||
return balanceService.getBalanceInformation(channelId)
|
||||
.orElse(BalanceInformation.EMPTY);
|
||||
}
|
||||
|
||||
private OnChainCostsDto getOnChainCosts(ChannelId channelId) {
|
||||
Coins openCosts = onChainCostService.getOpenCosts(channelId).orElse(Coins.NONE);
|
||||
Coins closeCosts = onChainCostService.getCloseCosts(channelId).orElse(Coins.NONE);
|
||||
return new OnChainCostsDto(openCosts, closeCosts);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package de.cotto.lndmanagej.controller.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import de.cotto.lndmanagej.model.BalanceInformation;
|
||||
import de.cotto.lndmanagej.model.ChannelId;
|
||||
import de.cotto.lndmanagej.model.LocalChannel;
|
||||
import de.cotto.lndmanagej.model.Pubkey;
|
||||
|
||||
public record ChannelDetailsDto(
|
||||
@@ -10,16 +12,25 @@ public record ChannelDetailsDto(
|
||||
String channelIdCompactLnd,
|
||||
Pubkey remotePubkey,
|
||||
String remoteAlias,
|
||||
@JsonProperty("private") boolean privateChannel
|
||||
@JsonProperty("private") boolean privateChannel,
|
||||
BalanceInformationDto balance,
|
||||
OnChainCostsDto onChainCosts
|
||||
) {
|
||||
public ChannelDetailsDto(ChannelId channelId, Pubkey remotePubkey, String remoteAlias, boolean privateChannel) {
|
||||
public ChannelDetailsDto(
|
||||
LocalChannel localChannel,
|
||||
String remoteAlias,
|
||||
BalanceInformation balanceInformation,
|
||||
OnChainCostsDto onChainCosts
|
||||
) {
|
||||
this(
|
||||
channelId,
|
||||
channelId.getCompactForm(),
|
||||
channelId.getCompactFormLnd(),
|
||||
remotePubkey,
|
||||
localChannel.getId(),
|
||||
localChannel.getId().getCompactForm(),
|
||||
localChannel.getId().getCompactFormLnd(),
|
||||
localChannel.getRemotePubkey(),
|
||||
remoteAlias,
|
||||
privateChannel
|
||||
localChannel.isPrivateChannel(),
|
||||
BalanceInformationDto.createFrom(balanceInformation),
|
||||
onChainCosts
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ public class BalanceService {
|
||||
.reduce(BalanceInformation.EMPTY, BalanceInformation::add);
|
||||
}
|
||||
|
||||
private Optional<BalanceInformation> getBalanceInformation(ChannelId channelId) {
|
||||
public Optional<BalanceInformation> getBalanceInformation(ChannelId channelId) {
|
||||
return grpcChannels.getChannel(channelId)
|
||||
.map(LocalOpenChannel::getBalanceInformation);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user