never executed always true always false
    1 {-# LANGUAGE FlexibleContexts #-}
    2 {-# LANGUAGE LambdaCase #-}
    3 
    4 {-# OPTIONS_HADDOCK hide #-}
    5 
    6 module Command.Script
    7     ( Cmd (..)
    8     , mod
    9     , run
   10     ) where
   11 
   12 import Prelude hiding
   13     ( mod )
   14 
   15 import Options.Applicative
   16     ( CommandFields
   17     , Mod
   18     , command
   19     , footerDoc
   20     , helper
   21     , info
   22     , progDesc
   23     , subparser
   24     )
   25 import Options.Applicative.Help.Pretty
   26     ( bold, indent, string, vsep )
   27 import System.IO.Extra
   28     ( progName )
   29 
   30 import qualified Command.Script.Hash as Hash
   31 import qualified Command.Script.Preimage as Preimage
   32 import qualified Command.Script.Validation as Validation
   33 
   34 data Cmd
   35     = Hash Hash.Cmd
   36     | Validation Validation.Cmd
   37     | Preimage Preimage.Cmd
   38     deriving (Show)
   39 
   40 mod :: (Cmd -> parent) -> Mod CommandFields parent
   41 mod liftCmd = command "script" $
   42     info (helper <*> fmap liftCmd parser) $ mempty
   43         <> progDesc "About scripts"
   44         <> footerDoc (Just $ vsep
   45             [ string "Example:"
   46             , indent 2 $ bold $ string $ "$ "<>progName<>" recovery-phrase generate --size 15 \\"
   47             , indent 4 $ bold $ string $ "| "<>progName<>" key from-recovery-phrase Shared > root_shared.xsk"
   48             , indent 2 $ string ""
   49             , indent 2 $ bold $ string "$ cat root_shared.xsk \\"
   50             , indent 4 $ bold $ string $ "| "<>progName<>" key child 1854H/1815H/0H/0/0 > signingKey1.xsk"
   51             , indent 2 $ string ""
   52             , indent 2 $ bold $ string "$ cat signingKey1.xsk \\"
   53             , indent 4 $ bold $ string $ "| "<>progName<>" key public --without-chain-code \\"
   54             , indent 4 $ bold $ string $ "| "<>progName<>" key hash > verKey1.vkh"
   55             , indent 2 $ string ""
   56             , indent 2 $ bold $ string "$ cat root_shared.xsk \\"
   57             , indent 4 $ bold $ string $ "| "<>progName<>" key child 1854H/1815H/0H/0/1 > signingKey2.xsk"
   58             , indent 2 $ string ""
   59             , indent 2 $ bold $ string "$ cat signingKey2.xsk \\"
   60             , indent 4 $ bold $ string $ "| "<>progName<>" key public --without-chain-code \\"
   61             , indent 4 $ bold $ string $ "| "<>progName<>" key hash > verKey2.vkh"
   62             , indent 2 $ string ""
   63             , indent 2 $ bold $ string $ "$ "<>progName<>" script hash \"all [$(cat verKey1.vkh),$(cat verKey2.vkh)]\""
   64             , indent 2 $ string ""
   65             , indent 2 $ bold $ string $ "$ "<>progName<>" script preimage \"all [addr_shared_vkh1zxt0uvrza94h3hv4jpv0ttddgnwkvdgeyq8jf9w30mcs6y8w3nq, active_from 100, active_until 150]\""
   66             ])
   67   where
   68     parser = subparser $ mconcat
   69         [ Hash.mod Hash
   70         , Validation.mod Validation
   71         , Preimage.mod Preimage
   72         ]
   73 
   74 run :: Cmd -> IO ()
   75 run = \case
   76     Hash sub -> Hash.run sub
   77     Validation sub -> Validation.run sub
   78     Preimage sub -> Preimage.run sub