mirror of
https://github.com/aljazceru/lnd-manageJ.git
synced 2026-01-23 07:54:24 +01:00
move ui demo to separate model
This commit is contained in:
committed by
Carsten Otto
parent
1d35da4e4f
commit
612d266af1
@@ -1,37 +0,0 @@
|
||||
package de.cotto.lndmanagej;
|
||||
|
||||
import de.cotto.lndmanagej.demo.DemoDataService;
|
||||
import de.cotto.lndmanagej.ui.UiDataService;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@EnableAutoConfiguration(
|
||||
exclude = {
|
||||
DataSourceAutoConfiguration.class,
|
||||
DataSourceTransactionManagerAutoConfiguration.class,
|
||||
HibernateJpaAutoConfiguration.class
|
||||
}
|
||||
)
|
||||
@ComponentScan(basePackages = {"de.cotto.lndmanagej.ui"})
|
||||
public class DemoApplication {
|
||||
|
||||
public DemoApplication() {
|
||||
// to satisfy pmd
|
||||
}
|
||||
|
||||
@Bean
|
||||
public UiDataService demoData() {
|
||||
return new DemoDataService();
|
||||
}
|
||||
|
||||
public static void main(String[] arguments) {
|
||||
SpringApplication.run(DemoApplication.class, arguments);
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,7 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
|
||||
import static de.cotto.lndmanagej.controller.dto.NodeDetailsDtoFixture.NODE_DETAILS_DTO;
|
||||
import static de.cotto.lndmanagej.model.BalanceInformationFixtures.BALANCE_INFORMATION;
|
||||
import static de.cotto.lndmanagej.model.ChannelDetailsFixtures.CHANNEL_DETAILS;
|
||||
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID;
|
||||
@@ -44,7 +45,6 @@ import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY;
|
||||
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY_2;
|
||||
import static de.cotto.lndmanagej.model.RebalanceReportFixtures.REBALANCE_REPORT;
|
||||
import static de.cotto.lndmanagej.model.warnings.ChannelWarningFixtures.CHANNEL_NUM_UPDATES_WARNING;
|
||||
import static de.cotto.lndmanagej.ui.model.NodeDetailsDtoFixture.NODE_DETAILS_DTO;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
package de.cotto.lndmanagej.demo;
|
||||
|
||||
import de.cotto.lndmanagej.controller.dto.NodeDetailsDto;
|
||||
import de.cotto.lndmanagej.model.ChannelId;
|
||||
import de.cotto.lndmanagej.model.Pubkey;
|
||||
import de.cotto.lndmanagej.ui.UiDataService;
|
||||
import de.cotto.lndmanagej.ui.dto.ChannelDetailsDto;
|
||||
import de.cotto.lndmanagej.ui.dto.NodeDto;
|
||||
import de.cotto.lndmanagej.ui.dto.OpenChannelDto;
|
||||
import de.cotto.lndmanagej.ui.dto.StatusModel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static de.cotto.lndmanagej.demo.utils.ChannelDetailsUtil.createChannelDetails;
|
||||
import static de.cotto.lndmanagej.demo.utils.NodeDetailsUtil.createNodeDetails;
|
||||
import static de.cotto.lndmanagej.demo.utils.NodeWarningsUtil.getStatusModel;
|
||||
import static de.cotto.lndmanagej.ui.model.OpenChannelDtoFixture.ACINQ;
|
||||
import static de.cotto.lndmanagej.ui.model.OpenChannelDtoFixture.ACINQ2;
|
||||
import static de.cotto.lndmanagej.ui.model.OpenChannelDtoFixture.BCASH;
|
||||
import static de.cotto.lndmanagej.ui.model.OpenChannelDtoFixture.COTTO;
|
||||
import static de.cotto.lndmanagej.ui.model.OpenChannelDtoFixture.OPEN_CHANNEL_DTO;
|
||||
import static de.cotto.lndmanagej.ui.model.OpenChannelDtoFixture.WOS;
|
||||
import static de.cotto.lndmanagej.ui.model.OpenChannelDtoFixture.WOS2;
|
||||
|
||||
public class DemoDataService extends UiDataService {
|
||||
|
||||
public DemoDataService() {
|
||||
super();
|
||||
}
|
||||
|
||||
@Override
|
||||
public StatusModel getStatus() {
|
||||
return getStatusModel();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<OpenChannelDto> getOpenChannels() {
|
||||
return List.of(OPEN_CHANNEL_DTO, ACINQ, ACINQ2, WOS, WOS2, BCASH, COTTO);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChannelDetailsDto getChannelDetails(ChannelId channelId) {
|
||||
OpenChannelDto localOpenChannel = getOpenChannels().stream()
|
||||
.filter(c -> c.channelId().equals(channelId))
|
||||
.findFirst()
|
||||
.orElseThrow();
|
||||
return createChannelDetails(localOpenChannel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeDto getNode(Pubkey pubkey) {
|
||||
return getOpenChannels().stream()
|
||||
.filter(channel -> channel.remotePubkey().equals(pubkey))
|
||||
.map(channel -> new NodeDto(pubkey.toString(), channel.remoteAlias(), isOnline(channel)))
|
||||
.findFirst().orElseThrow();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NodeDetailsDto getNodeDetails(Pubkey pubkey) {
|
||||
return createNodeDetails(getNode(pubkey));
|
||||
}
|
||||
|
||||
private static boolean isOnline(OpenChannelDto channel) {
|
||||
return channel.channelId().getShortChannelId() % 2 != 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
package de.cotto.lndmanagej.demo.utils;
|
||||
|
||||
import de.cotto.lndmanagej.controller.dto.FeeReportDto;
|
||||
import de.cotto.lndmanagej.controller.dto.FlowReportDto;
|
||||
import de.cotto.lndmanagej.controller.dto.OnChainCostsDto;
|
||||
import de.cotto.lndmanagej.controller.dto.RebalanceReportDto;
|
||||
import de.cotto.lndmanagej.model.FeeReportFixtures;
|
||||
import de.cotto.lndmanagej.model.FlowReportFixtures;
|
||||
import de.cotto.lndmanagej.model.OpenInitiator;
|
||||
import de.cotto.lndmanagej.model.RebalanceReportFixtures;
|
||||
import de.cotto.lndmanagej.ui.dto.ChannelDetailsDto;
|
||||
import de.cotto.lndmanagej.ui.dto.OpenChannelDto;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static de.cotto.lndmanagej.model.FeeReportFixtures.FEE_REPORT;
|
||||
import static de.cotto.lndmanagej.model.FlowReportFixtures.FLOW_REPORT;
|
||||
import static de.cotto.lndmanagej.model.OnChainCostsFixtures.ON_CHAIN_COSTS;
|
||||
import static de.cotto.lndmanagej.model.RebalanceReportFixtures.REBALANCE_REPORT;
|
||||
|
||||
public final class ChannelDetailsUtil {
|
||||
|
||||
private ChannelDetailsUtil() {
|
||||
// util class
|
||||
}
|
||||
|
||||
public static ChannelDetailsDto createChannelDetails(OpenChannelDto channel) {
|
||||
return new ChannelDetailsDto(
|
||||
channel.channelId(),
|
||||
channel.remotePubkey(),
|
||||
channel.remoteAlias(),
|
||||
OpenInitiator.REMOTE,
|
||||
channel.balanceInformation(),
|
||||
OnChainCostsDto.createFromModel(ON_CHAIN_COSTS),
|
||||
channel.policies(),
|
||||
FeeReportDto.createFromModel(FEE_REPORT),
|
||||
FlowReportDto.createFromModel(FLOW_REPORT),
|
||||
RebalanceReportDto.createFromModel(REBALANCE_REPORT),
|
||||
Set.of("Something is wrong with this channel."));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
package de.cotto.lndmanagej.demo.utils;
|
||||
|
||||
import de.cotto.lndmanagej.controller.dto.BalanceInformationDto;
|
||||
import de.cotto.lndmanagej.controller.dto.FeeReportDto;
|
||||
import de.cotto.lndmanagej.controller.dto.FlowReportDto;
|
||||
import de.cotto.lndmanagej.controller.dto.NodeDetailsDto;
|
||||
import de.cotto.lndmanagej.controller.dto.OnChainCostsDto;
|
||||
import de.cotto.lndmanagej.controller.dto.OnlineReportDto;
|
||||
import de.cotto.lndmanagej.controller.dto.RebalanceReportDto;
|
||||
import de.cotto.lndmanagej.model.ChannelId;
|
||||
import de.cotto.lndmanagej.model.FeeReportFixtures;
|
||||
import de.cotto.lndmanagej.model.FlowReportFixtures;
|
||||
import de.cotto.lndmanagej.model.OnlineReport;
|
||||
import de.cotto.lndmanagej.model.OnlineReportFixtures;
|
||||
import de.cotto.lndmanagej.model.Pubkey;
|
||||
import de.cotto.lndmanagej.model.RebalanceReportFixtures;
|
||||
import de.cotto.lndmanagej.ui.dto.NodeDto;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static de.cotto.lndmanagej.model.BalanceInformationFixtures.BALANCE_INFORMATION;
|
||||
import static de.cotto.lndmanagej.model.FeeReportFixtures.FEE_REPORT;
|
||||
import static de.cotto.lndmanagej.model.FlowReportFixtures.FLOW_REPORT;
|
||||
import static de.cotto.lndmanagej.model.OnChainCostsFixtures.ON_CHAIN_COSTS;
|
||||
import static de.cotto.lndmanagej.model.OnlineReportFixtures.ONLINE_REPORT;
|
||||
import static de.cotto.lndmanagej.model.OnlineReportFixtures.ONLINE_REPORT_OFFLINE;
|
||||
import static de.cotto.lndmanagej.model.RebalanceReportFixtures.REBALANCE_REPORT;
|
||||
|
||||
public final class NodeDetailsUtil {
|
||||
|
||||
private NodeDetailsUtil() {
|
||||
// util class
|
||||
}
|
||||
|
||||
public static NodeDetailsDto createNodeDetails(NodeDto node) {
|
||||
OnlineReport onlineReport = node.online() ? ONLINE_REPORT : ONLINE_REPORT_OFFLINE;
|
||||
return new NodeDetailsDto(
|
||||
Pubkey.create(node.pubkey()),
|
||||
node.alias(),
|
||||
List.of(ChannelId.fromCompactForm("712345x123x1")),
|
||||
List.of(ChannelId.fromCompactForm("712345x123x1")),
|
||||
List.of(),
|
||||
List.of(),
|
||||
OnChainCostsDto.createFromModel(ON_CHAIN_COSTS),
|
||||
BalanceInformationDto.createFromModel(BALANCE_INFORMATION),
|
||||
OnlineReportDto.createFromModel(onlineReport),
|
||||
FeeReportDto.createFromModel(FEE_REPORT),
|
||||
FlowReportDto.createFromModel(FLOW_REPORT),
|
||||
RebalanceReportDto.createFromModel(REBALANCE_REPORT),
|
||||
Set.of("Something is wrong with this node."));
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package de.cotto.lndmanagej.demo.utils;
|
||||
|
||||
import de.cotto.lndmanagej.controller.dto.ChannelWithWarningsDto;
|
||||
import de.cotto.lndmanagej.controller.dto.NodeWithWarningsDto;
|
||||
import de.cotto.lndmanagej.controller.dto.NodesAndChannelsWithWarningsDto;
|
||||
import de.cotto.lndmanagej.model.PubkeyFixtures;
|
||||
import de.cotto.lndmanagej.model.warnings.ChannelWarningsFixtures;
|
||||
import de.cotto.lndmanagej.model.warnings.NodeWarningsFixtures;
|
||||
import de.cotto.lndmanagej.model.warnings.Warning;
|
||||
import de.cotto.lndmanagej.ui.dto.StatusModel;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static de.cotto.lndmanagej.model.ChannelIdFixtures.CHANNEL_ID_3;
|
||||
import static de.cotto.lndmanagej.model.PubkeyFixtures.PUBKEY;
|
||||
import static de.cotto.lndmanagej.model.warnings.ChannelWarningsFixtures.CHANNEL_WARNINGS;
|
||||
import static de.cotto.lndmanagej.model.warnings.NodeWarningsFixtures.NODE_WARNINGS;
|
||||
|
||||
public final class NodeWarningsUtil {
|
||||
|
||||
private NodeWarningsUtil() {
|
||||
// util class
|
||||
}
|
||||
|
||||
public static StatusModel getStatusModel() {
|
||||
return new StatusModel(true, 735_642, createNodeWarnings());
|
||||
}
|
||||
|
||||
public static NodesAndChannelsWithWarningsDto createNodeWarnings() {
|
||||
return new NodesAndChannelsWithWarningsDto(
|
||||
List.of(new NodeWithWarningsDto(NODE_WARNINGS.warnings().stream()
|
||||
.map(Warning::description)
|
||||
.collect(Collectors.toSet()), "WalletOfSatoshi", PUBKEY),
|
||||
new NodeWithWarningsDto(NODE_WARNINGS.warnings().stream()
|
||||
.map(Warning::description)
|
||||
.collect(Collectors.toSet()), "Albert", PUBKEY)
|
||||
),
|
||||
List.of(new ChannelWithWarningsDto(CHANNEL_WARNINGS.warnings().stream()
|
||||
.map(Warning::description)
|
||||
.collect(Collectors.toSet()), CHANNEL_ID_3)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
package de.cotto.lndmanagej.ui.dto;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static de.cotto.lndmanagej.ui.model.OpenChannelDtoFixture.ACINQ;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.data.Percentage.withPercentage;
|
||||
|
||||
class OpenChannelDtoTest {
|
||||
|
||||
@Test
|
||||
void getLocalBalancePercentForPerfectlyBalancedChannel() {
|
||||
assertThat(ACINQ.getOutboundPercentage()).isCloseTo(50, withPercentage(1));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user