script

Representations and fast conversions for Script (docs.ppad.tech/script).
git clone git://git.ppad.tech/script.git
Log | Files | Refs | README | LICENSE

Weight.hs (1200B)


      1 {-# OPTIONS_GHC -fno-warn-orphans #-}
      2 {-# LANGUAGE OverloadedStrings #-}
      3 {-# LANGUAGE DeriveGeneric #-}
      4 {-# LANGUAGE DerivingStrategies #-}
      5 {-# LANGUAGE PackageImports #-}
      6 {-# LANGUAGE StandaloneDeriving #-}
      7 
      8 module Main where
      9 
     10 import Bitcoin.Prim.Script
     11 import Control.DeepSeq
     12 import qualified Data.ByteString as BS
     13 import GHC.Generics
     14 import qualified Weigh as W
     15 
     16 deriving stock instance Generic Script
     17 instance NFData Script
     18 
     19 deriving stock instance Generic Term
     20 instance NFData Term
     21 
     22 deriving stock instance Generic Opcode
     23 instance NFData Opcode
     24 
     25 main :: IO ()
     26 main = W.mainWith $ do
     27     W.func "bs_to_ba" bs_to_ba (BS.replicate 1024 0x00)
     28     W.func "ba_to_bs" ba_to_bs ba
     29     W.func "to_script" to_script terms
     30     W.func "from_script" from_script script
     31   where
     32     ba = bs_to_ba (BS.replicate 1024 0x00)
     33     script = to_script terms
     34     terms = [
     35         OPCODE OP_DUP,OPCODE OP_HASH160,OPCODE OP_PUSHBYTES_20,BYTE 0x89,BYTE 0xab
     36       , BYTE 0xcd,BYTE 0xef,BYTE 0xab,BYTE 0xba,BYTE 0xab,BYTE 0xba,BYTE 0xab
     37       , BYTE 0xba,BYTE 0xab,BYTE 0xba,BYTE 0xab,BYTE 0xba,BYTE 0xab,BYTE 0xba
     38       , BYTE 0xab,BYTE 0xba,BYTE 0xab,BYTE 0xba,OPCODE OP_EQUALVERIFY
     39       , OPCODE OP_CHECKSIG
     40       ]
     41