forked from kadena-io/kda-tool
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAppMain.hs
More file actions
89 lines (80 loc) · 3.13 KB
/
AppMain.hs
File metadata and controls
89 lines (80 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE NumericUnderscores #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE TypeFamilies #-}
module AppMain where
------------------------------------------------------------------------------
import Control.Monad.IO.Class
import Data.Aeson
import Data.Default
import Data.String (fromString)
import Katip
import Network.HTTP.Client hiding (withConnection)
import Network.HTTP.Client.TLS
import Options.Applicative
import System.Directory
import System.FilePath
import System.IO
import System.Random.MWC
import Text.Printf
------------------------------------------------------------------------------
import Commands.Cut
import Commands.CombineSigs
import Commands.GenTx
import Commands.Keygen
import Commands.ListKeys
import Commands.Local
import Commands.Mempool
import Commands.Poll
import Commands.Send
import Commands.Sign
import Commands.Verify
import Commands.WalletSign
import Types.Env
------------------------------------------------------------------------------
appMain :: IO ()
appMain = do
Args c severity verbosity mcf <- execParser opts
mgr <- newManager tlsManagerSettings
s1 <- liftIO $ mkHandleScribe ColorIfTerminal stderr
(permitItem severity) verbosity
le <- liftIO $ registerScribe "stderr" s1 defaultScribeSettings
=<< initLogEnv "myapp" "production"
logLE le DebugS $ fromStr $ printf "Logging with severity %s, verbosity %s"
(show severity) (show verbosity)
rand <- createSystemRandom
cf <- maybe (getXdgDirectory XdgConfig ("kda" </> "config.json")) pure mcf
logLE le DebugS $ logStr $ "Loading config from " <> cf
configExists <- doesFileExist cf
ecd <- if configExists
then eitherDecodeFileStrict' cf
else pure $ Right def
cd <- case ecd of
Left e -> error (printf "Error parsing %s\n%s" cf e)
Right cd -> pure cd
logLE le DebugS $ logStr $ "Loaded config: " <> show cd
let theEnv = Env mgr le cd rand
case c of
Cut hp ma mn -> cutCommand theEnv hp ma mn
CombineSigs files -> combineSigsCommand theEnv files
GenTx args -> genTxCommand theEnv args
Keygen keyType -> keygenCommand keyType
ListKeys kf ind -> listKeysCommand kf ind
Local args -> localCommand theEnv args
Mempool hp cid ma mn -> mempoolCommand hp ma mn cid
Poll args -> pollCommand theEnv args
Send args -> sendCommand theEnv args
Sign args -> signCommand args
Verify args -> verifyCommand args
WalletSign args -> walletSignCommand theEnv args
where
opts = info (envP <**> helper) $ mconcat
[ fullDesc
, header "kda - Command line tool for interacting with the Kadena blockchain"
, footerDoc (Just theFooter)
]
theFooter = fromString $ unlines
[ "Run the following command to enable tab completion:"
, ""
, "source <(kda --bash-completion-script `which kda`)"
]