commit c3b4d4d041bfaaa66ba433f4f1311aeb21bd63f3
parent 8a647b36107f5da8312c3f992828c276d58bf490
Author: Jared Tobin <jared@jtobin.io>
Date: Sun, 19 Jan 2025 14:26:28 +0400
lib: reorg
Diffstat:
1 file changed, 18 insertions(+), 16 deletions(-)
diff --git a/lib/Bitcoin/Prim/Script.hs b/lib/Bitcoin/Prim/Script.hs
@@ -471,22 +471,6 @@ from_script (Script bs) = go 0 where
_ -> go (succ j)
--- | Convert a 'Script' to a 'ScriptHash', ensuring that it doesn't exceed
--- the maximum redeemscript size.
-to_scripthash :: Script -> Maybe ScriptHash
-to_scripthash (Script bs)
- | BA.sizeofByteArray bs > _MAX_REDEEM_SCRIPT_SIZE = Nothing
- | otherwise = Just $!
- ScriptHash (RIPEMD160.hash (SHA256.hash (ba_to_bs bs)))
-
--- | Convert a 'Script' to a 'WitnessScriptHash', ensuring that it doesn't
--- the maximum witness script size.
-to_witness_scripthash :: Script -> Maybe WitnessScriptHash
-to_witness_scripthash (Script bs)
- | BA.sizeofByteArray bs > _MAX_WITNESS_SCRIPT_SIZE = Nothing
- | otherwise = Just $!
- WitnessScriptHash (SHA256.hash (ba_to_bs bs))
-
-- convert a pushbytes opcode to its corresponding int
pushbytes :: Opcode -> Maybe Int
pushbytes = \case
@@ -568,3 +552,21 @@ pushbytes = \case
OP_PUSHBYTES_75 -> Just $! 75
_ -> Nothing
+-- script hashes --------------------------------------------------------------
+
+-- | Convert a 'Script' to a 'ScriptHash', ensuring that it doesn't exceed
+-- the maximum redeemscript size.
+to_scripthash :: Script -> Maybe ScriptHash
+to_scripthash (Script bs)
+ | BA.sizeofByteArray bs > _MAX_REDEEM_SCRIPT_SIZE = Nothing
+ | otherwise = Just $!
+ ScriptHash (RIPEMD160.hash (SHA256.hash (ba_to_bs bs)))
+
+-- | Convert a 'Script' to a 'WitnessScriptHash', ensuring that it doesn't
+-- the maximum witness script size.
+to_witness_scripthash :: Script -> Maybe WitnessScriptHash
+to_witness_scripthash (Script bs)
+ | BA.sizeofByteArray bs > _MAX_WITNESS_SCRIPT_SIZE = Nothing
+ | otherwise = Just $!
+ WitnessScriptHash (SHA256.hash (ba_to_bs bs))
+