mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-11-04 21:36: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);
|
||||
}
|
||||
|
||||
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) {
|
||||
String[] parts = server.split("\\|");
|
||||
if(parts.length >= 2) {
|
||||
|
|
|
@ -146,6 +146,9 @@ public class Bwt {
|
|||
Config config = Config.get();
|
||||
if(config.getCoreServer() != null) {
|
||||
bwtConfig.bitcoindUrl = config.getCoreServer().getUrl();
|
||||
if(!config.getCoreServer().getHostAndPort().hasPort()) {
|
||||
bwtConfig.bitcoindUrl = config.getCoreServer().getUrl() + ":" + Network.get().getDefaultPort();
|
||||
}
|
||||
try {
|
||||
Protocol protocol = config.getCoreServer().getProtocol();
|
||||
HostAndPort hostAndPort = protocol.getServerHostAndPort(bwtConfig.bitcoindUrl);
|
||||
|
|
|
@ -43,7 +43,11 @@ public class BitcoindTransport implements Transport {
|
|||
private BitcoindTransport(Server bitcoindServer, String bitcoindWallet) {
|
||||
this.bitcoindServer = bitcoindServer;
|
||||
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) {
|
||||
log.error("Malformed Bitcoin Core RPC URL", e);
|
||||
}
|
||||
|
|
|
@ -243,6 +243,7 @@ public class ServerPreferencesController extends PreferencesDetailController {
|
|||
proxyHost.textProperty().addListener(getProxyListener(config));
|
||||
proxyPort.textProperty().addListener(getProxyListener(config));
|
||||
|
||||
corePort.setPromptText("e.g. " + Network.get().getDefaultPort());
|
||||
coreDataDirField.managedProperty().bind(coreDataDirField.visibleProperty());
|
||||
coreUserPassField.managedProperty().bind(coreUserPassField.visibleProperty());
|
||||
coreUserPassField.visibleProperty().bind(coreDataDirField.visibleProperty().not());
|
||||
|
@ -734,6 +735,10 @@ public class ServerPreferencesController extends PreferencesDetailController {
|
|||
private ChangeListener<String> getBitcoinCoreListener(Config config) {
|
||||
return (observable, oldValue, newValue) -> {
|
||||
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));
|
||||
setCoreServerInConfig(config);
|
||||
};
|
||||
|
@ -769,6 +774,10 @@ public class ServerPreferencesController extends PreferencesDetailController {
|
|||
private ChangeListener<String> getElectrumServerListener(Config config) {
|
||||
return (observable, oldValue, newValue) -> {
|
||||
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));
|
||||
setElectrumServerInConfig(config);
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue