mirror of
https://github.com/sparrowwallet/sparrow.git
synced 2024-12-25 05:06:45 +00:00
initialize bwt only on connection, default to core multi-wallet use
This commit is contained in:
parent
a9a3eef157
commit
aacecc8517
10 changed files with 58 additions and 29 deletions
|
@ -69,7 +69,7 @@ dependencies {
|
||||||
exclude group: 'org.openjfx', module: 'javafx-web'
|
exclude group: 'org.openjfx', module: 'javafx-web'
|
||||||
exclude group: 'org.openjfx', module: 'javafx-media'
|
exclude group: 'org.openjfx', module: 'javafx-media'
|
||||||
}
|
}
|
||||||
implementation('dev.bwt:bwt-jni:0.1.6')
|
implementation('dev.bwt:bwt-jni:0.1.7')
|
||||||
testImplementation('junit:junit:4.12')
|
testImplementation('junit:junit:4.12')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
2
drongo
2
drongo
|
@ -1 +1 @@
|
||||||
Subproject commit 3e91bdb46cd235247550b2b579285a05609c0837
|
Subproject commit 93d494fcde0d6979b2ded2a9d5ebd5d54d58b8ea
|
|
@ -30,7 +30,7 @@
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>100</string>
|
<string>100</string>
|
||||||
<key>NSHumanReadableCopyright</key>
|
<key>NSHumanReadableCopyright</key>
|
||||||
<string>Copyright (C) 2020</string>
|
<string>Copyright (C) 2021</string>
|
||||||
<key>NSHighResolutionCapable</key>
|
<key>NSHighResolutionCapable</key>
|
||||||
<string>true</string>
|
<string>true</string>
|
||||||
<key>NSCameraUsageDescription</key>
|
<key>NSCameraUsageDescription</key>
|
||||||
|
|
|
@ -66,6 +66,9 @@ public class MainApp extends Application {
|
||||||
|
|
||||||
if(Config.get().getServerType() == null && Config.get().getCoreServer() == null && Config.get().getElectrumServer() != null) {
|
if(Config.get().getServerType() == null && Config.get().getCoreServer() == null && Config.get().getElectrumServer() != null) {
|
||||||
Config.get().setServerType(ServerType.ELECTRUM_SERVER);
|
Config.get().setServerType(ServerType.ELECTRUM_SERVER);
|
||||||
|
} else if(Config.get().getServerType() == ServerType.BITCOIN_CORE && Config.get().getCoreWallet() == null) {
|
||||||
|
Config.get().setCoreMultiWallet(Boolean.TRUE);
|
||||||
|
Config.get().setCoreWallet("");
|
||||||
}
|
}
|
||||||
|
|
||||||
AppController appController = AppServices.newAppWindow(stage);
|
AppController appController = AppServices.newAppWindow(stage);
|
||||||
|
|
|
@ -44,6 +44,7 @@ public class Config {
|
||||||
private CoreAuthType coreAuthType;
|
private CoreAuthType coreAuthType;
|
||||||
private File coreDataDir;
|
private File coreDataDir;
|
||||||
private String coreAuth;
|
private String coreAuth;
|
||||||
|
private Boolean coreMultiWallet;
|
||||||
private String coreWallet;
|
private String coreWallet;
|
||||||
private String electrumServer;
|
private String electrumServer;
|
||||||
private File electrumServerCert;
|
private File electrumServerCert;
|
||||||
|
@ -298,12 +299,21 @@ public class Config {
|
||||||
flush();
|
flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Boolean getCoreMultiWallet() {
|
||||||
|
return coreMultiWallet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCoreMultiWallet(Boolean coreMultiWallet) {
|
||||||
|
this.coreMultiWallet = coreMultiWallet;
|
||||||
|
flush();
|
||||||
|
}
|
||||||
|
|
||||||
public String getCoreWallet() {
|
public String getCoreWallet() {
|
||||||
return coreWallet;
|
return coreWallet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCoreWallet(String coreWallet) {
|
public void setCoreWallet(String coreWallet) {
|
||||||
this.coreWallet = (coreWallet == null || coreWallet.isEmpty() ? null : coreWallet);
|
this.coreWallet = coreWallet;
|
||||||
flush();
|
flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,12 +25,16 @@ import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class Bwt {
|
public class Bwt {
|
||||||
private static final Logger log = LoggerFactory.getLogger(Bwt.class);
|
private static final Logger log = LoggerFactory.getLogger(Bwt.class);
|
||||||
|
|
||||||
|
public static final String DEFAULT_CORE_WALLET = "sparrow";
|
||||||
private static final int IMPORT_BATCH_SIZE = 350;
|
private static final int IMPORT_BATCH_SIZE = 350;
|
||||||
|
private static boolean initialized;
|
||||||
private Long shutdownPtr;
|
private Long shutdownPtr;
|
||||||
private boolean terminating;
|
private boolean terminating;
|
||||||
private boolean ready;
|
private boolean ready;
|
||||||
|
|
||||||
static {
|
public synchronized static void initialize() {
|
||||||
|
if(!initialized) {
|
||||||
try {
|
try {
|
||||||
org.controlsfx.tools.Platform platform = org.controlsfx.tools.Platform.getCurrent();
|
org.controlsfx.tools.Platform platform = org.controlsfx.tools.Platform.getCurrent();
|
||||||
if(platform == org.controlsfx.tools.Platform.OSX) {
|
if(platform == org.controlsfx.tools.Platform.OSX) {
|
||||||
|
@ -40,10 +44,12 @@ public class Bwt {
|
||||||
} else {
|
} else {
|
||||||
NativeUtils.loadLibraryFromJar("/native/linux/x64/libbwt_jni.so");
|
NativeUtils.loadLibraryFromJar("/native/linux/x64/libbwt_jni.so");
|
||||||
}
|
}
|
||||||
|
initialized = true;
|
||||||
} catch(IOException e) {
|
} catch(IOException e) {
|
||||||
log.error("Error loading bwt library", e);
|
log.error("Error loading bwt library", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void start(CallbackNotifier callback) {
|
private void start(CallbackNotifier callback) {
|
||||||
start(Collections.emptyList(), null, null, null, callback);
|
start(Collections.emptyList(), null, null, null, callback);
|
||||||
|
@ -111,9 +117,10 @@ public class Bwt {
|
||||||
} else {
|
} else {
|
||||||
bwtConfig.bitcoindAuth = config.getCoreAuth();
|
bwtConfig.bitcoindAuth = config.getCoreAuth();
|
||||||
}
|
}
|
||||||
if(config.getCoreWallet() != null && !config.getCoreWallet().isEmpty()) {
|
if(config.getCoreMultiWallet() != Boolean.FALSE) {
|
||||||
bwtConfig.bitcoindWallet = config.getCoreWallet();
|
bwtConfig.bitcoindWallet = config.getCoreWallet();
|
||||||
}
|
}
|
||||||
|
bwtConfig.createWalletIfMissing = true;
|
||||||
|
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
String jsonConfig = gson.toJson(bwtConfig);
|
String jsonConfig = gson.toJson(bwtConfig);
|
||||||
|
@ -178,6 +185,9 @@ public class Bwt {
|
||||||
@SerializedName("bitcoind_wallet")
|
@SerializedName("bitcoind_wallet")
|
||||||
public String bitcoindWallet;
|
public String bitcoindWallet;
|
||||||
|
|
||||||
|
@SerializedName("create_wallet_if_missing")
|
||||||
|
public Boolean createWalletIfMissing;
|
||||||
|
|
||||||
@SerializedName("descriptors")
|
@SerializedName("descriptors")
|
||||||
public List<String> descriptors;
|
public List<String> descriptors;
|
||||||
|
|
||||||
|
|
|
@ -779,6 +779,7 @@ public class ElectrumServer {
|
||||||
private final Bwt bwt = new Bwt();
|
private final Bwt bwt = new Bwt();
|
||||||
private final ReentrantLock bwtStartLock = new ReentrantLock();
|
private final ReentrantLock bwtStartLock = new ReentrantLock();
|
||||||
private final Condition bwtStartCondition = bwtStartLock.newCondition();
|
private final Condition bwtStartCondition = bwtStartLock.newCondition();
|
||||||
|
private Throwable bwtStartException;
|
||||||
private final StringProperty statusProperty = new SimpleStringProperty();
|
private final StringProperty statusProperty = new SimpleStringProperty();
|
||||||
|
|
||||||
public ConnectionService() {
|
public ConnectionService() {
|
||||||
|
@ -796,10 +797,14 @@ public class ElectrumServer {
|
||||||
ElectrumServer electrumServer = new ElectrumServer();
|
ElectrumServer electrumServer = new ElectrumServer();
|
||||||
|
|
||||||
if(Config.get().getServerType() == ServerType.BITCOIN_CORE) {
|
if(Config.get().getServerType() == ServerType.BITCOIN_CORE) {
|
||||||
|
Bwt.initialize();
|
||||||
|
|
||||||
if(!bwt.isRunning()) {
|
if(!bwt.isRunning()) {
|
||||||
Bwt.ConnectionService bwtConnectionService = bwt.getConnectionService(subscribe ? AppServices.get().getOpenWallets().keySet() : null);
|
Bwt.ConnectionService bwtConnectionService = bwt.getConnectionService(subscribe ? AppServices.get().getOpenWallets().keySet() : null);
|
||||||
|
bwtStartException = null;
|
||||||
bwtConnectionService.setOnFailed(workerStateEvent -> {
|
bwtConnectionService.setOnFailed(workerStateEvent -> {
|
||||||
log.error("Failed to start BWT", workerStateEvent.getSource().getException());
|
log.error("Failed to start BWT", workerStateEvent.getSource().getException());
|
||||||
|
bwtStartException = workerStateEvent.getSource().getException();
|
||||||
try {
|
try {
|
||||||
bwtStartLock.lock();
|
bwtStartLock.lock();
|
||||||
bwtStartCondition.signal();
|
bwtStartCondition.signal();
|
||||||
|
@ -813,9 +818,13 @@ public class ElectrumServer {
|
||||||
bwtStartLock.lock();
|
bwtStartLock.lock();
|
||||||
bwtStartCondition.await();
|
bwtStartCondition.await();
|
||||||
|
|
||||||
if(!bwt.isRunning()) {
|
if(!bwt.isReady()) {
|
||||||
|
if(bwtStartException != null && bwtStartException.getMessage().contains("Wallet file not specified")) {
|
||||||
|
throw new ServerException("Bitcoin Core requires Multi-Wallet to be enabled in the Server Preferences");
|
||||||
|
} else {
|
||||||
throw new ServerException("Check if Bitcoin Core is running, and the authentication details are correct.");
|
throw new ServerException("Check if Bitcoin Core is running, and the authentication details are correct.");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch(InterruptedException e) {
|
} catch(InterruptedException e) {
|
||||||
Thread.currentThread().interrupt();
|
Thread.currentThread().interrupt();
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -205,10 +205,8 @@ public class ServerPreferencesController extends PreferencesDetailController {
|
||||||
});
|
});
|
||||||
|
|
||||||
coreMultiWallet.selectedProperty().addListener((observable, oldValue, newValue) -> {
|
coreMultiWallet.selectedProperty().addListener((observable, oldValue, newValue) -> {
|
||||||
coreWallet.setText(" ");
|
config.setCoreMultiWallet(newValue);
|
||||||
coreWallet.setText("");
|
|
||||||
coreWallet.setDisable(!newValue);
|
coreWallet.setDisable(!newValue);
|
||||||
coreWallet.setPromptText(newValue ? "" : "Default");
|
|
||||||
});
|
});
|
||||||
|
|
||||||
electrumUseSsl.selectedProperty().addListener((observable, oldValue, newValue) -> {
|
electrumUseSsl.selectedProperty().addListener((observable, oldValue, newValue) -> {
|
||||||
|
@ -307,12 +305,15 @@ public class ServerPreferencesController extends PreferencesDetailController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
coreMultiWallet.setSelected(true);
|
coreWallet.setPromptText("Default");
|
||||||
coreMultiWallet.setSelected(config.getCoreWallet() != null);
|
if(config.getCoreWallet() == null) {
|
||||||
if(config.getCoreWallet() != null) {
|
coreWallet.setText(Bwt.DEFAULT_CORE_WALLET);
|
||||||
|
} else {
|
||||||
coreWallet.setText(config.getCoreWallet());
|
coreWallet.setText(config.getCoreWallet());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
coreMultiWallet.setSelected(config.getCoreMultiWallet() != Boolean.FALSE);
|
||||||
|
|
||||||
String electrumServer = config.getElectrumServer();
|
String electrumServer = config.getElectrumServer();
|
||||||
if(electrumServer != null) {
|
if(electrumServer != null) {
|
||||||
Protocol protocol = Protocol.getProtocol(electrumServer);
|
Protocol protocol = Protocol.getProtocol(electrumServer);
|
||||||
|
@ -452,10 +453,6 @@ public class ServerPreferencesController extends PreferencesDetailController {
|
||||||
(Control c, String newValue) -> ValidationResult.fromErrorIf( c, "Core pass required", coreAuthToggleGroup.getSelectedToggle().getUserData() == CoreAuthType.USERPASS && newValue.isEmpty())
|
(Control c, String newValue) -> ValidationResult.fromErrorIf( c, "Core pass required", coreAuthToggleGroup.getSelectedToggle().getUserData() == CoreAuthType.USERPASS && newValue.isEmpty())
|
||||||
));
|
));
|
||||||
|
|
||||||
validationSupport.registerValidator(coreWallet, Validator.combine(
|
|
||||||
(Control c, String newValue) -> ValidationResult.fromErrorIf( c, "Core wallet required", coreMultiWallet.isSelected() && newValue.isEmpty())
|
|
||||||
));
|
|
||||||
|
|
||||||
validationSupport.registerValidator(electrumHost, Validator.combine(
|
validationSupport.registerValidator(electrumHost, Validator.combine(
|
||||||
(Control c, String newValue) -> ValidationResult.fromErrorIf( c, "Invalid Electrum host", getHost(newValue) == null)
|
(Control c, String newValue) -> ValidationResult.fromErrorIf( c, "Invalid Electrum host", getHost(newValue) == null)
|
||||||
));
|
));
|
||||||
|
|
|
@ -89,7 +89,7 @@
|
||||||
<PasswordField fx:id="corePass"/>
|
<PasswordField fx:id="corePass"/>
|
||||||
</Field>
|
</Field>
|
||||||
<Field text="Multi-Wallet:">
|
<Field text="Multi-Wallet:">
|
||||||
<UnlabeledToggleSwitch fx:id="coreMultiWallet"/> <HelpLabel helpText="Enable this if using multiple Bitcoin Core wallets" />
|
<UnlabeledToggleSwitch fx:id="coreMultiWallet"/> <HelpLabel helpText="Creates a new Bitcoin Core wallet with the following name (recommended to avoid conflicts)" />
|
||||||
</Field>
|
</Field>
|
||||||
<Field text="Wallet Name:" styleClass="label-button">
|
<Field text="Wallet Name:" styleClass="label-button">
|
||||||
<TextField fx:id="coreWallet"/>
|
<TextField fx:id="coreWallet"/>
|
||||||
|
|
Binary file not shown.
Loading…
Reference in a new issue