mirror of
https://github.com/aljazceru/lnd-manageJ.git
synced 2026-01-26 09:24:41 +01:00
return summed fees and amounts for self payments
This commit is contained in:
@@ -2,7 +2,6 @@ package de.cotto.lndmanagej.controller;
|
||||
|
||||
import com.codahale.metrics.annotation.Timed;
|
||||
import de.cotto.lndmanagej.controller.dto.ObjectMapperConfiguration;
|
||||
import de.cotto.lndmanagej.controller.dto.SelfPaymentDto;
|
||||
import de.cotto.lndmanagej.dto.SelfPaymentsDto;
|
||||
import de.cotto.lndmanagej.model.ChannelId;
|
||||
import de.cotto.lndmanagej.model.Pubkey;
|
||||
@@ -26,32 +25,24 @@ public class SelfPaymentsController {
|
||||
@Timed
|
||||
@GetMapping("/channel/{channelId}/self-payments-from-channel")
|
||||
public SelfPaymentsDto getSelfPaymentsFromChannel(@PathVariable ChannelId channelId) {
|
||||
return new SelfPaymentsDto(selfPaymentsService.getSelfPaymentsFromChannel(channelId).stream()
|
||||
.map(SelfPaymentDto::createFromModel)
|
||||
.toList());
|
||||
return new SelfPaymentsDto(selfPaymentsService.getSelfPaymentsFromChannel(channelId));
|
||||
}
|
||||
|
||||
@Timed
|
||||
@GetMapping("/node/{pubkey}/self-payments-from-peer")
|
||||
public SelfPaymentsDto getSelfPaymentsFromPeer(@PathVariable Pubkey pubkey) {
|
||||
return new SelfPaymentsDto(selfPaymentsService.getSelfPaymentsFromPeer(pubkey).stream()
|
||||
.map(SelfPaymentDto::createFromModel)
|
||||
.toList());
|
||||
return new SelfPaymentsDto(selfPaymentsService.getSelfPaymentsFromPeer(pubkey));
|
||||
}
|
||||
|
||||
@Timed
|
||||
@GetMapping("/channel/{channelId}/self-payments-to-channel")
|
||||
public SelfPaymentsDto getSelfPaymentsToChannel(@PathVariable ChannelId channelId) {
|
||||
return new SelfPaymentsDto(selfPaymentsService.getSelfPaymentsToChannel(channelId).stream()
|
||||
.map(SelfPaymentDto::createFromModel)
|
||||
.toList());
|
||||
return new SelfPaymentsDto(selfPaymentsService.getSelfPaymentsToChannel(channelId));
|
||||
}
|
||||
|
||||
@Timed
|
||||
@GetMapping("/node/{pubkey}/self-payments-to-peer")
|
||||
public SelfPaymentsDto getSelfPaymentsToPeer(@PathVariable Pubkey pubkey) {
|
||||
return new SelfPaymentsDto(selfPaymentsService.getSelfPaymentsToPeer(pubkey).stream()
|
||||
.map(SelfPaymentDto::createFromModel)
|
||||
.toList());
|
||||
return new SelfPaymentsDto(selfPaymentsService.getSelfPaymentsToPeer(pubkey));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,28 @@
|
||||
package de.cotto.lndmanagej.dto;
|
||||
|
||||
import de.cotto.lndmanagej.controller.dto.SelfPaymentDto;
|
||||
import de.cotto.lndmanagej.model.Coins;
|
||||
import de.cotto.lndmanagej.model.SelfPayment;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
|
||||
public record SelfPaymentsDto(List<SelfPaymentDto> selfPayments) {
|
||||
public record SelfPaymentsDto(List<SelfPaymentDto> selfPayments, String amountPaid, String fees) {
|
||||
public SelfPaymentsDto(List<SelfPayment> selfPayments) {
|
||||
this(
|
||||
selfPayments.stream().map(SelfPaymentDto::createFromModel).toList(),
|
||||
sumToString(selfPayments, SelfPayment::amountPaid),
|
||||
sumToString(selfPayments, SelfPayment::fees)
|
||||
);
|
||||
}
|
||||
|
||||
private static String sumToString(List<SelfPayment> selfPayments, Function<SelfPayment, Coins> coinFunction) {
|
||||
return String.valueOf(sum(selfPayments, coinFunction).milliSatoshis());
|
||||
}
|
||||
|
||||
private static Coins sum(List<SelfPayment> selfPayments, Function<SelfPayment, Coins> coinFunction) {
|
||||
return selfPayments.stream()
|
||||
.map(coinFunction)
|
||||
.reduce(Coins.NONE, Coins::add);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user