mirror of
https://github.com/aljazceru/lnd-manageJ.git
synced 2026-01-31 03:34:36 +01:00
ui-demo: remove derived node & channel warnings
This commit is contained in:
committed by
Carsten Otto
parent
05f20e36d8
commit
4f616242fa
@@ -19,6 +19,7 @@ import de.cotto.lndmanagej.ui.dto.NodeDto;
|
||||
import de.cotto.lndmanagej.ui.dto.OpenChannelDto;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
@@ -26,14 +27,12 @@ import java.util.stream.Collectors;
|
||||
import static de.cotto.lndmanagej.model.OnlineReportFixtures.ONLINE_REPORT;
|
||||
import static de.cotto.lndmanagej.model.OnlineReportFixtures.ONLINE_REPORT_OFFLINE;
|
||||
import static de.cotto.lndmanagej.ui.demo.data.DeriveDataUtil.deriveChannelStatus;
|
||||
import static de.cotto.lndmanagej.ui.demo.data.DeriveDataUtil.deriveChannelWarnings;
|
||||
import static de.cotto.lndmanagej.ui.demo.data.DeriveDataUtil.deriveFeeReport;
|
||||
import static de.cotto.lndmanagej.ui.demo.data.DeriveDataUtil.deriveFlowReport;
|
||||
import static de.cotto.lndmanagej.ui.demo.data.DeriveDataUtil.deriveOnChainCosts;
|
||||
import static de.cotto.lndmanagej.ui.demo.data.DeriveDataUtil.deriveOpenInitiator;
|
||||
import static de.cotto.lndmanagej.ui.demo.data.DeriveDataUtil.derivePolicies;
|
||||
import static de.cotto.lndmanagej.ui.demo.data.DeriveDataUtil.deriveRebalanceReport;
|
||||
import static de.cotto.lndmanagej.ui.demo.data.DeriveDataUtil.deriveWarnings;
|
||||
|
||||
@SuppressWarnings("PMD.ExcessiveImports")
|
||||
@Component
|
||||
@@ -133,7 +132,15 @@ public class DemoDataService extends UiDataService {
|
||||
.filter(c -> channelId.equals(c.channelId()))
|
||||
.findFirst()
|
||||
.orElseThrow(NotFoundException::new);
|
||||
return createChannelDetails(localOpenChannel);
|
||||
return createChannelDetails(localOpenChannel, getChannelWarnings(channelId));
|
||||
}
|
||||
|
||||
private Set<String> getChannelWarnings(ChannelId channelId) {
|
||||
return getWarnings().channelsWithWarnings().stream()
|
||||
.filter(c -> c.channelId().equals(channelId))
|
||||
.map(ChannelWithWarningsDto::warnings)
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -146,7 +153,16 @@ public class DemoDataService extends UiDataService {
|
||||
|
||||
@Override
|
||||
public NodeDetailsDto getNodeDetails(Pubkey pubkey) {
|
||||
return createNodeDetails(getNode(pubkey), getOpenChannels(pubkey));
|
||||
List<OpenChannelDto> openChannels = getOpenChannels(pubkey);
|
||||
return createNodeDetails(getNode(pubkey), openChannels, getNodeWarnings(pubkey));
|
||||
}
|
||||
|
||||
private Set<String> getNodeWarnings(Pubkey pubkey) {
|
||||
return getWarnings().nodesWithWarnings().stream()
|
||||
.filter(p -> p.pubkey().equals(pubkey))
|
||||
.map(NodeWithWarningsDto::warnings)
|
||||
.flatMap(Collection::stream)
|
||||
.collect(Collectors.toSet());
|
||||
}
|
||||
|
||||
static boolean isOnline(ChannelId channelId) {
|
||||
@@ -183,7 +199,7 @@ public class DemoDataService extends UiDataService {
|
||||
return new OpenChannelDto(channelId, alias, remotePubkey, policies, balance, capacity);
|
||||
}
|
||||
|
||||
private static ChannelDetailsDto createChannelDetails(OpenChannelDto channel) {
|
||||
private static ChannelDetailsDto createChannelDetails(OpenChannelDto channel, Set<String> warnings) {
|
||||
return new ChannelDetailsDto(
|
||||
channel.channelId(),
|
||||
channel.remotePubkey(),
|
||||
@@ -197,11 +213,11 @@ public class DemoDataService extends UiDataService {
|
||||
deriveFeeReport(channel.channelId()),
|
||||
deriveFlowReport(channel.channelId()),
|
||||
deriveRebalanceReport(channel.channelId()),
|
||||
deriveWarnings(channel.channelId())
|
||||
warnings
|
||||
);
|
||||
}
|
||||
|
||||
private static NodeDetailsDto createNodeDetails(NodeDto node, List<OpenChannelDto> channels) {
|
||||
private static NodeDetailsDto createNodeDetails(NodeDto node, List<OpenChannelDto> channels, Set<String> warnings) {
|
||||
OpenChannelDto firstChannel = channels.stream().findFirst().orElseThrow();
|
||||
OnlineReport onlineReport = node.online() ? ONLINE_REPORT : ONLINE_REPORT_OFFLINE;
|
||||
return new NodeDetailsDto(
|
||||
@@ -217,7 +233,7 @@ public class DemoDataService extends UiDataService {
|
||||
deriveFeeReport(firstChannel.channelId()),
|
||||
deriveFlowReport(firstChannel.channelId()),
|
||||
deriveRebalanceReport(firstChannel.channelId()),
|
||||
deriveChannelWarnings(firstChannel.channelId()));
|
||||
warnings);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ import de.cotto.lndmanagej.model.Policy;
|
||||
import de.cotto.lndmanagej.model.RebalanceReport;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.random.RandomGenerator;
|
||||
|
||||
import static de.cotto.lndmanagej.model.OpenCloseStatus.OPEN;
|
||||
@@ -48,12 +47,6 @@ public final class DeriveDataUtil {
|
||||
));
|
||||
}
|
||||
|
||||
static Set<String> deriveWarnings(ChannelId channelId) {
|
||||
RandomGenerator rand = createRandomGenerator(channelId);
|
||||
int updates = (rand.nextInt(10) + 5) * 100_000;
|
||||
return rand.nextBoolean() ? Set.of("Channel has accumulated " + updates + " updates.") : Set.of();
|
||||
}
|
||||
|
||||
static FlowReportDto deriveFlowReport(ChannelId channelId) {
|
||||
RandomGenerator rand = createRandomGenerator(channelId);
|
||||
FlowReport flowReport = new FlowReport(
|
||||
@@ -104,12 +97,6 @@ public final class DeriveDataUtil {
|
||||
return new Policy(feeRate, baseFee, enabled, timeLockDelta, MAX_HTLC);
|
||||
}
|
||||
|
||||
static Set<String> deriveChannelWarnings(ChannelId channelId) {
|
||||
RandomGenerator rand = createRandomGenerator(channelId);
|
||||
int days = rand.nextInt(30) + 30;
|
||||
return rand.nextBoolean() ? Set.of("No flow in the past " + days + " days.") : Set.of();
|
||||
}
|
||||
|
||||
public static ChannelStatusDto deriveChannelStatus(ChannelId channelId) {
|
||||
boolean privateChannel = createRandomGenerator(channelId).nextBoolean();
|
||||
return ChannelStatusDto.createFromModel(new ChannelStatus(privateChannel, true, false, OPEN));
|
||||
|
||||
@@ -4,10 +4,7 @@ import de.cotto.lndmanagej.model.OpenInitiator;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID;
|
||||
import static de.cotto.lndmanagej.ui.demo.data.DemoDataService.POCKET;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class DeriveDataUtilTest {
|
||||
|
||||
@@ -35,26 +32,6 @@ class DeriveDataUtilTest {
|
||||
assertEquals(770L, DeriveDataUtil.derivePolicy(CHANNEL_ID).feeRate());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deriveWarnings_noWarnings() {
|
||||
assertFalse(DeriveDataUtil.deriveWarnings(CHANNEL_ID).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deriveWarnings_hasWarnings() {
|
||||
assertTrue(DeriveDataUtil.deriveWarnings(POCKET.channelId()).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deriveChannelWarnings_noWarnings() {
|
||||
assertFalse(DeriveDataUtil.deriveChannelWarnings(CHANNEL_ID).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deriveChannelWarnings_hasWarnings() {
|
||||
assertTrue(DeriveDataUtil.deriveChannelWarnings(POCKET.channelId()).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void deriveOnChainCosts_sameChannelId_sameResult() {
|
||||
assertEquals("1849", DeriveDataUtil.deriveOnChainCosts(CHANNEL_ID).sweepCostsSat());
|
||||
|
||||
Reference in New Issue
Block a user