wallet load order, dont clear history on trivial changes

This commit is contained in:
Craig Raw 2020-08-30 11:15:45 +02:00
parent a6e41e3f9d
commit 47855228d3
8 changed files with 65 additions and 21 deletions

2
drongo

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

View file

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

View file

@ -4,6 +4,8 @@ import com.sparrowwallet.sparrow.control.WelcomeDialog;
import com.sparrowwallet.sparrow.glyphfont.FontAwesome5; import com.sparrowwallet.sparrow.glyphfont.FontAwesome5;
import com.sparrowwallet.sparrow.glyphfont.FontAwesome5Brands; import com.sparrowwallet.sparrow.glyphfont.FontAwesome5Brands;
import com.sparrowwallet.sparrow.io.Config; 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.PreferenceGroup;
import com.sparrowwallet.sparrow.preferences.PreferencesDialog; import com.sparrowwallet.sparrow.preferences.PreferencesDialog;
import javafx.application.Application; import javafx.application.Application;
@ -18,8 +20,11 @@ import org.controlsfx.glyphfont.GlyphFontRegistry;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.File; import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Collectors;
public class MainApp extends Application { public class MainApp extends Application {
public static final String APP_NAME = "Sparrow"; public static final String APP_NAME = "Sparrow";
@ -82,7 +87,14 @@ public class MainApp extends Application {
List<File> recentWalletFiles = Config.get().getRecentWalletFiles(); List<File> recentWalletFiles = Config.get().getRecentWalletFiles();
if(recentWalletFiles != null) { 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()) { if(walletFile.exists()) {
Platform.runLater(() -> appController.openWalletFile(walletFile)); Platform.runLater(() -> appController.openWalletFile(walletFile));
} }

View file

@ -75,7 +75,8 @@ public class QRScanDialog extends Dialog<QRScanDialog.Result> {
if(decoder.getResult() != null) { if(decoder.getResult() != null) {
URDecoder.Result urResult = decoder.getResult(); URDecoder.Result urResult = decoder.getResult();
if(urResult.type == ResultType.SUCCESS) { 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 { try {
PSBT psbt = new PSBT(urResult.ur.toBytes()); PSBT psbt = new PSBT(urResult.ur.toBytes());
result = new Result(psbt); result = new Result(psbt);

View file

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

View file

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

View file

@ -1,5 +1,6 @@
package com.sparrowwallet.sparrow.wallet; package com.sparrowwallet.sparrow.wallet;
import com.sparrowwallet.drongo.wallet.Keystore;
import com.sparrowwallet.drongo.wallet.Wallet; import com.sparrowwallet.drongo.wallet.Wallet;
import com.sparrowwallet.sparrow.EventManager; import com.sparrowwallet.sparrow.EventManager;
import com.sparrowwallet.sparrow.event.WalletSettingsChangedEvent; import com.sparrowwallet.sparrow.event.WalletSettingsChangedEvent;
@ -31,10 +32,51 @@ public class SettingsWalletForm extends WalletForm {
@Override @Override
public void saveAndRefresh() throws IOException { public void saveAndRefresh() throws IOException {
//TODO: Detect trivial changes and don't clear everything boolean refreshAll = changesScriptHashes(wallet, walletCopy);
walletCopy.clearNodes(); if(refreshAll) {
walletCopy.clearNodes();
}
wallet = walletCopy.copy(); wallet = walletCopy.copy();
save(); 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;
} }
} }

View file

@ -35,11 +35,6 @@
<Field text="Outpoint:" styleClass="label-button"> <Field text="Outpoint:" styleClass="label-button">
<IdLabel fx:id="outpoint" /> <IdLabel fx:id="outpoint" />
<Hyperlink fx:id="linkedOutpoint" styleClass="id" visible="false" /> <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>
<Field text="Spends:"> <Field text="Spends:">
<CoinLabel fx:id="spends" /> <CoinLabel fx:id="spends" />