From 1b220c72eaf97d361c55d452be3abaf8d040bbd9 Mon Sep 17 00:00:00 2001 From: Craig Raw Date: Wed, 4 Nov 2020 16:32:17 +0200 Subject: [PATCH] further payjoin tweaks --- .../sparrow/control/DevicePane.java | 5 +++++ .../sparrow/payjoin/Payjoin.java | 21 +++++++++---------- .../transaction/HeadersController.java | 3 +-- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/src/main/java/com/sparrowwallet/sparrow/control/DevicePane.java b/src/main/java/com/sparrowwallet/sparrow/control/DevicePane.java index 4aed8aa7..411a07f6 100644 --- a/src/main/java/com/sparrowwallet/sparrow/control/DevicePane.java +++ b/src/main/java/com/sparrowwallet/sparrow/control/DevicePane.java @@ -32,10 +32,14 @@ import org.controlsfx.validation.ValidationResult; import org.controlsfx.validation.ValidationSupport; import org.controlsfx.validation.Validator; import org.controlsfx.validation.decoration.StyleClassValidationDecoration; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.List; public class DevicePane extends TitledDescriptionPane { + private static final Logger log = LoggerFactory.getLogger(DevicePane.class); + private final DeviceOperation deviceOperation; private final Wallet wallet; private final PSBT psbt; @@ -467,6 +471,7 @@ public class DevicePane extends TitledDescriptionPane { }); signPSBTService.setOnFailed(workerStateEvent -> { setError("Signing Error", signPSBTService.getException().getMessage()); + log.error("Signing Error: " + signPSBTService.getException().getMessage()); signButton.setDisable(false); }); setDescription("Signing..."); diff --git a/src/main/java/com/sparrowwallet/sparrow/payjoin/Payjoin.java b/src/main/java/com/sparrowwallet/sparrow/payjoin/Payjoin.java index 654640d8..f6e95c87 100644 --- a/src/main/java/com/sparrowwallet/sparrow/payjoin/Payjoin.java +++ b/src/main/java/com/sparrowwallet/sparrow/payjoin/Payjoin.java @@ -35,24 +35,17 @@ public class Payjoin { public Payjoin(BitcoinURI payjoinURI, Wallet wallet, PSBT psbt) { this.payjoinURI = payjoinURI; this.wallet = wallet; - this.psbt = psbt.getPublicCopy(); + this.psbt = psbt; - for(PSBTInput psbtInput : this.psbt.getPsbtInputs()) { + for(PSBTInput psbtInput : psbt.getPsbtInputs()) { if(psbtInput.getUtxo() == null) { throw new IllegalArgumentException("Original PSBT for payjoin transaction must have non_witness_utxo or witness_utxo fields for all inputs"); } - if(!psbtInput.getDerivedPublicKeys().isEmpty()) { - throw new IllegalArgumentException("Original PSBT for payjoin transaction must have no derived public keys for all inputs"); - } } - if(!this.psbt.isFinalized()) { + if(!psbt.isFinalized()) { throw new IllegalArgumentException("Original PSBT for payjoin transaction must be finalized"); } - - if(!this.psbt.getExtendedPublicKeys().isEmpty()) { - throw new IllegalArgumentException("Original PSBT for payjoin transaction must have no global xpubs"); - } } public PSBT requestPayjoinPSBT(boolean allowOutputSubstitution) throws PayjoinReceiverException { @@ -67,7 +60,7 @@ public class Payjoin { } try { - String base64Psbt = psbt.toBase64String(); + String base64Psbt = psbt.getPublicCopy().toBase64String(); String appendQuery = "v=1"; int changeOutputIndex = getChangeOutputIndex(); @@ -175,6 +168,7 @@ public class Payjoin { proposedPSBTInput.setWitnessUtxo(originalPSBTInput.getWitnessUtxo()); // We fill up information we had on the signed PSBT, so we can sign it. proposedPSBTInput.getDerivedPublicKeys().putAll(originalPSBTInput.getDerivedPublicKeys()); + proposedPSBTInput.getProprietary().putAll(originalPSBTInput.getProprietary()); proposedPSBTInput.setRedeemScript(originalPSBTInput.getFinalScriptSig().getFirstNestedScript()); proposedPSBTInput.setWitnessScript(originalPSBTInput.getFinalScriptWitness().getWitnessScript()); proposedPSBTInput.setSigHash(originalPSBTInput.getSigHash()); @@ -251,6 +245,7 @@ public class Payjoin { PSBTOutput originalPSBTOutput = originalOutput.getValue(); // We fill up information we had on the signed PSBT, so we can sign it. proposedPSBTOutput.getDerivedPublicKeys().putAll(originalPSBTOutput.getDerivedPublicKeys()); + proposedPSBTOutput.getProprietary().putAll(originalPSBTOutput.getProprietary()); proposedPSBTOutput.setRedeemScript(originalPSBTOutput.getRedeemScript()); proposedPSBTOutput.setWitnessScript(originalPSBTOutput.getWitnessScript()); } @@ -263,6 +258,10 @@ public class Payjoin { throw new PayjoinReceiverException("Some of our outputs are not included in the proposal"); } } + + //Add global pubkey map for signing + proposal.getExtendedPublicKeys().putAll(psbt.getExtendedPublicKeys()); + proposal.getGlobalProprietary().putAll(psbt.getGlobalProprietary()); } private int getChangeOutputIndex() { diff --git a/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java b/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java index 13b4bd29..71b15a4f 100644 --- a/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java +++ b/src/main/java/com/sparrowwallet/sparrow/transaction/HeadersController.java @@ -376,7 +376,6 @@ public class HeadersController extends TransactionFormController implements Init broadcastButtonBox.setVisible(false); if(headersForm.getBlockTransaction() != null) { - blockchainForm.setVisible(true); updateBlockchainForm(headersForm.getBlockTransaction(), AppController.getCurrentBlockHeight()); } else if(headersForm.getPsbt() != null) { PSBT psbt = headersForm.getPsbt(); @@ -481,6 +480,7 @@ public class HeadersController extends TransactionFormController implements Init } private void updateBlockchainForm(BlockTransaction blockTransaction, Integer currentHeight) { + signaturesForm.setVisible(false); blockchainForm.setVisible(true); if(Sha256Hash.ZERO_HASH.equals(blockTransaction.getBlockHash()) && blockTransaction.getHeight() == 0 && headersForm.getSigningWallet() == null) { @@ -1013,7 +1013,6 @@ public class HeadersController extends TransactionFormController implements Init BlockTransaction blockTransaction = transactionMap.get(txid); if(blockTransaction != null) { headersForm.setBlockTransaction(blockTransaction); - signaturesForm.setVisible(false); updateBlockchainForm(blockTransaction, AppController.getCurrentBlockHeight()); } });