Skip to content

Commit 8e23329

Browse files
committed
Builds. Fill in remaining commands
1 parent b6e3199 commit 8e23329

File tree

12 files changed

+252
-105
lines changed

12 files changed

+252
-105
lines changed

cardano-cli/cardano-cli.cabal

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ library
143143
Cardano.CLI.EraIndependent.Address.Option
144144
Cardano.CLI.EraIndependent.Address.Run
145145
Cardano.CLI.EraIndependent.Cip.Cip129.Command
146+
Cardano.CLI.EraIndependent.Cip.Cip129.Conversion
146147
Cardano.CLI.EraIndependent.Cip.Cip129.Options
147148
Cardano.CLI.EraIndependent.Cip.Cip129.Run
148149
Cardano.CLI.EraIndependent.Cip.Command
@@ -186,6 +187,7 @@ library
186187
Cardano.CLI.Orphan
187188
Cardano.CLI.Parser
188189
Cardano.CLI.Read
190+
Cardano.CLI.Read.DRep
189191
Cardano.CLI.Render
190192
Cardano.CLI.Run
191193
Cardano.CLI.TopHandler
@@ -286,6 +288,7 @@ library
286288
transformers-except ^>=0.1.3,
287289
unliftio-core,
288290
utf8-string,
291+
validation,
289292
vector,
290293
yaml,
291294

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
module Cardano.CLI.EraIndependent.Cip.Cip129.Command
2-
( Cip129(..)
2+
( Cip129 (..)
3+
, renderCip129Command
34
)
45
where
56

67
import Cardano.CLI.EraIndependent.Cip.Common
78

8-
data Cip129
9-
= Cip129DRep Input Output
10-
| Cip129CommitteeHotKey Input Output
11-
| Cip129CommitteeColdKey Input Output
12-
| Cip129GovernanceAction Input Output
9+
import Data.Text (Text)
10+
11+
data Cip129
12+
= Cip129DRep Input Output
13+
| Cip129CommitteeHotKey Input Output
14+
| Cip129CommitteeColdKey Input Output
15+
| Cip129GovernanceAction Input Output
16+
17+
renderCip129Command :: Cip129 -> Text
18+
renderCip129Command (Cip129DRep{}) = "cip-129 drep"
19+
renderCip129Command (Cip129CommitteeHotKey{}) = "cip-129 committee-hot-key"
20+
renderCip129Command (Cip129CommitteeColdKey{}) = "cip-129 committee-cold-key"
21+
renderCip129Command (Cip129GovernanceAction{}) = "cip-129 governance-action"
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{-# LANGUAGE DataKinds #-}
2+
3+
module Cardano.CLI.EraIndependent.Cip.Cip129.Conversion
4+
( encodeCip129DrepVerficationKeyText
5+
)
6+
where
7+
8+
import Cardano.CLI.Read.DRep
9+
import Data.Text
10+
import Cardano.Api.Ledger qualified as L
11+
import Cardano.Api.Ledger (StandardCrypto)
12+
import Cardano.Api.Shelley
13+
14+
15+
encodeCip129DrepVerficationKeyText :: AnyDrepVerificationKey -> Text
16+
encodeCip129DrepVerficationKeyText = serialiseToBech32CIP129 . anyDrepVerificationKeyToCredential
17+
18+
19+
anyDrepVerificationKeyToCredential :: AnyDrepVerificationKey -> L.Credential L.DRepRole StandardCrypto
20+
anyDrepVerificationKeyToCredential drepKey =
21+
case drepKey of
22+
AnyDrepVerificationKey vk ->
23+
let DRepKeyHash hash = verificationKeyHash vk
24+
in L.KeyHashObj hash
25+
AnyDrepExtendedVerificationKey vk ->
26+
let DRepExtendedKeyHash hash = verificationKeyHash vk
27+
in L.KeyHashObj hash

cardano-cli/src/Cardano/CLI/EraIndependent/Cip/Cip129/Options.hs

Lines changed: 60 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,65 +3,77 @@ module Cardano.CLI.EraIndependent.Cip.Cip129.Options
33
)
44
where
55

6-
import Options.Applicative qualified as Opt
76
import Cardano.CLI.EraIndependent.Cip.Command
8-
import Control.Applicative
97
import Cardano.CLI.EraIndependent.Cip.Common
108

9+
import Control.Applicative
10+
import Options.Applicative qualified as Opt
11+
1112
pCip129 :: Opt.Parser CipFormatCmds
12-
pCip129 = Cip129 <$> asum [ pCip129Drep
13-
, pCip129CommitteeHotKey
14-
, pCip129CommitteeColdKey
15-
, pCip129GovernanceAction
16-
]
13+
pCip129 =
14+
Cip129
15+
<$> asum
16+
[ pCip129Drep
17+
, pCip129CommitteeHotKey
18+
, pCip129CommitteeColdKey
19+
, pCip129GovernanceAction
20+
]
1721

1822
pCip129Drep :: Opt.Parser Cip129
19-
pCip129Drep =
20-
Cip129DRep
21-
<$> pInput
22-
<*> pOutput
23-
where
24-
pInput = asum [ pInputFile "drep-file" "Input hex/bech32/text envelope drep file"
25-
, pInputHexText "drep-hex" "HEX" "Input hex encoded drep"
26-
, pInputBech32Text "drep-bech32" "BECH32" "Input bech32 encoded drep"
27-
]
23+
pCip129Drep =
24+
Cip129DRep
25+
<$> pInput
26+
<*> pOutput
27+
where
28+
pInput =
29+
asum
30+
[ pInputFile "drep-file" "Input hex/bech32/text envelope drep file"
31+
, pInputHexText "drep-hex" "HEX" "Input hex encoded drep"
32+
, pInputBech32Text "drep-bech32" "BECH32" "Input bech32 encoded drep"
33+
]
2834

2935
pCip129CommitteeHotKey :: Opt.Parser Cip129
30-
pCip129CommitteeHotKey =
31-
Cip129CommitteeHotKey
32-
<$> pInput
33-
<*> pOutput
34-
where
35-
pInput = asum [ pInputFile "committee-hot-key-file" "Input hex/bech32/text envelope committee hot key file"
36-
, pInputHexText "committee-hot-key-hex" "HEX" "Input hex encoded committee hot key"
37-
, pInputBech32Text "committee-hot-key-bech32" "BECH32" "Input bech32 encoded committee hot key"
38-
]
36+
pCip129CommitteeHotKey =
37+
Cip129CommitteeHotKey
38+
<$> pInput
39+
<*> pOutput
40+
where
41+
pInput =
42+
asum
43+
[ pInputFile "committee-hot-key-file" "Input hex/bech32/text envelope committee hot key file"
44+
, pInputHexText "committee-hot-key-hex" "HEX" "Input hex encoded committee hot key"
45+
, pInputBech32Text "committee-hot-key-bech32" "BECH32" "Input bech32 encoded committee hot key"
46+
]
3947

4048
pCip129CommitteeColdKey :: Opt.Parser Cip129
41-
pCip129CommitteeColdKey =
42-
Cip129CommitteeColdKey
43-
<$> pInput
44-
<*> pOutput
45-
where
46-
pInput = asum [ pInputFile "committee-cold-key-file" "Input hex/bech32/text envelope committee cold key file"
47-
, pInputHexText "committee-cold-key-hex" "HEX" "Input hex encoded committee cold key"
48-
, pInputBech32Text "committee-cold-key-bech32" "BECH32" "Input bech32 encoded committee cold key"
49-
]
49+
pCip129CommitteeColdKey =
50+
Cip129CommitteeColdKey
51+
<$> pInput
52+
<*> pOutput
53+
where
54+
pInput =
55+
asum
56+
[ pInputFile "committee-cold-key-file" "Input hex/bech32/text envelope committee cold key file"
57+
, pInputHexText "committee-cold-key-hex" "HEX" "Input hex encoded committee cold key"
58+
, pInputBech32Text "committee-cold-key-bech32" "BECH32" "Input bech32 encoded committee cold key"
59+
]
5060

5161
pCip129GovernanceAction :: Opt.Parser Cip129
52-
pCip129GovernanceAction =
53-
Cip129GovernanceAction
54-
<$> pInput
55-
<*> pOutput
56-
where
57-
pInput = asum [ pInputFile "governance-action-file" "Input hex/bech32/text envelope governance action file"
58-
, pInputHexText "governance-action-hex" "HEX" "Input hex encoded governance action"
59-
, pInputBech32Text "governance-action-bech32" "BECH32" "Input bech32 encoded governance action"
60-
]
61-
62-
62+
pCip129GovernanceAction =
63+
Cip129GovernanceAction
64+
<$> pInput
65+
<*> pOutput
66+
where
67+
pInput =
68+
asum
69+
[ pInputFile "governance-action-file" "Input hex/bech32/text envelope governance action file"
70+
, pInputHexText "governance-action-hex" "HEX" "Input hex encoded governance action"
71+
, pInputBech32Text "governance-action-bech32" "BECH32" "Input bech32 encoded governance action"
72+
]
6373

6474
pOutput :: Opt.Parser Output
65-
pOutput = asum [ pOutputFile "output-file" "Output file"
66-
, pOutputText "output-text" "TEXT" "Output text"
67-
]
75+
pOutput =
76+
asum
77+
[ pOutputFile "output-file" "Output file"
78+
, pOutputText "output-text" "Output text"
79+
]
Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,42 @@
1+
{-# LANGUAGE RankNTypes #-}
2+
13
module Cardano.CLI.EraIndependent.Cip.Cip129.Run
24
( runCip129
35
)
46
where
57

8+
import Cardano.Api
9+
10+
import Cardano.CLI.Compatible.Exception
611
import Cardano.CLI.EraIndependent.Cip.Cip129.Command
12+
import Cardano.CLI.EraIndependent.Cip.Cip129.Conversion
13+
import Cardano.CLI.EraIndependent.Cip.Common
14+
import Cardano.CLI.Orphan ()
15+
import Cardano.CLI.Read
16+
import Cardano.CLI.Read.DRep
17+
18+
import Data.ByteString qualified as BS
19+
import Data.ByteString.Char8 qualified as BSC
20+
import Data.Text.Encoding qualified as Text
21+
import Data.Validation qualified as Valid
22+
import System.IO
723

8-
runCip129 :: Cip129 -> IO ()
9-
runCip129 (Cip129DRep inp out) = undefined
10-
runCip129 (Cip129CommitteeHotKey inp out) = undefined
11-
runCip129 (Cip129CommitteeColdKey inp out) = undefined
12-
runCip129 (Cip129GovernanceAction inp out) = undefined
24+
runCip129 :: Cip129 -> CIO e ()
25+
runCip129 (Cip129DRep inp out) = do
26+
k <- case inp of
27+
InputTextEnvelopeFile (File textEnvFp) -> do
28+
f <- liftIO $ fileOrPipe textEnvFp
29+
fromEitherIOCli $ readDrepVerificationKeyFile f
30+
InputHexText t -> do
31+
fromEitherCli . Valid.toEither $ readDRepHexVerificationKeyText t
32+
InputBech32Text t -> do
33+
fromEitherCli . Valid.toEither $ readDRepBech32VerificationKeyText t
34+
let cip129Output = Text.encodeUtf8 $ encodeCip129DrepVerficationKeyText k
35+
case out of
36+
OutputText ->
37+
liftIO $ BSC.hPutStrLn stdout cip129Output
38+
OutputFile (File fp) ->
39+
liftIO $ BS.writeFile fp cip129Output
40+
runCip129 (Cip129CommitteeHotKey _inp _out) = undefined
41+
runCip129 (Cip129CommitteeColdKey _inp _out) = undefined
42+
runCip129 (Cip129GovernanceAction _inp _out) = undefined
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
21
module Cardano.CLI.EraIndependent.Cip.Command
32
( -- * Supported CIPs
4-
Cip129(..)
5-
6-
, CipFormatCmds(..)
7-
3+
Cip129 (..)
4+
, CipFormatCmds (..)
5+
, renderCipFormatCmds
86
)
97
where
8+
109
import Cardano.CLI.EraIndependent.Cip.Cip129.Command
1110

12-
newtype CipFormatCmds
13-
= Cip129 Cip129
11+
import Data.Text (Text)
1412

13+
newtype CipFormatCmds
14+
= Cip129 Cip129
1515

16+
renderCipFormatCmds :: CipFormatCmds -> Text
17+
renderCipFormatCmds (Cip129 cip129) = "cip-format" <> renderCip129Command cip129
Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,40 @@
11
{-# LANGUAGE DataKinds #-}
2+
{-# LANGUAGE RankNTypes #-}
23

34
module Cardano.CLI.EraIndependent.Cip.Common
4-
( -- * Input related
5+
( -- * Input related
56
Input (..)
6-
77
, pInputFile
88
, pInputHexText
99
, pInputBech32Text
10-
11-
-- * Output related
10+
11+
-- * Output related
1212
, Output (..)
1313
, pOutputFile
1414
, pOutputText
1515
)
16-
where
16+
where
1717

18+
import Cardano.Api
1819

19-
import Options.Applicative qualified as Opt
20-
import Cardano.Api
2120
import Cardano.CLI.EraBased.Common.Option hiding (pOutputFile)
22-
import qualified Data.Text as Text
23-
import Data.Text (Text)
2421

22+
import Data.Text (Text)
23+
import Data.Text qualified as Text
24+
import Options.Applicative qualified as Opt
2525

26-
data Input
27-
= InputFile (File () In)
28-
| InputHexText Text
29-
| InputBech32Text Text
26+
data Input
27+
= InputTextEnvelopeFile (File () In)
28+
| InputHexText Text
29+
| InputBech32Text Text
3030

3131
pInputFile :: String -> String -> Opt.Parser Input
32-
pInputFile optName desc =
33-
InputFile <$> pFileInDirection optName desc
32+
pInputFile optName desc =
33+
InputTextEnvelopeFile <$> pFileInDirection optName desc
3434

3535
pInputHexText :: String -> String -> String -> Opt.Parser Input
36-
pInputHexText optName metavar help =
37-
fmap (InputHexText . Text.pack) $
36+
pInputHexText optName metavar help =
37+
fmap (InputHexText . Text.pack) $
3838
Opt.strOption $
3939
mconcat
4040
[ Opt.long optName
@@ -43,31 +43,27 @@ pInputHexText optName metavar help =
4343
]
4444

4545
pInputBech32Text :: String -> String -> String -> Opt.Parser Input
46-
pInputBech32Text optName metavar help =
47-
fmap (InputBech32Text . Text.pack) $
46+
pInputBech32Text optName metavar help =
47+
fmap (InputBech32Text . Text.pack) $
4848
Opt.strOption $
4949
mconcat
5050
[ Opt.long optName
5151
, Opt.metavar metavar
5252
, Opt.help help
5353
]
5454

55-
56-
data Output
57-
= OutputFile (File () Out)
58-
| OutputText Text
55+
data Output
56+
= OutputFile (File () Out)
57+
| OutputText
5958

6059
pOutputFile :: String -> String -> Opt.Parser Output
61-
pOutputFile optName desc =
62-
OutputFile <$> pFileOutDirection optName desc
60+
pOutputFile optName desc =
61+
OutputFile <$> pFileOutDirection optName desc
6362

64-
65-
pOutputText :: String -> String -> String -> Opt.Parser Output
66-
pOutputText optName metavar help =
67-
fmap (OutputText . Text.pack) $
68-
Opt.strOption $
69-
mconcat
70-
[ Opt.long optName
71-
, Opt.metavar metavar
72-
, Opt.help help
73-
]
63+
pOutputText :: String -> String -> Opt.Parser Output
64+
pOutputText optName help =
65+
Opt.flag' OutputText $
66+
mconcat
67+
[ Opt.long optName
68+
, Opt.help help
69+
]

0 commit comments

Comments
 (0)