various fixes to signing

This commit is contained in:
Craig Raw 2020-08-09 12:23:59 +02:00
parent f2afd7cb69
commit a8612da463
8 changed files with 82 additions and 20 deletions

2
drongo

@ -1 +1 @@
Subproject commit 1f7be6c7d5f1cdfda58617b212630575066e5496
Subproject commit d2582c041479704d609c20ed13195c3f92ced999

View file

@ -168,19 +168,9 @@ public class AppController implements Initializable {
if(selectedTab != null) {
TabData tabData = (TabData)selectedTab.getUserData();
if(tabData.getType() == TabData.TabType.TRANSACTION) {
TransactionTabData transactionTabData = (TransactionTabData)tabData;
EventManager.get().post(new TransactionTabSelectedEvent(selectedTab));
saveTransaction.setDisable(false);
saveTransaction.setText("Save " + (transactionTabData.getPsbt() == null || transactionTabData.getPsbt().isFinalized() ? "Transaction..." : "PSBT..."));
exportWallet.setDisable(true);
showTxHex.setDisable(false);
} else if(tabData.getType() == TabData.TabType.WALLET) {
WalletTabData walletTabData = (WalletTabData)tabData;
EventManager.get().post(new WalletTabSelectedEvent(selectedTab));
saveTransaction.setDisable(true);
saveTransaction.setText("Save Transaction...");
exportWallet.setDisable(walletTabData.getWallet() == null || !walletTabData.getWallet().isValid());
showTxHex.setDisable(true);
}
}
});
@ -492,6 +482,12 @@ public class AppController implements Initializable {
String fileName = selectedTab.getText();
if(fileName != null && !fileName.isEmpty()) {
if(transactionTabData.getPsbt() != null && !fileName.endsWith(".psbt")) {
fileName += ".psbt";
} else if(!fileName.endsWith(".txn")) {
fileName += ".txn";
}
if(saveTx && fileName.endsWith(".psbt")) {
fileName = fileName.replace(".psbt", "") + ".txn";
}
@ -919,13 +915,40 @@ public class AppController implements Initializable {
@Subscribe
public void tabSelected(TabSelectedEvent event) {
Tab selectedTab = event.getTab();
String tabName = selectedTab.getText();
String tabName = event.getTabName();
if(tabs.getScene() != null) {
Stage tabStage = (Stage)tabs.getScene().getWindow();
tabStage.setTitle("Sparrow - " + tabName);
}
if(event instanceof TransactionTabSelectedEvent) {
TransactionTabSelectedEvent txTabEvent = (TransactionTabSelectedEvent)event;
TransactionTabData transactionTabData = txTabEvent.getTransactionTabData();
saveTransaction.setDisable(false);
saveTransaction.setText("Save " + (transactionTabData.getPsbt() == null || transactionTabData.getPsbt().isFinalized() ? "Transaction..." : "PSBT..."));
exportWallet.setDisable(true);
showTxHex.setDisable(false);
} else if(event instanceof WalletTabSelectedEvent) {
WalletTabSelectedEvent walletTabEvent = (WalletTabSelectedEvent)event;
WalletTabData walletTabData = walletTabEvent.getWalletTabData();
saveTransaction.setDisable(true);
saveTransaction.setText("Save Transaction...");
exportWallet.setDisable(walletTabData.getWallet() == null || !walletTabData.getWallet().isValid());
showTxHex.setDisable(true);
}
}
@Subscribe
public void psbtFinalizedEvent(PSBTFinalizedEvent event) {
for(Tab tab : tabs.getTabs()) {
TabData tabData = (TabData) tab.getUserData();
if(tabData instanceof TransactionTabData) {
TransactionTabData transactionTabData = (TransactionTabData)tabData;
if(Arrays.equals(transactionTabData.getTransaction().bitcoinSerialize(), event.getPsbt().getTransaction().bitcoinSerialize())) {
saveTransaction.setText("Save Transaction...");
}
}
}
}
@Subscribe
@ -1113,6 +1136,8 @@ public class AppController implements Initializable {
if(!deviceEnumerateService.isRunning()) {
deviceEnumerateService.start();
}
break;
}
}

View file

@ -399,7 +399,7 @@ public class DevicePane extends TitledDescriptionPane {
EventManager.get().post(new KeystoreImportEvent(keystore));
});
getXpubService.setOnFailed(workerStateEvent -> {
setError(getXpubService.getException().getMessage(), null);
setError("Could not retrieve xpub", getXpubService.getException().getMessage());
importButton.setDisable(false);
});
setDescription("Importing...");
@ -414,7 +414,7 @@ public class DevicePane extends TitledDescriptionPane {
EventManager.get().post(new PSBTSignedEvent(psbt, signedPsbt));
});
signPSBTService.setOnFailed(workerStateEvent -> {
setError(signPSBTService.getException().getMessage(), null);
setError("Signing Error", signPSBTService.getException().getMessage());
signButton.setDisable(false);
});
setDescription("Signing...");
@ -429,7 +429,7 @@ public class DevicePane extends TitledDescriptionPane {
EventManager.get().post(new AddressDisplayedEvent(address));
});
displayAddressService.setOnFailed(failedEvent -> {
setError(displayAddressService.getException().getMessage(), null);
setError("Could not display address", displayAddressService.getException().getMessage());
displayAddressButton.setDisable(false);
});
setDescription("Check device for address");

View file

@ -12,6 +12,9 @@ import javafx.scene.layout.HBox;
import javafx.scene.layout.Priority;
import javafx.scene.layout.VBox;
import java.util.Arrays;
import java.util.OptionalDouble;
public class TitledDescriptionPane extends TitledPane {
private Label descriptionLabel;
protected Hyperlink showHideLink;
@ -123,6 +126,13 @@ public class TitledDescriptionPane extends TitledPane {
double width = TextUtils.computeTextWidth(details.getFont(), message, 0.0D);
double numLines = Math.max(1, width / 400);
//Handle long words like txids
OptionalDouble maxWordLength = Arrays.stream(message.split(" ")).mapToDouble(word -> TextUtils.computeTextWidth(details.getFont(), message, 0.0D)).max();
if(maxWordLength.isPresent() && maxWordLength.getAsDouble() > 300.0) {
numLines += 1.0;
}
double height = Math.max(60, numLines * 40);
contentBox.setPrefHeight(height);

View file

@ -1,9 +1,10 @@
package com.sparrowwallet.sparrow.event;
import com.sparrowwallet.sparrow.TabData;
import javafx.scene.control.Tab;
public class TabEvent {
private Tab tab;
private final Tab tab;
public TabEvent(Tab tab) {
this.tab = tab;
@ -12,4 +13,12 @@ public class TabEvent {
public Tab getTab() {
return tab;
}
public String getTabName() {
return tab.getText();
}
public TabData getTabData() {
return (TabData)tab.getUserData();
}
}

View file

@ -1,9 +1,14 @@
package com.sparrowwallet.sparrow.event;
import com.sparrowwallet.sparrow.TransactionTabData;
import javafx.scene.control.Tab;
public class TransactionTabSelectedEvent extends TabSelectedEvent {
public TransactionTabSelectedEvent(Tab tab) {
super(tab);
}
public TransactionTabData getTransactionTabData() {
return (TransactionTabData)getTabData();
}
}

View file

@ -1,9 +1,14 @@
package com.sparrowwallet.sparrow.event;
import com.sparrowwallet.sparrow.WalletTabData;
import javafx.scene.control.Tab;
public class WalletTabSelectedEvent extends TabSelectedEvent {
public WalletTabSelectedEvent(Tab tab) {
super(tab);
}
public WalletTabData getWalletTabData() {
return (WalletTabData)getTabData();
}
}

View file

@ -20,13 +20,21 @@ public class InputForm extends IndexedTransactionForm {
}
public TransactionInput getTransactionInput() {
if(txdata.getTransaction() != null) {
return txdata.getTransaction().getInputs().get(getIndex());
}
return null;
}
public PSBTInput getPsbtInput() {
if(txdata.getPsbt() != null) {
return txdata.getPsbt().getPsbtInputs().get(getIndex());
}
return null;
}
public TransactionOutput getReferencedTransactionOutput() {
if(getInputTransactions() != null) {
BlockTransaction inputTransaction = getInputTransactions().get(getTransactionInput().getOutpoint().getHash());