From 658ab2f81c2e1077ca4df22892a85643fa0c849a Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Tue, 28 Jul 2020 08:31:11 +0200 Subject: [PATCH] finalize psbt once signing animation is complete --- drongo | 2 +- .../sparrow/control/SignaturesProgressBar.java | 10 +++++++++- .../sparrow/event/KeystoreSignedEvent.java | 18 ++++++++++++++++++ .../sparrow/event/PSBTFinalizedEvent.java | 13 +++++++++++++ .../sparrow/event/PSBTSignedEvent.java | 4 ++++ .../sparrow/transaction/HeadersController.java | 10 ++++++++++ .../sparrow/transaction/InputController.java | 9 +++++++++ .../sparrow/transaction/InputsController.java | 8 ++++++++ 8 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/sparrowwallet/sparrow/event/KeystoreSignedEvent.java create mode 100644 src/main/java/com/sparrowwallet/sparrow/event/PSBTFinalizedEvent.java diff --git a/drongo b/drongo index 15beeefc..3ce23948 160000 --- a/drongo +++ b/drongo @@ -1 +1 @@ -Subproject commit 15beeefcb687c77adddbfe5e2b74c75b2c6f2196 +Subproject commit 3ce2394813749be99e79f4f0253f2636fab9df91 diff --git a/src/main/java/com/sparrowwallet/sparrow/control/SignaturesProgressBar.java b/src/main/java/com/sparrowwallet/sparrow/control/SignaturesProgressBar.java index f1ba187a..87522de1 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/SignaturesProgressBar.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/SignaturesProgressBar.java @@ -1,6 +1,8 @@ package com.sparrowwallet.sparrow.control; import com.sparrowwallet.drongo.wallet.Keystore; +import com.sparrowwallet.sparrow.EventManager; +import com.sparrowwallet.sparrow.event.KeystoreSignedEvent; import javafx.animation.KeyFrame; import javafx.animation.KeyValue; import javafx.animation.Timeline; @@ -100,6 +102,10 @@ public class SignaturesProgressBar extends SegmentedBar { + segment.signatureCompleted(); + }, new KeyValue(progressBar.progressProperty(), 1)) ); timeline.setCycleCount(1); timeline.play(); diff --git a/src/main/java/com/sparrowwallet/sparrow/event/KeystoreSignedEvent.java b/src/main/java/com/sparrowwallet/sparrow/event/KeystoreSignedEvent.java new file mode 100644 index 00000000..9df108c7 --- /dev/null +++ b/src/main/java/com/sparrowwallet/sparrow/event/KeystoreSignedEvent.java @@ -0,0 +1,18 @@ +package com.sparrowwallet.sparrow.event; + +import com.sparrowwallet.drongo.wallet.Keystore; + +/** + * This event is used to indicate the animation for signing a keystore is complete + */ +public class KeystoreSignedEvent { + private final Keystore keystore; + + public KeystoreSignedEvent(Keystore keystore) { + this.keystore = keystore; + } + + public Keystore getKeystore() { + return keystore; + } +} diff --git a/src/main/java/com/sparrowwallet/sparrow/event/PSBTFinalizedEvent.java b/src/main/java/com/sparrowwallet/sparrow/event/PSBTFinalizedEvent.java new file mode 100644 index 00000000..727774ea --- /dev/null +++ b/src/main/java/com/sparrowwallet/sparrow/event/PSBTFinalizedEvent.java @@ -0,0 +1,13 @@ +package com.sparrowwallet.sparrow.event; + +import com.sparrowwallet.drongo.psbt.PSBT; + +/** + * This event is fired once the signing animation has finished and the PSBT has been finalized + * + */ +public class PSBTFinalizedEvent extends PSBTEvent { + public PSBTFinalizedEvent(PSBT psbt) { + super(psbt); + } +} diff --git a/src/main/java/com/sparrowwallet/sparrow/event/PSBTSignedEvent.java b/src/main/java/com/sparrowwallet/sparrow/event/PSBTSignedEvent.java index b0fc2440..c331b651 100644 --- a/src/main/java/com/sparrowwallet/sparrow/event/PSBTSignedEvent.java +++ b/src/main/java/com/sparrowwallet/sparrow/event/PSBTSignedEvent.java @@ -2,6 +2,10 @@ package com.sparrowwallet.sparrow.event; import com.sparrowwallet.drongo.psbt.PSBT; +/** + * This event is used by the DeviceSignDialog to indicate that a USB device has signed a PSBT + * + */ public class PSBTSignedEvent extends PSBTEvent { private final PSBT signedPsbt; diff --git a/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java b/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java index ea102b14..a7f8fe15 100644 --- a/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java +++ b/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java @@ -646,4 +646,14 @@ public class HeadersController extends TransactionFormController implements Init updateSignedKeystores(headersForm.getSigningWallet()); } } + + @Subscribe + public void keystoreSigned(KeystoreSignedEvent event) { + if(headersForm.getSignedKeystores().contains(event.getKeystore()) && headersForm.getPsbt() != null) { + if(headersForm.getPsbt().isSigned()) { + headersForm.getSigningWallet().finalise(headersForm.getPsbt()); + EventManager.get().post(new PSBTFinalizedEvent(headersForm.getPsbt())); + } + } + } } \ No newline at end of file diff --git a/src/main/java/com/sparrowwallet/sparrow/transaction/InputController.java b/src/main/java/com/sparrowwallet/sparrow/transaction/InputController.java index dbab2104..eb4426f7 100644 --- a/src/main/java/com/sparrowwallet/sparrow/transaction/InputController.java +++ b/src/main/java/com/sparrowwallet/sparrow/transaction/InputController.java @@ -526,4 +526,13 @@ public class InputController extends TransactionFormController implements Initia updateSignatures(inputForm.getPsbtInput()); } } + + @Subscribe + public void psbtFinalized(PSBTFinalizedEvent event) { + if(event.getPsbt().equals(inputForm.getPsbt())) { + updateSpends(inputForm.getPsbtInput().getUtxo()); + updateScriptFields(inputForm.getTransactionInput(), inputForm.getPsbtInput()); + updateSignatures(inputForm.getPsbtInput()); + } + } } diff --git a/src/main/java/com/sparrowwallet/sparrow/transaction/InputsController.java b/src/main/java/com/sparrowwallet/sparrow/transaction/InputsController.java index b713681d..871b8e7c 100644 --- a/src/main/java/com/sparrowwallet/sparrow/transaction/InputsController.java +++ b/src/main/java/com/sparrowwallet/sparrow/transaction/InputsController.java @@ -12,6 +12,7 @@ import com.sparrowwallet.sparrow.control.CopyableLabel; import com.sparrowwallet.sparrow.event.BitcoinUnitChangedEvent; import com.sparrowwallet.sparrow.event.BlockTransactionFetchedEvent; import com.sparrowwallet.sparrow.event.PSBTCombinedEvent; +import com.sparrowwallet.sparrow.event.PSBTFinalizedEvent; import javafx.collections.ListChangeListener; import javafx.fxml.FXML; import javafx.fxml.Initializable; @@ -180,4 +181,11 @@ public class InputsController extends TransactionFormController implements Initi updatePSBTInputs(inputsForm.getPsbt()); } } + + @Subscribe + public void psbtFinalized(PSBTFinalizedEvent event) { + if(event.getPsbt().equals(inputsForm.getPsbt())) { + updatePSBTInputs(inputsForm.getPsbt()); + } + } }