legacy: include fee rate in output

This commit is contained in:
Carsten Otto
2022-06-02 13:20:47 +02:00
parent 74dc369381
commit fac4ddcb60
3 changed files with 32 additions and 5 deletions

View File

@@ -2,9 +2,11 @@ package de.cotto.lndmanagej.controller;
import com.codahale.metrics.annotation.Timed;
import de.cotto.lndmanagej.model.LocalOpenChannel;
import de.cotto.lndmanagej.model.Policy;
import de.cotto.lndmanagej.model.Pubkey;
import de.cotto.lndmanagej.service.ChannelService;
import de.cotto.lndmanagej.service.NodeService;
import de.cotto.lndmanagej.service.PolicyService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -18,13 +20,16 @@ public class LegacyController {
private static final String NEWLINE = "\n";
private final NodeService nodeService;
private final ChannelService channelService;
private final PolicyService policyService;
public LegacyController(
NodeService nodeService,
ChannelService channelService
ChannelService channelService,
PolicyService policyService
) {
this.nodeService = nodeService;
this.channelService = channelService;
this.policyService = policyService;
}
@Timed
@@ -34,10 +39,14 @@ public class LegacyController {
.sorted(Comparator.comparing(LocalOpenChannel::getId))
.map(localOpenChannel -> {
Pubkey pubkey = localOpenChannel.getRemotePubkey();
long ppm = policyService.getPolicyTo(localOpenChannel.getId(), pubkey)
.map(Policy::feeRate)
.orElse(0L);
return localOpenChannel.getId().getCompactForm() +
"\t" + pubkey +
"\t" + localOpenChannel.getCapacity().toStringSat() +
"\t" + localOpenChannel.getBalanceInformation().localAvailable().toStringSat() +
"\t" + ppm +
"\t" + nodeService.getAlias(pubkey);
})
.collect(Collectors.joining(NEWLINE));