diff --git a/core/src/main/scala/org/bitcoins/core/protocol/script/ScriptPubKey.scala b/core/src/main/scala/org/bitcoins/core/protocol/script/ScriptPubKey.scala index 4eaf583354..94ce694878 100644 --- a/core/src/main/scala/org/bitcoins/core/protocol/script/ScriptPubKey.scala +++ b/core/src/main/scala/org/bitcoins/core/protocol/script/ScriptPubKey.scala @@ -1410,7 +1410,7 @@ object P2WSHWitnessSPKV0 extends ScriptFactory[P2WSHWitnessSPKV0] { fromAsm(Seq(OP_0) ++ pushop ++ Seq(ScriptConstant(hash.bytes))) } - def apply(spk: ScriptPubKey): P2WSHWitnessSPKV0 = { + def apply(spk: RawScriptPubKey): P2WSHWitnessSPKV0 = { require( BitcoinScriptUtil.isOnlyCompressedPubKey(spk), s"Public key must be compressed to be used in a segwit script, see BIP143") diff --git a/core/src/main/scala/org/bitcoins/core/psbt/PSBT.scala b/core/src/main/scala/org/bitcoins/core/psbt/PSBT.scala index 7acf731c73..42a13b2d73 100644 --- a/core/src/main/scala/org/bitcoins/core/psbt/PSBT.scala +++ b/core/src/main/scala/org/bitcoins/core/psbt/PSBT.scala @@ -378,7 +378,16 @@ case class PSBT( OutputPSBTRecord.RedeemScript(redeemScript) } case p2wsh: P2WSHWitnessSPKV0 => - val scriptHash = P2WSHWitnessSPKV0(redeemScript).scriptHash + val scriptHash = { + redeemScript match { + case raw: RawScriptPubKey => P2WSHWitnessSPKV0(raw).scriptHash + case nonraw @ (_: P2SHScriptPubKey | _: P2WPKHWitnessSPKV0 | + _: TaprootScriptPubKey | _: UnassignedWitnessScriptPubKey | + _: P2WSHWitnessSPKV0) => + throw new IllegalArgumentException( + s"Cannot make p2wsh from non raw spk=$nonraw") + } + } if (scriptHash != p2wsh.scriptHash) { throw new IllegalArgumentException( s"The given script's hash does not match the expected script has, got: $scriptHash, expected ${p2wsh.scriptHash}") diff --git a/testkit-core/src/main/scala/org/bitcoins/testkitcore/gen/ScriptGenerators.scala b/testkit-core/src/main/scala/org/bitcoins/testkitcore/gen/ScriptGenerators.scala index ffec01f8cf..b1e612b922 100644 --- a/testkit-core/src/main/scala/org/bitcoins/testkitcore/gen/ScriptGenerators.scala +++ b/testkit-core/src/main/scala/org/bitcoins/testkitcore/gen/ScriptGenerators.scala @@ -346,7 +346,7 @@ sealed abstract class ScriptGenerators { /** Generates a random P2WSHWitnessSPKV0 as well as it's corresponding private keys and redeem script */ def p2wshSPKV0: Gen[(P2WSHWitnessSPKV0, Seq[ECPrivateKey], ScriptPubKey)] = - randomNonP2SHScriptPubKey + rawScriptPubKey .suchThat { case (spk, _) => !redeemScriptTooBig(spk) }