From 62e7c34eb5bae3302d3c1a0f68bd83c5e8db6d6d Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Mon, 30 May 2022 16:29:09 +0200 Subject: [PATCH] show taproot specific sighash default in sighash dropdown, and select if appropriate --- drongo | 2 +- .../transaction/HeadersController.java | 26 ++++++++++++++----- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/drongo b/drongo index 7535c876..7f2c5a5a 160000 --- a/drongo +++ b/drongo @@ -1 +1 @@ -Subproject commit 7535c876bad20a82b0ef4635e97d1528d58c4ba7 +Subproject commit 7f2c5a5a59c046816b9809fc629305c7d4cfe932 diff --git a/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java b/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java index 7bc62043..f0d1aad2 100644 --- a/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java +++ b/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java @@ -484,16 +484,28 @@ public class HeadersController extends TransactionFormController implements Init noWalletsWarningLink.managedProperty().bind(noWalletsWarningLink.visibleProperty()); noWalletsWarningLink.visibleProperty().bind(noWalletsWarning.visibleProperty()); - SigHash psbtSigHash = SigHash.ALL; - for(PSBTInput psbtInput : psbt.getPsbtInputs()) { - if(psbtInput.getSigHash() != null) { - psbtSigHash = psbtInput.getSigHash(); + boolean taprootInput = psbt.getPsbtInputs().stream().anyMatch(PSBTInput::isTaproot); + SigHash psbtSigHash = psbt.getPsbtInputs().stream().map(PSBTInput::getSigHash).filter(Objects::nonNull).findFirst().orElse(taprootInput ? SigHash.DEFAULT : SigHash.ALL); + sigHash.setItems(FXCollections.observableList(taprootInput ? SigHash.TAPROOT_SIGNING_TYPES : SigHash.LEGACY_SIGNING_TYPES)); + sigHash.setValue(psbtSigHash); + sigHash.setConverter(new StringConverter<>() { + @Override + public String toString(SigHash sigHash) { + if(sigHash == null) { + return ""; + } + + return sigHash.getName() + ((taprootInput && sigHash == SigHash.DEFAULT) || (!taprootInput && sigHash == SigHash.ALL) ? " (Recommended)" : ""); } - } - sigHash.setValue(psbtSigHash == SigHash.ALL_TAPROOT ? SigHash.ALL : psbtSigHash); + + @Override + public SigHash fromString(String string) { + return null; + } + }); sigHash.valueProperty().addListener((observable, oldValue, newValue) -> { for(PSBTInput psbtInput : psbt.getPsbtInputs()) { - psbtInput.setSigHash(psbtInput.isTaproot() && newValue == SigHash.ALL ? SigHash.ALL_TAPROOT : newValue); + psbtInput.setSigHash(newValue == SigHash.DEFAULT && !psbtInput.isTaproot() ? SigHash.ALL : newValue); } });