From a1237a636bfc99076a0c2874b6ff97e96e839e96 Mon Sep 17 00:00:00 2001 From: Andreas Schildbach Date: Wed, 5 Apr 2023 18:19:21 +0200 Subject: [PATCH] ScriptBuilder: extract private helper `p2whOutputScript()` --- .../main/java/org/bitcoinj/script/ScriptBuilder.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/org/bitcoinj/script/ScriptBuilder.java b/core/src/main/java/org/bitcoinj/script/ScriptBuilder.java index 8c959f52b..f3e53bf18 100644 --- a/core/src/main/java/org/bitcoinj/script/ScriptBuilder.java +++ b/core/src/main/java/org/bitcoinj/script/ScriptBuilder.java @@ -317,16 +317,20 @@ public class ScriptBuilder { else throw new IllegalStateException("Cannot handle " + scriptType); } else if (to instanceof SegwitAddress) { - // OP_0 - 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 + 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