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 else
throw new IllegalStateException("Cannot handle " + scriptType); throw new IllegalStateException("Cannot handle " + scriptType);
} else if (to instanceof SegwitAddress) { } else if (to instanceof SegwitAddress) {
// OP_0 <pubKeyHash|scriptHash> p2whOutputScript((SegwitAddress) to);
SegwitAddress toSegwit = (SegwitAddress) to;
smallNum(toSegwit.getWitnessVersion());
data(toSegwit.getWitnessProgram());
} else { } else {
throw new IllegalStateException("Cannot handle " + to); throw new IllegalStateException("Cannot handle " + to);
} }
return this; 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. * 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 * If given signature is null, incomplete scriptSig will be created with OP_0 instead of signature