ScriptBuilder: extract private helper p2whOutputScript()

This commit is contained in:
Andreas Schildbach 2023-04-05 18:19:21 +02:00
parent 15ee38aae0
commit a1237a636b

View File

@ -317,16 +317,20 @@ public class ScriptBuilder {
else
throw new IllegalStateException("Cannot handle " + scriptType);
} else if (to instanceof SegwitAddress) {
// OP_0 <pubKeyHash|scriptHash>
SegwitAddress toSegwit = (SegwitAddress) to;
smallNum(toSegwit.getWitnessVersion());
data(toSegwit.getWitnessProgram());
p2whOutputScript((SegwitAddress) to);
} else {
throw new IllegalStateException("Cannot handle " + to);
}
return this;
}
private ScriptBuilder p2whOutputScript(SegwitAddress address) {
checkState(chunks.isEmpty());
// OP_0 <pubKeyHash|scriptHash>
return smallNum(address.getWitnessVersion())
.data(address.getWitnessProgram());
}
/**
* Creates a scriptSig that can redeem a P2PKH output.
* If given signature is null, incomplete scriptSig will be created with OP_0 instead of signature