diff --git a/application/src/integrationTest/java/de/cotto/lndmanagej/controller/LegacyControllerIT.java b/application/src/integrationTest/java/de/cotto/lndmanagej/controller/LegacyControllerIT.java index c9b9ceab..37eb93cb 100644 --- a/application/src/integrationTest/java/de/cotto/lndmanagej/controller/LegacyControllerIT.java +++ b/application/src/integrationTest/java/de/cotto/lndmanagej/controller/LegacyControllerIT.java @@ -83,6 +83,13 @@ class LegacyControllerIT { .andExpect(content().string(CHANNEL_ID_COMPACT + "\n" + CHANNEL_ID_COMPACT_3)); } + @Test + void getOpenChannelIdsPretty() throws Exception { + when(channelService.getOpenChannels()).thenReturn(Set.of(LOCAL_CHANNEL, LOCAL_CHANNEL_3)); + mockMvc.perform(get("/legacy/open-channels/pretty")) + .andExpect(status().isOk()); + } + @Test void isSyncedToChain_true() throws Exception { when(ownNodeService.isSyncedToChain()).thenReturn(true); diff --git a/application/src/main/java/de/cotto/lndmanagej/controller/LegacyController.java b/application/src/main/java/de/cotto/lndmanagej/controller/LegacyController.java index 7999926f..b714ede5 100644 --- a/application/src/main/java/de/cotto/lndmanagej/controller/LegacyController.java +++ b/application/src/main/java/de/cotto/lndmanagej/controller/LegacyController.java @@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.Comparator; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -65,6 +66,20 @@ public class LegacyController { .collect(Collectors.joining(NEWLINE)); } + @GetMapping("/open-channels/pretty") + public String getOpenChannelIdsPretty() { + return channelService.getOpenChannels().stream() + .sorted(Comparator.comparing(LocalChannel::getId)) + .map(localChannel -> { + Pubkey pubkey = localChannel.getRemotePubkey(); + return localChannel.getId().getCompactForm() + + "\t" + pubkey + + "\t" + localChannel.getCapacity() + + "\t" + nodeService.getAlias(pubkey); + }) + .collect(Collectors.joining(NEWLINE)); + } + @GetMapping("/peer-pubkeys") public String getPeerPubkeys() { return channelService.getOpenChannels().stream() diff --git a/application/src/test/java/de/cotto/lndmanagej/controller/LegacyControllerTest.java b/application/src/test/java/de/cotto/lndmanagej/controller/LegacyControllerTest.java index 54f15331..93f7484d 100644 --- a/application/src/test/java/de/cotto/lndmanagej/controller/LegacyControllerTest.java +++ b/application/src/test/java/de/cotto/lndmanagej/controller/LegacyControllerTest.java @@ -15,15 +15,21 @@ import org.mockito.junit.jupiter.MockitoExtension; import java.util.Set; +import static de.cotto.lndmanagej.model.ChannelFixtures.CAPACITY; +import static de.cotto.lndmanagej.model.ChannelFixtures.CAPACITY_2; import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID; import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID_2; import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID_3; import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID_COMPACT; import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID_COMPACT_3; +import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID_COMPACT_4; import static de.cotto.lndmanagej.model.LocalChannelFixtures.LOCAL_CHANNEL; import static de.cotto.lndmanagej.model.LocalChannelFixtures.LOCAL_CHANNEL_2; import static de.cotto.lndmanagej.model.LocalChannelFixtures.LOCAL_CHANNEL_3; +import static de.cotto.lndmanagej.model.LocalChannelFixtures.LOCAL_CHANNEL_TO_NODE_3; import static de.cotto.lndmanagej.model.NodeFixtures.ALIAS; +import static de.cotto.lndmanagej.model.NodeFixtures.ALIAS_2; +import static de.cotto.lndmanagej.model.NodeFixtures.ALIAS_3; import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY; import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_2; import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_3; @@ -85,6 +91,24 @@ class LegacyControllerTest { ); } + @Test + void getOpenChannelIdsPretty() { + when(nodeService.getAlias(PUBKEY_2)).thenReturn(ALIAS_2); + when(nodeService.getAlias(PUBKEY_3)).thenReturn(ALIAS_3); + when(channelService.getOpenChannels()).thenReturn(Set.of(LOCAL_CHANNEL, LOCAL_CHANNEL_TO_NODE_3)); + assertThat(legacyController.getOpenChannelIdsPretty()).isEqualTo( + CHANNEL_ID_COMPACT + "\t" + PUBKEY_2 + "\t" + CAPACITY + "\t" + ALIAS_2 + "\n" + + CHANNEL_ID_COMPACT_4 + "\t" + PUBKEY_3 + "\t" + CAPACITY_2 + "\t" + ALIAS_3 + ); + } + + @Test + void getOpenChannelIdsPretty_sorted() { + when(channelService.getOpenChannels()).thenReturn(Set.of(LOCAL_CHANNEL_TO_NODE_3, LOCAL_CHANNEL)); + assertThat(legacyController.getOpenChannelIdsPretty()) + .matches(CHANNEL_ID_COMPACT + ".*\n" + CHANNEL_ID_COMPACT_4 + ".*"); + } + @Test void getOpenChannelIds_ordered() { when(channelService.getOpenChannels()).thenReturn(Set.of(LOCAL_CHANNEL_3, LOCAL_CHANNEL)); diff --git a/model/src/testFixtures/java/de/cotto/lndmanagej/model/ChannelFixtures.java b/model/src/testFixtures/java/de/cotto/lndmanagej/model/ChannelFixtures.java index dc74b179..ab783bbf 100644 --- a/model/src/testFixtures/java/de/cotto/lndmanagej/model/ChannelFixtures.java +++ b/model/src/testFixtures/java/de/cotto/lndmanagej/model/ChannelFixtures.java @@ -3,26 +3,32 @@ package de.cotto.lndmanagej.model; import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID; import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID_2; import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID_3; +import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID_4; import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY; import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_2; import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_3; public final class ChannelFixtures { public static final Coins CAPACITY = Coins.ofSatoshis(21_000_000L); + public static final Coins CAPACITY_2 = Coins.ofSatoshis(42_000_000L); public static final Channel CHANNEL = create(PUBKEY, PUBKEY_2, CHANNEL_ID); public static final Channel CHANNEL_2 = create(PUBKEY, PUBKEY_2, CHANNEL_ID_2); public static final Channel CHANNEL_3 = create(PUBKEY, PUBKEY_2, CHANNEL_ID_3); - public static final Channel CHANNEL_TO_NODE_3 = create(PUBKEY, PUBKEY_3, CHANNEL_ID); + public static final Channel CHANNEL_TO_NODE_3 = create(PUBKEY, PUBKEY_3, CHANNEL_ID_4, CAPACITY_2); private ChannelFixtures() { // do not instantiate } public static Channel create(Pubkey pubkey1, Pubkey pubkey2, ChannelId channelId) { + return create(pubkey1, pubkey2, channelId, CAPACITY); + } + + public static Channel create(Pubkey pubkey1, Pubkey pubkey2, ChannelId channelId, Coins capacity) { return Channel.builder() .withChannelId(channelId) - .withCapacity(CAPACITY) + .withCapacity(capacity) .withNode1(pubkey1) .withNode2(pubkey2) .build(); diff --git a/model/src/testFixtures/java/de/cotto/lndmanagej/model/ChannelIdFixtures.java b/model/src/testFixtures/java/de/cotto/lndmanagej/model/ChannelIdFixtures.java index 30432320..4d7238ca 100644 --- a/model/src/testFixtures/java/de/cotto/lndmanagej/model/ChannelIdFixtures.java +++ b/model/src/testFixtures/java/de/cotto/lndmanagej/model/ChannelIdFixtures.java @@ -4,7 +4,9 @@ public class ChannelIdFixtures { public static final String CHANNEL_ID_COMPACT = "712345:123:1"; public static final String CHANNEL_ID_COMPACT_2 = "799999:456:2"; public static final String CHANNEL_ID_COMPACT_3 = "799999:456:3"; + public static final String CHANNEL_ID_COMPACT_4 = "799999:456:4"; public static final ChannelId CHANNEL_ID = ChannelId.fromCompactForm(CHANNEL_ID_COMPACT); public static final ChannelId CHANNEL_ID_2 = ChannelId.fromCompactForm(CHANNEL_ID_COMPACT_2); public static final ChannelId CHANNEL_ID_3 = ChannelId.fromCompactForm(CHANNEL_ID_COMPACT_3); + public static final ChannelId CHANNEL_ID_4 = ChannelId.fromCompactForm(CHANNEL_ID_COMPACT_4); }