add fee-configuration endpoint for channel

This commit is contained in:
Carsten Otto
2021-11-24 12:40:40 +01:00
parent 7ac9230adc
commit 30aae170fe
5 changed files with 54 additions and 14 deletions

View File

@@ -24,6 +24,8 @@ 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
@RequestMapping("/api/channel/{channelId}")
@Import(ObjectMapperConfiguration.class)
@@ -69,6 +71,21 @@ public class ChannelController {
);
}
@GetMapping("/fee-configuration")
public FeeConfigurationDto getFeeConfiguration(@PathVariable ChannelId channelId) {
metrics.mark(MetricRegistry.name(getClass(), "getFeeConfiguration"));
LocalChannel localChannel = channelService.getLocalChannel(channelId).orElse(null);
return getFeeConfiguration(localChannel);
}
private FeeConfigurationDto getFeeConfiguration(@Nullable LocalChannel channel) {
if (channel == null || channel.getStatus().openCloseStatus() != OpenCloseStatus.OPEN) {
return FeeConfigurationDto.EMPTY;
}
FeeConfiguration feeConfiguration = feeService.getFeeConfiguration(channel.getId());
return FeeConfigurationDto.createFrom(feeConfiguration);
}
private BalanceInformation getBalanceInformation(ChannelId channelId) {
return balanceService.getBalanceInformation(channelId)
.orElse(BalanceInformation.EMPTY);
@@ -79,12 +96,4 @@ public class ChannelController {
Coins closeCosts = onChainCostService.getCloseCosts(channelId).orElse(Coins.NONE);
return new OnChainCostsDto(openCosts, closeCosts);
}
private FeeConfigurationDto getFeeConfiguration(LocalChannel channel) {
if (channel.getStatus().openCloseStatus() == OpenCloseStatus.OPEN) {
FeeConfiguration feeConfiguration = feeService.getFeeConfiguration(channel.getId());
return FeeConfigurationDto.createFrom(feeConfiguration);
}
return new FeeConfigurationDto(0, 0, 0, 0);
}
}

View File

@@ -8,6 +8,9 @@ public record FeeConfigurationDto(
long incomingFeeRatePpm,
long incomingBaseFeeMilliSat
) {
public static final FeeConfigurationDto EMPTY =
new FeeConfigurationDto(0, 0, 0, 0);
public static FeeConfigurationDto createFrom(FeeConfiguration feeConfiguration) {
return new FeeConfigurationDto(
feeConfiguration.outgoingFeeRate(),