mirror of
https://github.com/aljazceru/lnd-manageJ.git
synced 2026-01-22 07:24:23 +01:00
move feeconfiguration to policies (local+remote)
This commit is contained in:
@@ -4,22 +4,22 @@ 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;
|
||||
import de.cotto.lndmanagej.controller.dto.PoliciesDto;
|
||||
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.FeeConfiguration;
|
||||
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.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;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
@@ -37,14 +37,14 @@ public class ChannelController {
|
||||
private final Metrics metrics;
|
||||
private final BalanceService balanceService;
|
||||
private final OnChainCostService onChainCostService;
|
||||
private final FeeService feeService;
|
||||
private final PolicyService policyService;
|
||||
|
||||
public ChannelController(
|
||||
ChannelService channelService,
|
||||
NodeService nodeService,
|
||||
BalanceService balanceService,
|
||||
OnChainCostService onChainCostService,
|
||||
FeeService feeService,
|
||||
PolicyService policyService,
|
||||
Metrics metrics
|
||||
) {
|
||||
this.channelService = channelService;
|
||||
@@ -52,7 +52,7 @@ public class ChannelController {
|
||||
this.balanceService = balanceService;
|
||||
this.onChainCostService = onChainCostService;
|
||||
this.metrics = metrics;
|
||||
this.feeService = feeService;
|
||||
this.policyService = policyService;
|
||||
}
|
||||
|
||||
@GetMapping("/")
|
||||
@@ -79,7 +79,7 @@ public class ChannelController {
|
||||
remoteAlias,
|
||||
getBalanceInformation(channelId),
|
||||
getOnChainCosts(channelId),
|
||||
getFeeConfiguration(localChannel)
|
||||
getPolicies(localChannel)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -91,19 +91,19 @@ public class ChannelController {
|
||||
return BalanceInformationDto.createFrom(balanceInformation);
|
||||
}
|
||||
|
||||
@GetMapping("/fee-configuration")
|
||||
public FeeConfigurationDto getFeeConfiguration(@PathVariable ChannelId channelId) {
|
||||
metrics.mark(MetricRegistry.name(getClass(), "getFeeConfiguration"));
|
||||
@GetMapping("/policies")
|
||||
public PoliciesDto getPolicies(@PathVariable ChannelId channelId) {
|
||||
metrics.mark(MetricRegistry.name(getClass(), "getPolicies"));
|
||||
LocalChannel localChannel = channelService.getLocalChannel(channelId).orElse(null);
|
||||
return getFeeConfiguration(localChannel);
|
||||
return getPolicies(localChannel);
|
||||
}
|
||||
|
||||
private FeeConfigurationDto getFeeConfiguration(@Nullable LocalChannel channel) {
|
||||
private PoliciesDto getPolicies(@Nullable LocalChannel channel) {
|
||||
if (channel == null || channel.getStatus().openCloseStatus() != OpenCloseStatus.OPEN) {
|
||||
return FeeConfigurationDto.EMPTY;
|
||||
return PoliciesDto.EMPTY;
|
||||
}
|
||||
FeeConfiguration feeConfiguration = feeService.getFeeConfiguration(channel.getId());
|
||||
return FeeConfigurationDto.createFrom(feeConfiguration);
|
||||
Policies policies = policyService.getPolicies(channel.getId());
|
||||
return PoliciesDto.createFrom(policies);
|
||||
}
|
||||
|
||||
private BalanceInformation getBalanceInformation(ChannelId channelId) {
|
||||
|
||||
@@ -21,14 +21,14 @@ public record ChannelDetailsDto(
|
||||
ChannelStatusDto status,
|
||||
BalanceInformationDto balance,
|
||||
OnChainCostsDto onChainCosts,
|
||||
FeeConfigurationDto feeConfiguration
|
||||
PoliciesDto policies
|
||||
) {
|
||||
public ChannelDetailsDto(
|
||||
ChannelDto channelDto,
|
||||
String remoteAlias,
|
||||
BalanceInformation balanceInformation,
|
||||
OnChainCostsDto onChainCosts,
|
||||
FeeConfigurationDto feeConfiguration
|
||||
PoliciesDto policies
|
||||
) {
|
||||
this(
|
||||
channelDto.channelIdShort(),
|
||||
@@ -45,7 +45,7 @@ public record ChannelDetailsDto(
|
||||
channelDto.status(),
|
||||
BalanceInformationDto.createFrom(balanceInformation),
|
||||
onChainCosts,
|
||||
feeConfiguration
|
||||
policies
|
||||
);
|
||||
}
|
||||
|
||||
@@ -54,14 +54,14 @@ public record ChannelDetailsDto(
|
||||
String remoteAlias,
|
||||
BalanceInformation balanceInformation,
|
||||
OnChainCostsDto onChainCosts,
|
||||
FeeConfigurationDto feeConfiguration
|
||||
PoliciesDto policies
|
||||
) {
|
||||
this(
|
||||
new ChannelDto(localChannel),
|
||||
remoteAlias,
|
||||
balanceInformation,
|
||||
onChainCosts,
|
||||
feeConfiguration
|
||||
policies
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
package de.cotto.lndmanagej.controller.dto;
|
||||
|
||||
import de.cotto.lndmanagej.model.FeeConfiguration;
|
||||
|
||||
public record FeeConfigurationDto(
|
||||
long outgoingFeeRatePpm,
|
||||
long outgoingBaseFeeMilliSat,
|
||||
long incomingFeeRatePpm,
|
||||
long incomingBaseFeeMilliSat,
|
||||
boolean enabledLocal,
|
||||
boolean enabledRemote
|
||||
) {
|
||||
public static final FeeConfigurationDto EMPTY =
|
||||
new FeeConfigurationDto(
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
false,
|
||||
false
|
||||
);
|
||||
|
||||
public static FeeConfigurationDto createFrom(FeeConfiguration feeConfiguration) {
|
||||
return new FeeConfigurationDto(
|
||||
feeConfiguration.outgoingFeeRate(),
|
||||
feeConfiguration.outgoingBaseFee().milliSatoshis(),
|
||||
feeConfiguration.incomingFeeRate(),
|
||||
feeConfiguration.incomingBaseFee().milliSatoshis(),
|
||||
feeConfiguration.enabledLocal(),
|
||||
feeConfiguration.enabledRemote()
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package de.cotto.lndmanagej.controller.dto;
|
||||
|
||||
import de.cotto.lndmanagej.model.Policies;
|
||||
|
||||
public record PoliciesDto(
|
||||
PolicyDto local,
|
||||
PolicyDto remote
|
||||
) {
|
||||
public static final PoliciesDto EMPTY =
|
||||
new PoliciesDto(PolicyDto.EMPTY, PolicyDto.EMPTY);
|
||||
|
||||
public static PoliciesDto createFrom(Policies policies) {
|
||||
return new PoliciesDto(
|
||||
PolicyDto.createFrom(policies.local()),
|
||||
PolicyDto.createFrom(policies.remote())
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package de.cotto.lndmanagej.controller.dto;
|
||||
|
||||
import de.cotto.lndmanagej.model.Policy;
|
||||
|
||||
public record PolicyDto(
|
||||
long feeRatePpm,
|
||||
long baseFeeMilliSat,
|
||||
boolean enabled
|
||||
) {
|
||||
public static final PolicyDto EMPTY =
|
||||
new PolicyDto(
|
||||
0,
|
||||
0,
|
||||
false
|
||||
);
|
||||
|
||||
public static PolicyDto createFrom(Policy policy) {
|
||||
return new PolicyDto(
|
||||
policy.feeRate(),
|
||||
policy.baseFee().milliSatoshis(),
|
||||
policy.enabled()
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user