mirror of
https://github.com/aljazceru/lnd-manageJ.git
synced 2026-01-21 15:04:22 +01:00
add self payments endpoints
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
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.model.ChannelId;
|
||||
import de.cotto.lndmanagej.service.SelfPaymentsService;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("/api/")
|
||||
@Import(ObjectMapperConfiguration.class)
|
||||
public class SelfPaymentsController {
|
||||
private final SelfPaymentsService selfPaymentsService;
|
||||
|
||||
public SelfPaymentsController(SelfPaymentsService selfPaymentsService) {
|
||||
this.selfPaymentsService = selfPaymentsService;
|
||||
}
|
||||
|
||||
@Timed
|
||||
@GetMapping("/channel/{channelId}/self-payments-to-channel")
|
||||
public List<SelfPaymentDto> getSelfPaymentsToChannel(@PathVariable ChannelId channelId) {
|
||||
return selfPaymentsService.getSelfPaymentsToChannel(channelId).stream()
|
||||
.map(SelfPaymentDto::createFromModel)
|
||||
.toList();
|
||||
}
|
||||
|
||||
@Timed
|
||||
@GetMapping("/channel/{channelId}/self-payments-from-channel")
|
||||
public List<SelfPaymentDto> getSelfPaymentsFromChannel(@PathVariable ChannelId channelId) {
|
||||
return selfPaymentsService.getSelfPaymentsFromChannel(channelId).stream()
|
||||
.map(SelfPaymentDto::createFromModel)
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,8 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
@Configuration
|
||||
public class ObjectMapperConfiguration {
|
||||
public ObjectMapperConfiguration() {
|
||||
@@ -23,6 +25,7 @@ public class ObjectMapperConfiguration {
|
||||
module.addSerializer(Pubkey.class, new ToStringSerializer());
|
||||
module.addSerializer(ChannelId.class, new ToStringSerializer());
|
||||
module.addSerializer(ChannelPoint.class, new ToStringSerializer());
|
||||
module.addSerializer(ZonedDateTime.class, new ToStringSerializer());
|
||||
return new ObjectMapper().registerModule(module);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package de.cotto.lndmanagej.controller.dto;
|
||||
|
||||
import de.cotto.lndmanagej.model.ChannelId;
|
||||
import de.cotto.lndmanagej.model.SelfPayment;
|
||||
|
||||
import java.time.ZonedDateTime;
|
||||
|
||||
public record SelfPaymentDto(
|
||||
ZonedDateTime settleDate,
|
||||
String memo,
|
||||
String value,
|
||||
String fees,
|
||||
ChannelId firstChannel,
|
||||
ChannelId lastChannel
|
||||
) {
|
||||
public static SelfPaymentDto createFromModel(SelfPayment selfPayment) {
|
||||
return new SelfPaymentDto(
|
||||
selfPayment.settleDate(),
|
||||
selfPayment.memo(),
|
||||
String.valueOf(selfPayment.value().milliSatoshis()),
|
||||
String.valueOf(selfPayment.fees().milliSatoshis()),
|
||||
selfPayment.firstChannel().orElseThrow(),
|
||||
selfPayment.lastChannel().orElseThrow()
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user