add endpoint providing basic channel information

This commit is contained in:
Carsten Otto
2021-11-25 20:32:04 +01:00
parent c7bc495d16
commit 500d2b4392
6 changed files with 166 additions and 10 deletions

View File

@@ -3,6 +3,7 @@ package de.cotto.lndmanagej.controller;
import com.codahale.metrics.MetricRegistry;
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.FeeConfigurationDto;
import de.cotto.lndmanagej.controller.dto.ObjectMapperConfiguration;
import de.cotto.lndmanagej.controller.dto.OnChainCostsDto;
@@ -54,6 +55,16 @@ public class ChannelController {
this.feeService = feeService;
}
@GetMapping("/")
public ChannelDto getBasicInformation(@PathVariable ChannelId channelId) throws NotFoundException {
metrics.mark(MetricRegistry.name(getClass(), "getBasicInformation"));
LocalChannel localChannel = channelService.getLocalChannel(channelId).orElse(null);
if (localChannel == null) {
throw new NotFoundException();
}
return new ChannelDto(localChannel);
}
@GetMapping("/details")
public ChannelDetailsDto getDetails(@PathVariable ChannelId channelId) throws NotFoundException {
metrics.mark(MetricRegistry.name(getClass(), "getDetails"));

View File

@@ -19,6 +19,29 @@ public record ChannelDetailsDto(
OnChainCostsDto onChainCosts,
FeeConfigurationDto feeConfiguration
) {
public ChannelDetailsDto(
ChannelDto channelDto,
String remoteAlias,
BalanceInformation balanceInformation,
OnChainCostsDto onChainCosts,
FeeConfigurationDto feeConfiguration
) {
this(
channelDto.channelIdShort(),
channelDto.channelIdCompact(),
channelDto.channelIdCompactLnd(),
channelDto.channelPoint(),
channelDto.openHeight(),
channelDto.remotePubkey(),
remoteAlias,
channelDto.capacity(),
channelDto.status(),
BalanceInformationDto.createFrom(balanceInformation),
onChainCosts,
feeConfiguration
);
}
public ChannelDetailsDto(
LocalChannel localChannel,
String remoteAlias,
@@ -27,16 +50,9 @@ public record ChannelDetailsDto(
FeeConfigurationDto feeConfiguration
) {
this(
String.valueOf(localChannel.getId().getShortChannelId()),
localChannel.getId().getCompactForm(),
localChannel.getId().getCompactFormLnd(),
localChannel.getChannelPoint(),
localChannel.getId().getBlockHeight(),
localChannel.getRemotePubkey(),
new ChannelDto(localChannel),
remoteAlias,
String.valueOf(localChannel.getCapacity().satoshis()),
ChannelStatusDto.createFrom(localChannel.getStatus()),
BalanceInformationDto.createFrom(balanceInformation),
balanceInformation,
onChainCosts,
feeConfiguration
);

View File

@@ -0,0 +1,29 @@
package de.cotto.lndmanagej.controller.dto;
import de.cotto.lndmanagej.model.ChannelPoint;
import de.cotto.lndmanagej.model.LocalChannel;
import de.cotto.lndmanagej.model.Pubkey;
public record ChannelDto(
String channelIdShort,
String channelIdCompact,
String channelIdCompactLnd,
ChannelPoint channelPoint,
int openHeight,
Pubkey remotePubkey,
String capacity,
ChannelStatusDto status
) {
public ChannelDto(LocalChannel localChannel) {
this(
String.valueOf(localChannel.getId().getShortChannelId()),
localChannel.getId().getCompactForm(),
localChannel.getId().getCompactFormLnd(),
localChannel.getChannelPoint(),
localChannel.getId().getBlockHeight(),
localChannel.getRemotePubkey(),
String.valueOf(localChannel.getCapacity().satoshis()),
ChannelStatusDto.createFrom(localChannel.getStatus())
);
}
}