File tree Expand file tree Collapse file tree 1 file changed +25
-10
lines changed
pub/haskell-bitcoin-script/src/Data/Bitcoin Expand file tree Collapse file tree 1 file changed +25
-10
lines changed Original file line number Diff line number Diff line change 1
- module Data.Bitcoin.Script ( decode
2
- , encode
3
- , ScriptOp (.. )
4
- , Script (.. )
5
- , PushDataType (.. ) ) where
1
+ {-# LANGUAGE CPP #-}
6
2
7
- import qualified Data.Binary as B
8
- import qualified Data.ByteString.Base16.Lazy as BS16L
9
- import qualified Data.ByteString.Lazy as BSL
3
+ module Data.Bitcoin.Script
4
+ ( decode ,
5
+ encode ,
6
+ ScriptOp (.. ),
7
+ Script (.. ),
8
+ PushDataType (.. ),
9
+ )
10
+ where
10
11
11
- import Data.Bitcoin.Script.Types
12
+ import qualified Data.Binary as B
13
+ import Data.Bitcoin.Script.Types
14
+ import qualified Data.ByteString.Base16.Lazy as BS16L
15
+ import qualified Data.ByteString.Lazy as BSL
12
16
13
17
-- | Decodes a hex representation of a script into a 'Script' object.
14
18
decode :: BSL. ByteString -> Script
15
19
decode =
16
- B. decode . fst . BS16L. decode
20
+ B. decode . handler . BS16L. decode
21
+ where
22
+ #if MIN_VERSION_base16_bytestring(1,0,0)
23
+ handler :: Either String BSL. ByteString -> BSL. ByteString
24
+ handler =
25
+ either error id
26
+ #else
27
+ handler :: (BSL. ByteString , BSL. ByteString ) -> BSL. ByteString
28
+ handler = \ case
29
+ (success, " " ) -> success
30
+ failure -> error $ " Non-Hex bytestring " <> show failure
31
+ #endif
17
32
18
33
-- | Encodes a 'Script' object into a hex representation
19
34
encode :: Script -> BSL. ByteString
You can’t perform that action at this time.
0 commit comments