add public testnet electrum server

This commit is contained in:
Craig Raw 2021-11-03 12:27:45 +02:00
parent a22f69e2c1
commit b5301c4556
5 changed files with 41 additions and 24 deletions

View file

@ -77,7 +77,8 @@ public class MainApp extends Application {
createNewWallet = optNewWallet.isPresent() && optNewWallet.get(); createNewWallet = optNewWallet.isPresent() && optNewWallet.get();
} else if(Network.get() == Network.MAINNET) { } else if(Network.get() == Network.MAINNET) {
Config.get().setServerType(ServerType.PUBLIC_ELECTRUM_SERVER); Config.get().setServerType(ServerType.PUBLIC_ELECTRUM_SERVER);
Config.get().setPublicElectrumServer(PublicElectrumServer.values()[new Random().nextInt(PublicElectrumServer.values().length)].getUrl()); List<PublicElectrumServer> servers = PublicElectrumServer.getServers();
Config.get().setPublicElectrumServer(servers.get(new Random().nextInt(servers.size())).getUrl());
} }
} }
} }

View file

@ -384,7 +384,7 @@ public class Config {
} }
public void changePublicServer() { public void changePublicServer() {
List<String> otherServers = Arrays.stream(PublicElectrumServer.values()).map(PublicElectrumServer::getUrl).filter(url -> !url.equals(getPublicElectrumServer())).collect(Collectors.toList()); List<String> otherServers = PublicElectrumServer.getServers().stream().map(PublicElectrumServer::getUrl).filter(url -> !url.equals(getPublicElectrumServer())).collect(Collectors.toList());
setPublicElectrumServer(otherServers.get(new Random().nextInt(otherServers.size()))); setPublicElectrumServer(otherServers.get(new Random().nextInt(otherServers.size())));
} }

View file

@ -1,19 +1,30 @@
package com.sparrowwallet.sparrow.net; package com.sparrowwallet.sparrow.net;
public enum PublicElectrumServer { import com.sparrowwallet.drongo.Network;
BLOCKSTREAM_INFO("blockstream.info", "ssl://blockstream.info:700"),
ELECTRUM_BLOCKSTREAM_INFO("electrum.blockstream.info", "ssl://electrum.blockstream.info:50002"),
LUKECHILDS_CO("bitcoin.lukechilds.co", "ssl://bitcoin.lukechilds.co:50002"),
EMZY_DE("electrum.emzy.de", "ssl://electrum.emzy.de:50002"),
BITAROO_NET("electrum.bitaroo.net", "ssl://electrum.bitaroo.net:50002");
PublicElectrumServer(String name, String url) { import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public enum PublicElectrumServer {
BLOCKSTREAM_INFO("blockstream.info", "ssl://blockstream.info:700", Network.MAINNET),
ELECTRUM_BLOCKSTREAM_INFO("electrum.blockstream.info", "ssl://electrum.blockstream.info:50002", Network.MAINNET),
LUKECHILDS_CO("bitcoin.lukechilds.co", "ssl://bitcoin.lukechilds.co:50002", Network.MAINNET),
EMZY_DE("electrum.emzy.de", "ssl://electrum.emzy.de:50002", Network.MAINNET),
BITAROO_NET("electrum.bitaroo.net", "ssl://electrum.bitaroo.net:50002", Network.MAINNET),
TESTNET_ARANGUREN_ORG("testnet.aranguren.org", "ssl://testnet.aranguren.org:51002", Network.TESTNET);
PublicElectrumServer(String name, String url, Network network) {
this.name = name; this.name = name;
this.url = url; this.url = url;
this.network = network;
} }
public static final List<Network> SUPPORTED_NETWORKS = List.of(Network.MAINNET, Network.TESTNET);
private final String name; private final String name;
private final String url; private final String url;
private final Network network;
public String getName() { public String getName() {
return name; return name;
@ -23,6 +34,18 @@ public enum PublicElectrumServer {
return url; return url;
} }
public Network getNetwork() {
return network;
}
public static List<PublicElectrumServer> getServers() {
return Arrays.stream(values()).filter(server -> server.network == Network.get()).collect(Collectors.toList());
}
public static boolean supportedNetwork() {
return SUPPORTED_NETWORKS.contains(Network.get());
}
public static PublicElectrumServer fromUrl(String url) { public static PublicElectrumServer fromUrl(String url) {
for(PublicElectrumServer server : values()) { for(PublicElectrumServer server : values()) {
if(server.url.equals(url)) { if(server.url.equals(url)) {

View file

@ -15,6 +15,7 @@ import com.sparrowwallet.sparrow.io.Storage;
import com.sparrowwallet.sparrow.net.*; import com.sparrowwallet.sparrow.net.*;
import javafx.application.Platform; import javafx.application.Platform;
import javafx.beans.value.ChangeListener; import javafx.beans.value.ChangeListener;
import javafx.collections.FXCollections;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.text.Font; import javafx.scene.text.Font;
@ -186,15 +187,16 @@ public class ServerPreferencesController extends PreferencesDetailController {
} }
}); });
ServerType serverType = config.getServerType() != null ? ServerType serverType = config.getServerType() != null ?
(config.getServerType() == ServerType.PUBLIC_ELECTRUM_SERVER && Network.get() != Network.MAINNET ? ServerType.BITCOIN_CORE : config.getServerType()) : (config.getServerType() == ServerType.PUBLIC_ELECTRUM_SERVER && !PublicElectrumServer.supportedNetwork() ? ServerType.BITCOIN_CORE : config.getServerType()) :
(config.getCoreServer() == null && config.getElectrumServer() != null ? ServerType.ELECTRUM_SERVER : (config.getCoreServer() == null && config.getElectrumServer() != null ? ServerType.ELECTRUM_SERVER :
(config.getCoreServer() != null || Network.get() != Network.MAINNET ? ServerType.BITCOIN_CORE : ServerType.PUBLIC_ELECTRUM_SERVER)); (config.getCoreServer() != null || !PublicElectrumServer.supportedNetwork() ? ServerType.BITCOIN_CORE : ServerType.PUBLIC_ELECTRUM_SERVER));
if(Network.get() != Network.MAINNET) { if(!PublicElectrumServer.supportedNetwork()) {
serverTypeSegmentedButton.getButtons().remove(publicElectrumToggle); serverTypeSegmentedButton.getButtons().remove(publicElectrumToggle);
serverTypeToggleGroup.getToggles().remove(publicElectrumToggle); serverTypeToggleGroup.getToggles().remove(publicElectrumToggle);
} }
serverTypeToggleGroup.selectToggle(serverTypeToggleGroup.getToggles().stream().filter(toggle -> toggle.getUserData() == serverType).findFirst().orElse(null)); serverTypeToggleGroup.selectToggle(serverTypeToggleGroup.getToggles().stream().filter(toggle -> toggle.getUserData() == serverType).findFirst().orElse(null));
publicElectrumServer.setItems(FXCollections.observableList(PublicElectrumServer.getServers()));
publicElectrumServer.getSelectionModel().selectedItemProperty().addListener(getPublicElectrumServerListener(config)); publicElectrumServer.getSelectionModel().selectedItemProperty().addListener(getPublicElectrumServerListener(config));
publicUseProxy.selectedProperty().bindBidirectional(useProxy.selectedProperty()); publicUseProxy.selectedProperty().bindBidirectional(useProxy.selectedProperty());
@ -326,7 +328,8 @@ public class ServerPreferencesController extends PreferencesDetailController {
PublicElectrumServer configPublicElectrumServer = PublicElectrumServer.fromUrl(config.getPublicElectrumServer()); PublicElectrumServer configPublicElectrumServer = PublicElectrumServer.fromUrl(config.getPublicElectrumServer());
if(configPublicElectrumServer == null) { if(configPublicElectrumServer == null) {
publicElectrumServer.setValue(PublicElectrumServer.values()[new Random().nextInt(PublicElectrumServer.values().length)]); List<PublicElectrumServer> servers = PublicElectrumServer.getServers();
publicElectrumServer.setValue(servers.get(new Random().nextInt(servers.size())));
} else { } else {
publicElectrumServer.setValue(configPublicElectrumServer); publicElectrumServer.setValue(configPublicElectrumServer);
} }

View file

@ -85,17 +85,7 @@
<CopyableLabel text="Using a public server means it can see your transactions."/> <CopyableLabel text="Using a public server means it can see your transactions."/>
</Field> </Field>
<Field text="URL:"> <Field text="URL:">
<ComboBox fx:id="publicElectrumServer"> <ComboBox fx:id="publicElectrumServer" />
<items>
<FXCollections fx:factory="observableArrayList">
<PublicElectrumServer fx:constant="BLOCKSTREAM_INFO" />
<PublicElectrumServer fx:constant="ELECTRUM_BLOCKSTREAM_INFO" />
<PublicElectrumServer fx:constant="LUKECHILDS_CO" />
<PublicElectrumServer fx:constant="EMZY_DE" />
<PublicElectrumServer fx:constant="BITAROO_NET" />
</FXCollections>
</items>
</ComboBox>
</Field> </Field>
<Field text="Use Proxy:"> <Field text="Use Proxy:">
<UnlabeledToggleSwitch fx:id="publicUseProxy"/> <UnlabeledToggleSwitch fx:id="publicUseProxy"/>