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,8 +307,12 @@ public class Transaction extends ChildMessage {
} }
public TransactionInput addInput(Sha256Hash spendTxHash, long outputIndex, Script script) { public TransactionInput addInput(Sha256Hash spendTxHash, long outputIndex, Script script) {
if(isSegwit()) {
return addInput(spendTxHash, outputIndex, script, new TransactionWitness(this));
} else {
return addInput(new TransactionInput(this, new TransactionOutPoint(spendTxHash, outputIndex), script.getProgram())); return addInput(new TransactionInput(this, new TransactionOutPoint(spendTxHash, outputIndex), script.getProgram()));
} }
}
public TransactionInput addInput(Sha256Hash spendTxHash, long outputIndex, Script script, TransactionWitness witness) { public TransactionInput addInput(Sha256Hash spendTxHash, long outputIndex, Script script, TransactionWitness witness) {
if(!isSegwit()) { if(!isSegwit()) {

View file

@ -33,6 +33,10 @@ public class TransactionWitness extends ChildMessage {
pushes.add(witnessScript.getProgram()); pushes.add(witnessScript.getProgram());
} }
public TransactionWitness(Transaction transaction) {
this(transaction, new ArrayList<>());
}
public TransactionWitness(Transaction transaction, List<byte[]> witnesses) { public TransactionWitness(Transaction transaction, List<byte[]> witnesses) {
setParent(transaction); setParent(transaction);
this.pushes = witnesses; this.pushes = witnesses;

View file

@ -484,7 +484,7 @@ public class PSBT {
if(psbtInput.getFinalScriptWitness() != null) { if(psbtInput.getFinalScriptWitness() != null) {
txInput.setWitness(psbtInput.getFinalScriptWitness()); txInput.setWitness(psbtInput.getFinalScriptWitness());
} else { } else {
txInput.setWitness(new TransactionWitness(transaction, Collections.emptyList())); txInput.setWitness(new TransactionWitness(transaction));
} }
} }
} }