diff --git a/src/main/java/com/sparrowwallet/drongo/psbt/PSBT.java b/src/main/java/com/sparrowwallet/drongo/psbt/PSBT.java index f4817c1..32d6c47 100644 --- a/src/main/java/com/sparrowwallet/drongo/psbt/PSBT.java +++ b/src/main/java/com/sparrowwallet/drongo/psbt/PSBT.java @@ -87,6 +87,8 @@ public class PSBT { this.version = version; } + boolean alwaysIncludeWitnessUtxo = wallet.getKeystores().stream().anyMatch(keystore -> keystore.getWalletModel().alwaysIncludeNonWitnessUtxo()); + int inputIndex = 0; for(Iterator> iter = walletTransaction.getSelectedUtxos().entrySet().iterator(); iter.hasNext(); inputIndex++) { Map.Entry utxoEntry = iter.next(); @@ -112,7 +114,7 @@ public class PSBT { derivedPublicKeys.put(keystore.getPubKey(walletNode), keystore.getKeyDerivation().extend(walletNode.getDerivation())); } - PSBTInput psbtInput = new PSBTInput(wallet.getScriptType(), transaction, inputIndex, utxo, utxoIndex, redeemScript, witnessScript, derivedPublicKeys, Collections.emptyMap()); + PSBTInput psbtInput = new PSBTInput(wallet.getScriptType(), transaction, inputIndex, utxo, utxoIndex, redeemScript, witnessScript, derivedPublicKeys, Collections.emptyMap(), alwaysIncludeWitnessUtxo); psbtInputs.add(psbtInput); } diff --git a/src/main/java/com/sparrowwallet/drongo/psbt/PSBTInput.java b/src/main/java/com/sparrowwallet/drongo/psbt/PSBTInput.java index 5d156f2..907efc3 100644 --- a/src/main/java/com/sparrowwallet/drongo/psbt/PSBTInput.java +++ b/src/main/java/com/sparrowwallet/drongo/psbt/PSBTInput.java @@ -48,16 +48,20 @@ public class PSBTInput { this.index = index; } - PSBTInput(ScriptType scriptType, Transaction transaction, int index, Transaction utxo, int utxoIndex, Script redeemScript, Script witnessScript, Map derivedPublicKeys, Map proprietary) { + PSBTInput(ScriptType scriptType, Transaction transaction, int index, Transaction utxo, int utxoIndex, Script redeemScript, Script witnessScript, Map derivedPublicKeys, Map proprietary, boolean alwaysAddNonWitnessTx) { this(transaction, index); sigHash = SigHash.ALL; if(Arrays.asList(ScriptType.WITNESS_TYPES).contains(scriptType)) { this.witnessUtxo = utxo.getOutputs().get(utxoIndex); + } else { + this.nonWitnessUtxo = utxo; } - //Add non-witness UTXO to segwit types to handle Trezor and Ledger requirements - this.nonWitnessUtxo = utxo; + if(alwaysAddNonWitnessTx) { + //Add non-witness UTXO to segwit types to handle Trezor, Bitbox and Ledger requirements + this.nonWitnessUtxo = utxo; + } this.redeemScript = redeemScript; this.witnessScript = witnessScript; diff --git a/src/main/java/com/sparrowwallet/drongo/wallet/WalletModel.java b/src/main/java/com/sparrowwallet/drongo/wallet/WalletModel.java index 13b2295..845534a 100644 --- a/src/main/java/com/sparrowwallet/drongo/wallet/WalletModel.java +++ b/src/main/java/com/sparrowwallet/drongo/wallet/WalletModel.java @@ -35,6 +35,14 @@ public enum WalletModel { return this.toString().toLowerCase(); } + public boolean alwaysIncludeNonWitnessUtxo() { + if(this == COLDCARD || this == COBO_VAULT) { + return false; + } + + return true; + } + public boolean requiresPinPrompt() { return (this == TREZOR_1 || this == KEEPKEY); }