Browse Source

configurable wallet gap limit

bwt
Craig Raw 4 years ago
parent
commit
38b27bb091
  1. 2
      drongo
  2. 2
      src/main/java/com/sparrowwallet/sparrow/event/SettingsChangedEvent.java
  3. 8
      src/main/java/com/sparrowwallet/sparrow/net/ElectrumServer.java
  4. 30
      src/main/java/com/sparrowwallet/sparrow/wallet/AdvancedController.java
  5. 35
      src/main/java/com/sparrowwallet/sparrow/wallet/AdvancedDialog.java
  6. 6
      src/main/java/com/sparrowwallet/sparrow/wallet/SettingsController.java
  7. 4
      src/main/java/com/sparrowwallet/sparrow/wallet/SettingsWalletForm.java
  8. 38
      src/main/resources/com/sparrowwallet/sparrow/wallet/advanced.fxml
  9. 7
      src/main/resources/com/sparrowwallet/sparrow/wallet/settings.fxml

2
drongo

@ -1 +1 @@
Subproject commit 488752c142765bacd0373390faccbdb11b47487a Subproject commit 9faacb055c635d22ce0dd7318f2b87814da85bcd

2
src/main/java/com/sparrowwallet/sparrow/event/SettingsChangedEvent.java

@ -20,6 +20,6 @@ public class SettingsChangedEvent {
} }
public enum Type { 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;
} }
} }

8
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 //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(); 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) //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) { while(historySize < gapLimitSize) {
purposeNode.fillToIndex(gapLimitSize - 1); purposeNode.fillToIndex(gapLimitSize - 1);
getHistory(wallet, purposeNode.getChildren(), nodeTransactionMap, historySize); getHistory(wallet, purposeNode.getChildren(), nodeTransactionMap, historySize);
historySize = purposeNode.getChildren().size(); historySize = purposeNode.getChildren().size();
gapLimitSize = getGapLimitSize(nodeTransactionMap); gapLimitSize = getGapLimitSize(wallet, nodeTransactionMap);
} }
} }
private int getGapLimitSize(Map<WalletNode, Set<BlockTransactionHash>> nodeTransactionMap) { private int getGapLimitSize(Wallet wallet, Map<WalletNode, Set<BlockTransactionHash>> nodeTransactionMap) {
int highestIndex = nodeTransactionMap.entrySet().stream().filter(entry -> !entry.getValue().isEmpty()).map(entry -> entry.getKey().getIndex()).max(Comparator.comparing(Integer::valueOf)).orElse(-1); 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<WalletNode> nodes, Map<WalletNode, Set<BlockTransactionHash>> nodeTransactionMap, int startIndex) throws ServerException { public void getHistory(Wallet wallet, Collection<WalletNode> nodes, Map<WalletNode, Set<BlockTransactionHash>> nodeTransactionMap, int startIndex) throws ServerException {

30
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<Integer> 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));
});
}
}

35
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<Void> {
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);
}
}
}

6
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 com.sparrowwallet.sparrow.io.Storage;
import javafx.beans.property.SimpleIntegerProperty; import javafx.beans.property.SimpleIntegerProperty;
import javafx.collections.FXCollections; import javafx.collections.FXCollections;
import javafx.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader; import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable; 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 @Override
protected String describeKeystore(Keystore keystore) { protected String describeKeystore(Keystore keystore) {
if(!keystore.isValid()) { if(!keystore.isValid()) {

4
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; return false;
} }
} }

38
src/main/resources/com/sparrowwallet/sparrow/wallet/advanced.fxml

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>
<?import tornadofx.control.Form?>
<?import tornadofx.control.Fieldset?>
<?import tornadofx.control.Field?>
<?import com.sparrowwallet.sparrow.control.HelpLabel?>
<?import javafx.geometry.Insets?>
<BorderPane stylesheets="@../general.css" xmlns="http://javafx.com/javafx" xmlns:fx="http://javafx.com/fxml" fx:controller="com.sparrowwallet.sparrow.wallet.AdvancedController">
<center>
<GridPane hgap="10.0" vgap="10.0">
<padding>
<Insets left="25.0" right="25.0" top="25.0" />
</padding>
<columnConstraints>
<ColumnConstraints percentWidth="100" />
</columnConstraints>
<rowConstraints>
<RowConstraints />
</rowConstraints>
<Form GridPane.columnIndex="0" GridPane.rowIndex="0">
<Fieldset inputGrow="SOMETIMES" text="Advanced Settings" styleClass="wideLabelFieldSet">
<Field text="Gap limit:">
<Spinner fx:id="gapLimit" editable="true" prefWidth="90" />
<HelpLabel helpText="Change how far ahead to look for additional transactions beyond the highest derivation with previous transaction outputs"/>
</Field>
</Fieldset>
</Form>
</GridPane>
</center>
</BorderPane>

7
src/main/resources/com/sparrowwallet/sparrow/wallet/settings.fxml

@ -95,8 +95,11 @@
<padding> <padding>
<Insets left="25.0" right="25.0" bottom="25.0" /> <Insets left="25.0" right="25.0" bottom="25.0" />
</padding> </padding>
<Button fx:id="apply" text="Apply" defaultButton="true" AnchorPane.rightAnchor="10" /> <HBox AnchorPane.rightAnchor="10" spacing="20">
<Button fx:id="revert" text="Revert" cancelButton="true" AnchorPane.rightAnchor="80" /> <Button text="Advanced..." onAction="#showAdvanced" />
<Button fx:id="revert" text="Revert" cancelButton="true" />
<Button fx:id="apply" text="Apply" defaultButton="true" />
</HBox>
</AnchorPane> </AnchorPane>
</bottom> </bottom>
</BorderPane> </BorderPane>

Loading…
Cancel
Save