Browse Source

wallet load order, dont clear history on trivial changes

bwt
Craig Raw 4 years ago
parent
commit
47855228d3
  1. 2
      drongo
  2. 6
      src/main/java/com/sparrowwallet/sparrow/AppController.java
  3. 14
      src/main/java/com/sparrowwallet/sparrow/MainApp.java
  4. 3
      src/main/java/com/sparrowwallet/sparrow/control/QRScanDialog.java
  5. 7
      src/main/java/com/sparrowwallet/sparrow/transaction/InputController.java
  6. 1
      src/main/java/com/sparrowwallet/sparrow/ur/UR.java
  7. 48
      src/main/java/com/sparrowwallet/sparrow/wallet/SettingsWalletForm.java
  8. 5
      src/main/resources/com/sparrowwallet/sparrow/transaction/input.fxml

2
drongo

@ -1 +1 @@
Subproject commit 6da818606a506e43bdafcfea93cad85d8cf82f74
Subproject commit 55717c31bf8046e558ee90a5997c1de769517813

6
src/main/java/com/sparrowwallet/sparrow/AppController.java

@ -1067,11 +1067,11 @@ public class AppController implements Initializable {
text += event.getValueAsText(event.getTotalValue());
} else {
if(event.getTotalBlockchainValue() > 0 && event.getTotalMempoolValue() > 0) {
text = "New transactions: " + event.getValueAsText(event.getTotalValue()) + " (" + event.getValueAsText(event.getTotalMempoolValue()) + " in mempool)";
text = "New transactions: " + event.getValueAsText(event.getTotalValue()) + " total (" + event.getValueAsText(event.getTotalMempoolValue()) + " in mempool)";
} else if(event.getTotalMempoolValue() > 0) {
text = "New mempool transactions: " + event.getValueAsText(event.getTotalMempoolValue());
text = "New mempool transactions: " + event.getValueAsText(event.getTotalMempoolValue()) + " total";
} else {
text = "New transactions: " + event.getValueAsText(event.getTotalValue());
text = "New transactions: " + event.getValueAsText(event.getTotalValue()) + " total";
}
}

14
src/main/java/com/sparrowwallet/sparrow/MainApp.java

@ -4,6 +4,8 @@ import com.sparrowwallet.sparrow.control.WelcomeDialog;
import com.sparrowwallet.sparrow.glyphfont.FontAwesome5;
import com.sparrowwallet.sparrow.glyphfont.FontAwesome5Brands;
import com.sparrowwallet.sparrow.io.Config;
import com.sparrowwallet.sparrow.io.FileType;
import com.sparrowwallet.sparrow.io.IOUtils;
import com.sparrowwallet.sparrow.preferences.PreferenceGroup;
import com.sparrowwallet.sparrow.preferences.PreferencesDialog;
import javafx.application.Application;
@ -18,8 +20,11 @@ import org.controlsfx.glyphfont.GlyphFontRegistry;
import org.slf4j.LoggerFactory;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
public class MainApp extends Application {
public static final String APP_NAME = "Sparrow";
@ -82,7 +87,14 @@ public class MainApp extends Application {
List<File> recentWalletFiles = Config.get().getRecentWalletFiles();
if(recentWalletFiles != null) {
for(File walletFile : recentWalletFiles) {
//Resort to preserve wallet order as far as possible. Unencrypted wallets will still be opened first.
List<File> encryptedWalletFiles = recentWalletFiles.stream().filter(file -> FileType.BINARY.equals(IOUtils.getFileType(file))).collect(Collectors.toList());
Collections.reverse(encryptedWalletFiles);
List<File> sortedWalletFiles = new ArrayList<>(recentWalletFiles);
sortedWalletFiles.removeAll(encryptedWalletFiles);
sortedWalletFiles.addAll(encryptedWalletFiles);
for(File walletFile : sortedWalletFiles) {
if(walletFile.exists()) {
Platform.runLater(() -> appController.openWalletFile(walletFile));
}

3
src/main/java/com/sparrowwallet/sparrow/control/QRScanDialog.java

@ -75,7 +75,8 @@ public class QRScanDialog extends Dialog<QRScanDialog.Result> {
if(decoder.getResult() != null) {
URDecoder.Result urResult = decoder.getResult();
if(urResult.type == ResultType.SUCCESS) {
if(urResult.ur.getType().equals(UR.BYTES_TYPE)) {
//TODO: Confirm once UR type registry is updated
if(urResult.ur.getType().contains(UR.BYTES_TYPE) || urResult.ur.getType().equals(UR.CRYPTO_PSBT_TYPE)) {
try {
PSBT psbt = new PSBT(urResult.ur.toBytes());
result = new Result(psbt);

7
src/main/java/com/sparrowwallet/sparrow/transaction/InputController.java

@ -42,9 +42,6 @@ public class InputController extends TransactionFormController implements Initia
@FXML
private Hyperlink linkedOutpoint;
@FXML
private Button outpointSelect;
@FXML
private CoinLabel spends;
@ -143,7 +140,6 @@ public class InputController extends TransactionFormController implements Initia
if(txInput.isCoinBase()) {
outpoint.setText("Coinbase");
outpointSelect.setVisible(false);
long totalAmt = 0;
for(TransactionOutput output : inputForm.getTransaction().getOutputs()) {
totalAmt += output.getValue();
@ -164,9 +160,6 @@ public class InputController extends TransactionFormController implements Initia
} else if(inputForm.getInputTransactions() != null) {
updateSpends(inputForm.getInputTransactions());
}
//TODO: Enable select outpoint when wallet present
outpointSelect.setDisable(true);
}
private void updateOutpoint(Map<Sha256Hash, BlockTransaction> inputTransactions) {

1
src/main/java/com/sparrowwallet/sparrow/ur/UR.java

@ -19,6 +19,7 @@ import java.util.Objects;
public class UR {
public static final String UR_PREFIX = "ur";
public static final String BYTES_TYPE = "bytes";
public static final String CRYPTO_PSBT_TYPE = "crypto-psbt";
private final String type;
private final byte[] data;

48
src/main/java/com/sparrowwallet/sparrow/wallet/SettingsWalletForm.java

@ -1,5 +1,6 @@
package com.sparrowwallet.sparrow.wallet;
import com.sparrowwallet.drongo.wallet.Keystore;
import com.sparrowwallet.drongo.wallet.Wallet;
import com.sparrowwallet.sparrow.EventManager;
import com.sparrowwallet.sparrow.event.WalletSettingsChangedEvent;
@ -31,10 +32,51 @@ public class SettingsWalletForm extends WalletForm {
@Override
public void saveAndRefresh() throws IOException {
//TODO: Detect trivial changes and don't clear everything
walletCopy.clearNodes();
boolean refreshAll = changesScriptHashes(wallet, walletCopy);
if(refreshAll) {
walletCopy.clearNodes();
}
wallet = walletCopy.copy();
save();
EventManager.get().post(new WalletSettingsChangedEvent(wallet, getWalletFile()));
if(refreshAll) {
EventManager.get().post(new WalletSettingsChangedEvent(wallet, getWalletFile()));
}
}
private boolean changesScriptHashes(Wallet original, Wallet changed) {
if(!original.isValid() || !changed.isValid()) {
return true;
}
if(original.getPolicyType() != changed.getPolicyType()) {
return true;
}
if(original.getScriptType() != changed.getScriptType()) {
return true;
}
//TODO: Determine if Miniscript has changed for custom policies
if(original.getKeystores().size() != changed.getKeystores().size()) {
return true;
}
for(int i = 0; i < original.getKeystores().size(); i++) {
Keystore originalKeystore = original.getKeystores().get(i);
Keystore changedKeystore = changed.getKeystores().get(i);
if(!originalKeystore.getKeyDerivation().equals(changedKeystore.getKeyDerivation())) {
return true;
}
if(!originalKeystore.getExtendedPublicKey().equals(changedKeystore.getExtendedPublicKey())) {
return true;
}
}
return false;
}
}

5
src/main/resources/com/sparrowwallet/sparrow/transaction/input.fxml

@ -35,11 +35,6 @@
<Field text="Outpoint:" styleClass="label-button">
<IdLabel fx:id="outpoint" />
<Hyperlink fx:id="linkedOutpoint" styleClass="id" visible="false" />
<Button fx:id="outpointSelect" maxWidth="25" minWidth="-Infinity" prefWidth="30" text="Ed">
<graphic>
<Glyph fontFamily="FontAwesome" icon="EDIT" prefWidth="15" />
</graphic>
</Button>
</Field>
<Field text="Spends:">
<CoinLabel fx:id="spends" />

Loading…
Cancel
Save