mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 05:06:45 +00:00
use default ports for bitcoin core if absent, fix ux on changing port for an aliased server
This commit is contained in:
parent
e88ea0bac1
commit
c360177c31
4 changed files with 25 additions and 1 deletions
|
@ -70,6 +70,14 @@ public class Server {
|
||||||
return url + (alias == null ? "" : "|" + alias);
|
return url + (alias == null ? "" : "|" + alias);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean portEquals(String port) {
|
||||||
|
if(port == null) {
|
||||||
|
return !getHostAndPort().hasPort();
|
||||||
|
}
|
||||||
|
|
||||||
|
return port.equals(getHostAndPort().hasPort() ? Integer.toString(getHostAndPort().getPort()) : "");
|
||||||
|
}
|
||||||
|
|
||||||
public static Server fromString(String server) {
|
public static Server fromString(String server) {
|
||||||
String[] parts = server.split("\\|");
|
String[] parts = server.split("\\|");
|
||||||
if(parts.length >= 2) {
|
if(parts.length >= 2) {
|
||||||
|
|
|
@ -146,6 +146,9 @@ public class Bwt {
|
||||||
Config config = Config.get();
|
Config config = Config.get();
|
||||||
if(config.getCoreServer() != null) {
|
if(config.getCoreServer() != null) {
|
||||||
bwtConfig.bitcoindUrl = config.getCoreServer().getUrl();
|
bwtConfig.bitcoindUrl = config.getCoreServer().getUrl();
|
||||||
|
if(!config.getCoreServer().getHostAndPort().hasPort()) {
|
||||||
|
bwtConfig.bitcoindUrl = config.getCoreServer().getUrl() + ":" + Network.get().getDefaultPort();
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
Protocol protocol = config.getCoreServer().getProtocol();
|
Protocol protocol = config.getCoreServer().getProtocol();
|
||||||
HostAndPort hostAndPort = protocol.getServerHostAndPort(bwtConfig.bitcoindUrl);
|
HostAndPort hostAndPort = protocol.getServerHostAndPort(bwtConfig.bitcoindUrl);
|
||||||
|
|
|
@ -43,7 +43,11 @@ public class BitcoindTransport implements Transport {
|
||||||
private BitcoindTransport(Server bitcoindServer, String bitcoindWallet) {
|
private BitcoindTransport(Server bitcoindServer, String bitcoindWallet) {
|
||||||
this.bitcoindServer = bitcoindServer;
|
this.bitcoindServer = bitcoindServer;
|
||||||
try {
|
try {
|
||||||
this.bitcoindUrl = new URL(bitcoindServer.getUrl() + "/wallet/" + bitcoindWallet);
|
String serverUrl = bitcoindServer.getUrl();
|
||||||
|
if(!bitcoindServer.getHostAndPort().hasPort()) {
|
||||||
|
serverUrl += ":" + Network.get().getDefaultPort();
|
||||||
|
}
|
||||||
|
this.bitcoindUrl = new URL(serverUrl + "/wallet/" + bitcoindWallet);
|
||||||
} catch(MalformedURLException e) {
|
} catch(MalformedURLException e) {
|
||||||
log.error("Malformed Bitcoin Core RPC URL", e);
|
log.error("Malformed Bitcoin Core RPC URL", e);
|
||||||
}
|
}
|
||||||
|
|
|
@ -243,6 +243,7 @@ public class ServerPreferencesController extends PreferencesDetailController {
|
||||||
proxyHost.textProperty().addListener(getProxyListener(config));
|
proxyHost.textProperty().addListener(getProxyListener(config));
|
||||||
proxyPort.textProperty().addListener(getProxyListener(config));
|
proxyPort.textProperty().addListener(getProxyListener(config));
|
||||||
|
|
||||||
|
corePort.setPromptText("e.g. " + Network.get().getDefaultPort());
|
||||||
coreDataDirField.managedProperty().bind(coreDataDirField.visibleProperty());
|
coreDataDirField.managedProperty().bind(coreDataDirField.visibleProperty());
|
||||||
coreUserPassField.managedProperty().bind(coreUserPassField.visibleProperty());
|
coreUserPassField.managedProperty().bind(coreUserPassField.visibleProperty());
|
||||||
coreUserPassField.visibleProperty().bind(coreDataDirField.visibleProperty().not());
|
coreUserPassField.visibleProperty().bind(coreDataDirField.visibleProperty().not());
|
||||||
|
@ -734,6 +735,10 @@ public class ServerPreferencesController extends PreferencesDetailController {
|
||||||
private ChangeListener<String> getBitcoinCoreListener(Config config) {
|
private ChangeListener<String> getBitcoinCoreListener(Config config) {
|
||||||
return (observable, oldValue, newValue) -> {
|
return (observable, oldValue, newValue) -> {
|
||||||
Server existingServer = config.getRecentCoreServers().stream().filter(server -> coreHost.getText().equals(server.getAlias())).findFirst().orElse(null);
|
Server existingServer = config.getRecentCoreServers().stream().filter(server -> coreHost.getText().equals(server.getAlias())).findFirst().orElse(null);
|
||||||
|
if(existingServer != null && !existingServer.portEquals(corePort.getText())) {
|
||||||
|
coreHost.setText(existingServer.getHost());
|
||||||
|
existingServer = null;
|
||||||
|
}
|
||||||
coreHost.setLeft(existingServer == null ? null : getGlyph(FontAwesome5.Glyph.TAG, null));
|
coreHost.setLeft(existingServer == null ? null : getGlyph(FontAwesome5.Glyph.TAG, null));
|
||||||
setCoreServerInConfig(config);
|
setCoreServerInConfig(config);
|
||||||
};
|
};
|
||||||
|
@ -769,6 +774,10 @@ public class ServerPreferencesController extends PreferencesDetailController {
|
||||||
private ChangeListener<String> getElectrumServerListener(Config config) {
|
private ChangeListener<String> getElectrumServerListener(Config config) {
|
||||||
return (observable, oldValue, newValue) -> {
|
return (observable, oldValue, newValue) -> {
|
||||||
Server existingServer = config.getRecentElectrumServers().stream().filter(server -> electrumHost.getText().equals(server.getAlias())).findFirst().orElse(null);
|
Server existingServer = config.getRecentElectrumServers().stream().filter(server -> electrumHost.getText().equals(server.getAlias())).findFirst().orElse(null);
|
||||||
|
if(existingServer != null && !existingServer.portEquals(electrumPort.getText())) {
|
||||||
|
electrumHost.setText(existingServer.getHost());
|
||||||
|
existingServer = null;
|
||||||
|
}
|
||||||
electrumHost.setLeft(existingServer == null ? null : getGlyph(FontAwesome5.Glyph.TAG, null));
|
electrumHost.setLeft(existingServer == null ? null : getGlyph(FontAwesome5.Glyph.TAG, null));
|
||||||
setElectrumServerInConfig(config);
|
setElectrumServerInConfig(config);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue