diff --git a/drongo b/drongo index 488752c1..9faacb05 160000 --- a/drongo +++ b/drongo @@ -1 +1 @@ -Subproject commit 488752c142765bacd0373390faccbdb11b47487a +Subproject commit 9faacb055c635d22ce0dd7318f2b87814da85bcd diff --git a/src/main/java/com/sparrowwallet/sparrow/event/SettingsChangedEvent.java b/src/main/java/com/sparrowwallet/sparrow/event/SettingsChangedEvent.java index bf5c79b4..63c1a93b 100644 --- a/src/main/java/com/sparrowwallet/sparrow/event/SettingsChangedEvent.java +++ b/src/main/java/com/sparrowwallet/sparrow/event/SettingsChangedEvent.java @@ -20,6 +20,6 @@ public class SettingsChangedEvent { } public enum Type { - POLICY, SCRIPT_TYPE, MUTLISIG_THRESHOLD, MULTISIG_TOTAL, KEYSTORE_LABEL, KEYSTORE_FINGERPRINT, KEYSTORE_DERIVATION, KEYSTORE_XPUB; + POLICY, SCRIPT_TYPE, MUTLISIG_THRESHOLD, MULTISIG_TOTAL, KEYSTORE_LABEL, KEYSTORE_FINGERPRINT, KEYSTORE_DERIVATION, KEYSTORE_XPUB, GAP_LIMIT; } } diff --git a/src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java b/src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java index 1e551279..5208c5b8 100644 --- a/src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java +++ b/src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java @@ -137,18 +137,18 @@ public class ElectrumServer { //Because node children are added sequentially in WalletNode.fillToIndex, we can simply look at the number of children to determine the highest filled index int historySize = purposeNode.getChildren().size(); //The gap limit size takes the highest used index in the retrieved history and adds the gap limit (plus one to be comparable to the number of children since index is zero based) - int gapLimitSize = getGapLimitSize(nodeTransactionMap); + int gapLimitSize = getGapLimitSize(wallet, nodeTransactionMap); while(historySize < gapLimitSize) { purposeNode.fillToIndex(gapLimitSize - 1); getHistory(wallet, purposeNode.getChildren(), nodeTransactionMap, historySize); historySize = purposeNode.getChildren().size(); - gapLimitSize = getGapLimitSize(nodeTransactionMap); + gapLimitSize = getGapLimitSize(wallet, nodeTransactionMap); } } - private int getGapLimitSize(Map> nodeTransactionMap) { + private int getGapLimitSize(Wallet wallet, Map> nodeTransactionMap) { int highestIndex = nodeTransactionMap.entrySet().stream().filter(entry -> !entry.getValue().isEmpty()).map(entry -> entry.getKey().getIndex()).max(Comparator.comparing(Integer::valueOf)).orElse(-1); - return highestIndex + Wallet.DEFAULT_LOOKAHEAD + 1; + return highestIndex + wallet.getGapLimit() + 1; } public void getHistory(Wallet wallet, Collection nodes, Map> nodeTransactionMap, int startIndex) throws ServerException { diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/AdvancedController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/AdvancedController.java new file mode 100644 index 00000000..d27c0e6a --- /dev/null +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/AdvancedController.java @@ -0,0 +1,30 @@ +package com.sparrowwallet.sparrow.wallet; + +import com.sparrowwallet.drongo.wallet.Wallet; +import com.sparrowwallet.sparrow.EventManager; +import com.sparrowwallet.sparrow.event.SettingsChangedEvent; +import javafx.fxml.FXML; +import javafx.fxml.Initializable; +import javafx.scene.control.Spinner; +import javafx.scene.control.SpinnerValueFactory; + +import java.net.URL; +import java.util.ResourceBundle; + +public class AdvancedController implements Initializable { + @FXML + private Spinner gapLimit; + + @Override + public void initialize(URL location, ResourceBundle resources) { + + } + + public void initializeView(Wallet wallet) { + gapLimit.setValueFactory(new SpinnerValueFactory.IntegerSpinnerValueFactory(Wallet.DEFAULT_LOOKAHEAD, 10000, wallet.getGapLimit())); + gapLimit.valueProperty().addListener((observable, oldValue, newValue) -> { + wallet.setGapLimit(newValue); + EventManager.get().post(new SettingsChangedEvent(wallet, SettingsChangedEvent.Type.GAP_LIMIT)); + }); + } +} diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/AdvancedDialog.java b/src/main/java/com/sparrowwallet/sparrow/wallet/AdvancedDialog.java new file mode 100644 index 00000000..a7cfa5e6 --- /dev/null +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/AdvancedDialog.java @@ -0,0 +1,35 @@ +package com.sparrowwallet.sparrow.wallet; + +import com.sparrowwallet.drongo.wallet.Wallet; +import com.sparrowwallet.sparrow.AppController; +import javafx.fxml.FXMLLoader; +import javafx.scene.control.ButtonBar; +import javafx.scene.control.ButtonType; +import javafx.scene.control.Dialog; +import javafx.scene.control.DialogPane; +import org.controlsfx.tools.Borders; + +import java.io.IOException; + +public class AdvancedDialog extends Dialog { + public AdvancedDialog(Wallet wallet) { + final DialogPane dialogPane = getDialogPane(); + AppController.setStageIcon(dialogPane.getScene().getWindow()); + + try { + FXMLLoader advancedLoader = new FXMLLoader(AppController.class.getResource("wallet/advanced.fxml")); + dialogPane.setContent(Borders.wrap(advancedLoader.load()).lineBorder().outerPadding(0).innerPadding(0).buildAll()); + AdvancedController settingsAdvancedController = advancedLoader.getController(); + settingsAdvancedController.initializeView(wallet); + + final ButtonType closeButtonType = new javafx.scene.control.ButtonType("Close", ButtonBar.ButtonData.CANCEL_CLOSE); + dialogPane.getButtonTypes().addAll(closeButtonType); + + dialogPane.setPrefWidth(400); + dialogPane.setPrefHeight(300); + } + catch(IOException e) { + throw new RuntimeException(e); + } + } +} diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java b/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java index c9b5b3a6..6a29e540 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java @@ -21,6 +21,7 @@ import com.sparrowwallet.sparrow.event.TimedEvent; import com.sparrowwallet.sparrow.io.Storage; import javafx.beans.property.SimpleIntegerProperty; import javafx.collections.FXCollections; +import javafx.event.ActionEvent; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.fxml.Initializable; @@ -247,6 +248,11 @@ public class SettingsController extends WalletFormController implements Initiali } } + public void showAdvanced(ActionEvent event) { + AdvancedDialog advancedDialog = new AdvancedDialog(walletForm.getWallet()); + advancedDialog.showAndWait(); + } + @Override protected String describeKeystore(Keystore keystore) { if(!keystore.isValid()) { diff --git a/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsWalletForm.java b/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsWalletForm.java index 630f0a6e..bbc49984 100644 --- a/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsWalletForm.java +++ b/src/main/java/com/sparrowwallet/sparrow/wallet/SettingsWalletForm.java @@ -77,6 +77,10 @@ public class SettingsWalletForm extends WalletForm { } } + if(original.getGapLimit() != changed.getGapLimit()) { + return true; + } + return false; } } diff --git a/src/main/resources/com/sparrowwallet/sparrow/wallet/advanced.fxml b/src/main/resources/com/sparrowwallet/sparrow/wallet/advanced.fxml new file mode 100644 index 00000000..c9724666 --- /dev/null +++ b/src/main/resources/com/sparrowwallet/sparrow/wallet/advanced.fxml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + +
+ + + + + + + + + + + +
+
+ + + + +
+
+
+
+
+ diff --git a/src/main/resources/com/sparrowwallet/sparrow/wallet/settings.fxml b/src/main/resources/com/sparrowwallet/sparrow/wallet/settings.fxml index 122391c6..cfe6ddda 100644 --- a/src/main/resources/com/sparrowwallet/sparrow/wallet/settings.fxml +++ b/src/main/resources/com/sparrowwallet/sparrow/wallet/settings.fxml @@ -95,8 +95,11 @@ -