handle adding non witness inputs to segwit transactions

This commit is contained in:
Craig Raw 2020-07-24 10:09:24 +02:00
parent 70d0b7afcd
commit 0466755883
3 changed files with 10 additions and 2 deletions

View file

@ -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) {

View file

@ -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<byte[]> witnesses) {
setParent(transaction);
this.pushes = witnesses;

View file

@ -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));
}
}
}