diff --git a/src/main/java/com/sparrowwallet/drongo/protocol/Transaction.java b/src/main/java/com/sparrowwallet/drongo/protocol/Transaction.java index 560c120..ee0f076 100644 --- a/src/main/java/com/sparrowwallet/drongo/protocol/Transaction.java +++ b/src/main/java/com/sparrowwallet/drongo/protocol/Transaction.java @@ -307,7 +307,11 @@ public class Transaction extends ChildMessage { } public TransactionInput addInput(Sha256Hash spendTxHash, long outputIndex, Script script) { - return addInput(new TransactionInput(this, new TransactionOutPoint(spendTxHash, outputIndex), script.getProgram())); + if(isSegwit()) { + return addInput(spendTxHash, outputIndex, script, new TransactionWitness(this)); + } else { + return addInput(new TransactionInput(this, new TransactionOutPoint(spendTxHash, outputIndex), script.getProgram())); + } } public TransactionInput addInput(Sha256Hash spendTxHash, long outputIndex, Script script, TransactionWitness witness) { diff --git a/src/main/java/com/sparrowwallet/drongo/protocol/TransactionWitness.java b/src/main/java/com/sparrowwallet/drongo/protocol/TransactionWitness.java index 6c8929a..fb4e796 100644 --- a/src/main/java/com/sparrowwallet/drongo/protocol/TransactionWitness.java +++ b/src/main/java/com/sparrowwallet/drongo/protocol/TransactionWitness.java @@ -33,6 +33,10 @@ public class TransactionWitness extends ChildMessage { pushes.add(witnessScript.getProgram()); } + public TransactionWitness(Transaction transaction) { + this(transaction, new ArrayList<>()); + } + public TransactionWitness(Transaction transaction, List witnesses) { setParent(transaction); this.pushes = witnesses; diff --git a/src/main/java/com/sparrowwallet/drongo/psbt/PSBT.java b/src/main/java/com/sparrowwallet/drongo/psbt/PSBT.java index 1c151e8..cde1c38 100644 --- a/src/main/java/com/sparrowwallet/drongo/psbt/PSBT.java +++ b/src/main/java/com/sparrowwallet/drongo/psbt/PSBT.java @@ -484,7 +484,7 @@ public class PSBT { if(psbtInput.getFinalScriptWitness() != null) { txInput.setWitness(psbtInput.getFinalScriptWitness()); } else { - txInput.setWitness(new TransactionWitness(transaction, Collections.emptyList())); + txInput.setWitness(new TransactionWitness(transaction)); } } }