From a8612da463b0efb8dcad401f2b51c18aede3f5b5 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Sun, 9 Aug 2020 12:23:59 +0200 Subject: [PATCH] various fixes to signing --- drongo | 2 +- .../sparrowwallet/sparrow/AppController.java | 51 ++++++++++++++----- .../sparrow/control/DevicePane.java | 6 +-- .../control/TitledDescriptionPane.java | 10 ++++ .../sparrowwallet/sparrow/event/TabEvent.java | 11 +++- .../event/TransactionTabSelectedEvent.java | 5 ++ .../sparrow/event/WalletTabSelectedEvent.java | 5 ++ .../sparrow/transaction/InputForm.java | 12 ++++- 8 files changed, 82 insertions(+), 20 deletions(-) diff --git a/drongo b/drongo index 1f7be6c7..d2582c04 160000 --- a/drongo +++ b/drongo @@ -1 +1 @@ -Subproject commit 1f7be6c7d5f1cdfda58617b212630575066e5496 +Subproject commit d2582c041479704d609c20ed13195c3f92ced999 diff --git a/src/main/java/com/sparrowwallet/sparrow/AppController.java b/src/main/java/com/sparrowwallet/sparrow/AppController.java index ce34e0d8..c38c5748 100644 --- a/src/main/java/com/sparrowwallet/sparrow/AppController.java +++ b/src/main/java/com/sparrowwallet/sparrow/AppController.java @@ -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; } } diff --git a/src/main/java/com/sparrowwallet/sparrow/control/DevicePane.java b/src/main/java/com/sparrowwallet/sparrow/control/DevicePane.java index cd26d2a4..8d37a9e8 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/DevicePane.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/DevicePane.java @@ -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"); diff --git a/src/main/java/com/sparrowwallet/sparrow/control/TitledDescriptionPane.java b/src/main/java/com/sparrowwallet/sparrow/control/TitledDescriptionPane.java index be40ab0c..654002fe 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/TitledDescriptionPane.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/TitledDescriptionPane.java @@ -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); diff --git a/src/main/java/com/sparrowwallet/sparrow/event/TabEvent.java b/src/main/java/com/sparrowwallet/sparrow/event/TabEvent.java index 680c7203..dfbc3e72 100644 --- a/src/main/java/com/sparrowwallet/sparrow/event/TabEvent.java +++ b/src/main/java/com/sparrowwallet/sparrow/event/TabEvent.java @@ -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(); + } } diff --git a/src/main/java/com/sparrowwallet/sparrow/event/TransactionTabSelectedEvent.java b/src/main/java/com/sparrowwallet/sparrow/event/TransactionTabSelectedEvent.java index 3810fc39..58127a5e 100644 --- a/src/main/java/com/sparrowwallet/sparrow/event/TransactionTabSelectedEvent.java +++ b/src/main/java/com/sparrowwallet/sparrow/event/TransactionTabSelectedEvent.java @@ -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(); + } } diff --git a/src/main/java/com/sparrowwallet/sparrow/event/WalletTabSelectedEvent.java b/src/main/java/com/sparrowwallet/sparrow/event/WalletTabSelectedEvent.java index 67460b92..e5ff2081 100644 --- a/src/main/java/com/sparrowwallet/sparrow/event/WalletTabSelectedEvent.java +++ b/src/main/java/com/sparrowwallet/sparrow/event/WalletTabSelectedEvent.java @@ -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(); + } } diff --git a/src/main/java/com/sparrowwallet/sparrow/transaction/InputForm.java b/src/main/java/com/sparrowwallet/sparrow/transaction/InputForm.java index d065c59c..e010c2b4 100644 --- a/src/main/java/com/sparrowwallet/sparrow/transaction/InputForm.java +++ b/src/main/java/com/sparrowwallet/sparrow/transaction/InputForm.java @@ -20,11 +20,19 @@ public class InputForm extends IndexedTransactionForm { } public TransactionInput getTransactionInput() { - return txdata.getTransaction().getInputs().get(getIndex()); + if(txdata.getTransaction() != null) { + return txdata.getTransaction().getInputs().get(getIndex()); + } + + return null; } public PSBTInput getPsbtInput() { - return txdata.getPsbt().getPsbtInputs().get(getIndex()); + if(txdata.getPsbt() != null) { + return txdata.getPsbt().getPsbtInputs().get(getIndex()); + } + + return null; } public TransactionOutput getReferencedTransactionOutput() {