/
Parsers.hs
3658 lines (3291 loc) · 122 KB
/
Parsers.hs
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
module Cardano.CLI.Shelley.Parsers
( -- * CLI command parser
parseShelleyCommands
-- * CLI command and flag types
, module Cardano.CLI.Shelley.Commands
-- * Field parser and renderers
, parseTxIn
) where
import Cardano.Api
import Cardano.Api.Shelley
import Cardano.Chain.Common (BlockCount (BlockCount))
import Cardano.CLI.Common.Parsers
import Cardano.CLI.Environment (EnvCli (..))
import Cardano.CLI.Shelley.Commands
import Cardano.CLI.Shelley.Key (PaymentVerifier (..), PoolDelegationTarget (..),
StakeIdentifier (..), StakeVerifier (..), VerificationKeyOrFile (..),
VerificationKeyOrHashOrFile (..), VerificationKeyTextOrFile (..))
import Cardano.CLI.Types
import qualified Cardano.Ledger.BaseTypes as Shelley
import qualified Cardano.Ledger.Shelley.TxBody as Shelley
import Cardano.Prelude (ConvertText (..))
import qualified Data.Aeson as Aeson
import qualified Data.Attoparsec.ByteString.Char8 as Atto
import Data.Bifunctor
import Data.ByteString (ByteString)
import qualified Data.ByteString.Base16 as B16
import qualified Data.ByteString.Char8 as BSC
import Data.Foldable
import Data.Functor (($>))
import qualified Data.IP as IP
import Data.List.NonEmpty (NonEmpty)
import qualified Data.List.NonEmpty as NE
import Data.Maybe (fromMaybe)
import Data.Ratio ((%))
import qualified Data.Set as Set
import Data.Text (Text)
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
import Data.Time.Clock (UTCTime)
import Data.Time.Format (defaultTimeLocale, parseTimeOrError)
import Data.Word (Word64)
import GHC.Natural (Natural)
import Network.Socket (PortNumber)
import Options.Applicative hiding (help, str)
import qualified Options.Applicative as Opt
import qualified Options.Applicative.Help as H
import Prettyprinter (line, pretty)
import qualified Text.Parsec as Parsec
import Text.Parsec ((<?>))
import qualified Text.Parsec.Error as Parsec
import qualified Text.Parsec.Language as Parsec
import qualified Text.Parsec.String as Parsec
import qualified Text.Parsec.Token as Parsec
import Text.Read (readEither, readMaybe)
{- HLINT ignore "Use <$>" -}
{- HLINT ignore "Move brackets to avoid $" -}
--
-- Shelley CLI command parsers
--
parseShelleyCommands :: EnvCli -> Parser ShelleyCommand
parseShelleyCommands envCli =
Opt.hsubparser $ mconcat
[ Opt.metavar "Era based commands"
, Opt.commandGroup "Era based commands"
, Opt.command "address" $
Opt.info (AddressCmd <$> pAddressCmd envCli) $ Opt.progDesc "Payment address commands"
, Opt.command "stake-address" $
Opt.info (StakeAddressCmd <$> pStakeAddressCmd envCli) $ Opt.progDesc "Stake address commands"
, Opt.command "key" $
Opt.info (KeyCmd <$> pKeyCmd) $ Opt.progDesc "Key utility commands"
, Opt.command "transaction" $
Opt.info (TransactionCmd <$> pTransaction envCli) $ Opt.progDesc "Transaction commands"
, Opt.command "node" $
Opt.info (NodeCmd <$> pNodeCmd) $ Opt.progDesc "Node operation commands"
, Opt.command "stake-pool" $
Opt.info (PoolCmd <$> pPoolCmd envCli) $ Opt.progDesc "Stake pool commands"
, Opt.command "query" $
Opt.info (QueryCmd <$> pQueryCmd envCli) . Opt.progDesc $ mconcat
[ "Node query commands. Will query the local node whose Unix domain socket "
, "is obtained from the CARDANO_NODE_SOCKET_PATH environment variable."
]
, Opt.command "genesis" $
Opt.info (GenesisCmd <$> pGenesisCmd envCli) $ Opt.progDesc "Genesis block commands"
, Opt.command "governance" $
Opt.info (GovernanceCmd <$> pGovernanceCmd envCli) $ Opt.progDesc "Governance commands"
, Opt.command "text-view" $
Opt.info (TextViewCmd <$> pTextViewCmd) . Opt.progDesc $ mconcat
[ "Commands for dealing with Shelley TextView files. "
, "Transactions, addresses etc are stored on disk as TextView files."
]
]
pTextViewCmd :: Parser TextViewCmd
pTextViewCmd =
asum
[ subParser "decode-cbor"
(Opt.info (TextViewInfo <$> pCBORInFile <*> pMaybeOutputFile)
$ Opt.progDesc "Print a TextView file as decoded CBOR."
)
]
pCBORInFile :: Parser FilePath
pCBORInFile =
Opt.strOption
( Opt.long "in-file"
<> Opt.metavar "FILE"
<> Opt.help "CBOR input file."
<> Opt.completer (Opt.bashCompleter "file")
)
<|>
Opt.strOption
( Opt.long "file"
<> Opt.internal
)
pAddressCmd :: EnvCli -> Parser AddressCmd
pAddressCmd envCli =
asum
[ subParser "key-gen"
(Opt.info pAddressKeyGen $ Opt.progDesc "Create an address key pair.")
, subParser "key-hash"
(Opt.info pAddressKeyHash $ Opt.progDesc "Print the hash of an address key.")
, subParser "build"
(Opt.info pAddressBuild $ Opt.progDesc "Build a Shelley payment address, with optional delegation to a stake address.")
, subParser "info"
(Opt.info pAddressInfo $ Opt.progDesc "Print information about an address.")
]
where
pAddressKeyGen :: Parser AddressCmd
pAddressKeyGen = AddressKeyGen
<$> pAddressKeyType
<*> pVerificationKeyFileOut
<*> pSigningKeyFileOut
pAddressKeyHash :: Parser AddressCmd
pAddressKeyHash =
AddressKeyHash
<$> pPaymentVerificationKeyTextOrFile
<*> pMaybeOutputFile
pAddressBuild :: Parser AddressCmd
pAddressBuild = AddressBuild
<$> pPaymentVerifier
<*> Opt.optional pStakeIdentifier
<*> pNetworkId envCli
<*> pMaybeOutputFile
pAddressInfo :: Parser AddressCmd
pAddressInfo = AddressInfo <$> pAddress <*> pMaybeOutputFile
pPaymentVerifier :: Parser PaymentVerifier
pPaymentVerifier =
PaymentVerifierKey <$> pPaymentVerificationKeyTextOrFile
<|> PaymentVerifierScriptFile <$>
pScriptFor "payment-script-file" Nothing
"Filepath of the payment script."
pStakeIdentifier :: Parser StakeIdentifier
pStakeIdentifier = asum
[ StakeIdentifierVerifier <$> pStakeVerifier
, StakeIdentifierAddress <$> pStakeAddress
]
pStakeVerifier :: Parser StakeVerifier
pStakeVerifier = asum
[ StakeVerifierKey <$> pStakeVerificationKeyOrFile
, StakeVerifierScriptFile <$> pScriptFor "stake-script-file" Nothing "Filepath of the staking script."
]
pPaymentVerificationKeyTextOrFile :: Parser VerificationKeyTextOrFile
pPaymentVerificationKeyTextOrFile =
VktofVerificationKeyText <$> pPaymentVerificationKeyText
<|> VktofVerificationKeyFile <$> pPaymentVerificationKeyFile
pPaymentVerificationKeyText :: Parser Text
pPaymentVerificationKeyText =
Text.pack <$>
Opt.strOption
( Opt.long "payment-verification-key"
<> Opt.metavar "STRING"
<> Opt.help "Payment verification key (Bech32-encoded)"
)
pPaymentVerificationKeyFile :: Parser (VerificationKeyFile In)
pPaymentVerificationKeyFile =
fmap File $ asum
[ Opt.strOption $ mconcat
[ Opt.long "payment-verification-key-file"
, Opt.metavar "FILE"
, Opt.help "Filepath of the payment verification key."
, Opt.completer (Opt.bashCompleter "file")
]
, Opt.strOption $ mconcat
[ Opt.long "verification-key-file"
, Opt.internal
]
]
pScript :: Parser ScriptFile
pScript = pScriptFor "script-file" Nothing "Filepath of the script."
pScriptFor :: String -> Maybe String -> String -> Parser ScriptFile
pScriptFor name Nothing help =
ScriptFile <$> Opt.strOption
( Opt.long name
<> Opt.metavar "FILE"
<> Opt.help help
<> Opt.completer (Opt.bashCompleter "file")
)
pScriptFor name (Just deprecated) help =
pScriptFor name Nothing help
<|> ScriptFile <$> Opt.strOption
( Opt.long deprecated
<> Opt.internal
)
pReferenceTxIn :: String -> String -> Parser TxIn
pReferenceTxIn prefix scriptType =
Opt.option (readerFromParsecParser parseTxIn) $ mconcat
[ Opt.long (prefix ++ "tx-in-reference")
, Opt.metavar "TX-IN"
, Opt.help $ mconcat
[ "TxId#TxIx - Specify a reference input. The reference input must have"
, " a " <> scriptType <> " reference script attached."
]
]
pReadOnlyReferenceTxIn :: Parser TxIn
pReadOnlyReferenceTxIn =
Opt.option (readerFromParsecParser parseTxIn) $ mconcat
[ Opt.long "read-only-tx-in-reference"
, Opt.metavar "TX-IN"
, Opt.help $ mconcat
[ "Specify a read only reference input. This reference input is not witnessing anything "
, "it is simply provided in the plutus script context."
]
]
pScriptWitnessFiles :: forall witctx.
WitCtx witctx
-> BalanceTxExecUnits -- ^ Use the @execution-units@ flag.
-> String -- ^ Script flag prefix
-> Maybe String
-> String
-> Parser (ScriptWitnessFiles witctx)
pScriptWitnessFiles witctx autoBalanceExecUnits scriptFlagPrefix scriptFlagPrefixDeprecated help =
toScriptWitnessFiles
<$> pScriptFor (scriptFlagPrefix ++ "-script-file")
((++ "-script-file") <$> scriptFlagPrefixDeprecated)
("The file containing the script to witness " ++ help)
<*> optional ((,,) <$> pScriptDatumOrFile scriptFlagPrefix witctx
<*> pScriptRedeemerOrFile scriptFlagPrefix
<*> (case autoBalanceExecUnits of
AutoBalance -> pure (ExecutionUnits 0 0)
ManualBalance -> pExecutionUnits scriptFlagPrefix)
)
where
toScriptWitnessFiles :: ScriptFile
-> Maybe (ScriptDatumOrFile witctx,
ScriptRedeemerOrFile,
ExecutionUnits)
-> ScriptWitnessFiles witctx
toScriptWitnessFiles sf Nothing = SimpleScriptWitnessFile sf
toScriptWitnessFiles sf (Just (d,r, e)) = PlutusScriptWitnessFiles sf d r e
pExecutionUnits :: String -> Parser ExecutionUnits
pExecutionUnits scriptFlagPrefix =
uncurry ExecutionUnits <$>
Opt.option Opt.auto
( Opt.long (scriptFlagPrefix ++ "-execution-units")
<> Opt.metavar "(INT, INT)"
<> Opt.help "The time and space units needed by the script."
)
pScriptRedeemerOrFile :: String -> Parser ScriptDataOrFile
pScriptRedeemerOrFile scriptFlagPrefix =
pScriptDataOrFile (scriptFlagPrefix ++ "-redeemer")
"The script redeemer, in JSON syntax."
"The script redeemer, in the given JSON file."
pScriptDatumOrFile :: String -> WitCtx witctx -> Parser (ScriptDatumOrFile witctx)
pScriptDatumOrFile scriptFlagPrefix witctx =
case witctx of
WitCtxTxIn -> (ScriptDatumOrFileForTxIn <$>
pScriptDataOrFile
(scriptFlagPrefix ++ "-datum")
"The script datum, in JSON syntax."
"The script datum, in the given JSON file.") <|>
pInlineDatumPresent
WitCtxMint -> pure NoScriptDatumOrFileForMint
WitCtxStake -> pure NoScriptDatumOrFileForStake
where
pInlineDatumPresent :: Parser (ScriptDatumOrFile WitCtxTxIn)
pInlineDatumPresent =
flag' InlineDatumPresentAtTxIn
( long (scriptFlagPrefix ++ "-inline-datum-present")
<> Opt.help "Inline datum present at transaction input."
)
pScriptDataOrFile :: String -> String -> String -> Parser ScriptDataOrFile
pScriptDataOrFile dataFlagPrefix helpTextForValue helpTextForFile =
pScriptDataCborFile
<|> pScriptDataFile
<|> pScriptDataValue
where
pScriptDataCborFile = fmap ScriptDataCborFile . Opt.strOption $ mconcat
[ Opt.long (dataFlagPrefix ++ "-cbor-file")
, Opt.metavar "CBOR FILE"
, Opt.help $ mconcat
[ helpTextForFile
, " The file must follow the special JSON schema for script data."
]
]
pScriptDataFile = fmap ScriptDataJsonFile . Opt.strOption $ mconcat
[ Opt.long (dataFlagPrefix ++ "-file")
, Opt.metavar "JSON FILE"
, Opt.help $ mconcat
[ helpTextForFile ++ " The file must follow the special "
, "JSON schema for script data."
]
]
pScriptDataValue = fmap ScriptDataValue . Opt.option readerScriptData $ mconcat
[ Opt.long (dataFlagPrefix ++ "-value")
, Opt.metavar "JSON VALUE"
, Opt.help $ mconcat
[ helpTextForValue
, " There is no schema: (almost) any JSON value is supported, including "
, "top-level strings and numbers."
]
]
readerScriptData :: ReadM HashableScriptData
readerScriptData = do
v <- Opt.str
case Aeson.eitherDecode v of
Left e -> fail $ "readerScriptData: " <> e
Right sDataValue ->
case scriptDataJsonToHashable ScriptDataJsonNoSchema sDataValue of
Left err -> fail (displayError err)
Right sd -> return sd
pStakeAddressCmd :: EnvCli -> Parser StakeAddressCmd
pStakeAddressCmd envCli =
asum
[ subParser "key-gen"
(Opt.info pStakeAddressKeyGen $ Opt.progDesc "Create a stake address key pair")
, subParser "build"
(Opt.info pStakeAddressBuild $ Opt.progDesc "Build a stake address")
, subParser "key-hash"
(Opt.info pStakeAddressKeyHash $ Opt.progDesc "Print the hash of a stake address key.")
, subParser "registration-certificate"
(Opt.info pStakeAddressRegistrationCert $ Opt.progDesc "Create a stake address registration certificate")
, subParser "deregistration-certificate"
(Opt.info pStakeAddressDeregistrationCert $ Opt.progDesc "Create a stake address deregistration certificate")
, subParser "pool-delegation-certificate"
(Opt.info pStakeAddressPoolDelegationCert $ Opt.progDesc "Create a stake address pool delegation certificate")
]
where
pStakeAddressKeyGen :: Parser StakeAddressCmd
pStakeAddressKeyGen =
StakeAddressKeyGen
<$> pVerificationKeyFileOut
<*> pSigningKeyFileOut
pStakeAddressKeyHash :: Parser StakeAddressCmd
pStakeAddressKeyHash = StakeAddressKeyHash <$> pStakeVerificationKeyOrFile <*> pMaybeOutputFile
pStakeAddressBuild :: Parser StakeAddressCmd
pStakeAddressBuild =
StakeAddressBuild
<$> pStakeVerifier
<*> pNetworkId envCli
<*> pMaybeOutputFile
pStakeAddressRegistrationCert :: Parser StakeAddressCmd
pStakeAddressRegistrationCert =
StakeRegistrationCert
<$> pStakeIdentifier
<*> pOutputFile
pStakeAddressDeregistrationCert :: Parser StakeAddressCmd
pStakeAddressDeregistrationCert =
StakeCredentialDeRegistrationCert
<$> pStakeIdentifier
<*> pOutputFile
pStakeAddressPoolDelegationCert :: Parser StakeAddressCmd
pStakeAddressPoolDelegationCert =
StakeCredentialDelegationCert
<$> pStakeIdentifier
<*> pPoolDelegationTarget
<*> pOutputFile
pKeyCmd :: Parser KeyCmd
pKeyCmd =
asum
[ subParser "verification-key" $
Opt.info pKeyGetVerificationKey $
Opt.progDesc $ "Get a verification key from a signing key. This "
++ " supports all key types."
, subParser "non-extended-key" $
Opt.info pKeyNonExtendedKey $
Opt.progDesc $ "Get a non-extended verification key from an "
++ "extended verification key. This supports all "
++ "extended key types."
, subParser "convert-byron-key" $
Opt.info pKeyConvertByronKey $
Opt.progDesc $ "Convert a Byron payment, genesis or genesis "
++ "delegate key (signing or verification) to a "
++ "corresponding Shelley-format key."
, subParser "convert-byron-genesis-vkey" $
Opt.info pKeyConvertByronGenesisVKey $
Opt.progDesc $ "Convert a Base64-encoded Byron genesis "
++ "verification key to a Shelley genesis "
++ "verification key"
, subParser "convert-itn-key" $
Opt.info pKeyConvertITNKey $
Opt.progDesc $ "Convert an Incentivized Testnet (ITN) non-extended "
++ "(Ed25519) signing or verification key to a "
++ "corresponding Shelley stake key"
, subParser "convert-itn-extended-key" $
Opt.info pKeyConvertITNExtendedKey $
Opt.progDesc $ "Convert an Incentivized Testnet (ITN) extended "
++ "(Ed25519Extended) signing key to a corresponding "
++ "Shelley stake signing key"
, subParser "convert-itn-bip32-key" $
Opt.info pKeyConvertITNBip32Key $
Opt.progDesc $ "Convert an Incentivized Testnet (ITN) BIP32 "
++ "(Ed25519Bip32) signing key to a corresponding "
++ "Shelley stake signing key"
, subParser "convert-cardano-address-key" $
Opt.info pKeyConvertCardanoAddressSigningKey $
Opt.progDesc $ "Convert a cardano-address extended signing key "
++ "to a corresponding Shelley-format key."
]
where
pKeyGetVerificationKey :: Parser KeyCmd
pKeyGetVerificationKey =
KeyGetVerificationKey
<$> pSigningKeyFileIn
<*> pVerificationKeyFileOut
pKeyNonExtendedKey :: Parser KeyCmd
pKeyNonExtendedKey =
KeyNonExtendedKey
<$> pExtendedVerificationKeyFileIn
<*> pVerificationKeyFileOut
pKeyConvertByronKey :: Parser KeyCmd
pKeyConvertByronKey =
KeyConvertByronKey
<$> optional pPassword
<*> pByronKeyType
<*> pByronKeyFile
<*> pOutputFile
pPassword :: Parser Text
pPassword = Opt.strOption
( Opt.long "password"
<> Opt.metavar "TEXT"
<> Opt.help "Password for signing key (if applicable)."
)
pByronKeyType :: Parser ByronKeyType
pByronKeyType =
Opt.flag' (ByronPaymentKey NonLegacyByronKeyFormat)
( Opt.long "byron-payment-key-type"
<> Opt.help "Use a Byron-era payment key."
)
<|> Opt.flag' (ByronPaymentKey LegacyByronKeyFormat)
( Opt.long "legacy-byron-payment-key-type"
<> Opt.help "Use a Byron-era payment key, in legacy SL format."
)
<|> Opt.flag' (ByronGenesisKey NonLegacyByronKeyFormat)
( Opt.long "byron-genesis-key-type"
<> Opt.help "Use a Byron-era genesis key."
)
<|> Opt.flag' (ByronGenesisKey LegacyByronKeyFormat)
( Opt.long "legacy-byron-genesis-key-type"
<> Opt.help "Use a Byron-era genesis key, in legacy SL format."
)
<|> Opt.flag' (ByronDelegateKey NonLegacyByronKeyFormat)
( Opt.long "byron-genesis-delegate-key-type"
<> Opt.help "Use a Byron-era genesis delegate key."
)
<|> Opt.flag' (ByronDelegateKey LegacyByronKeyFormat)
( Opt.long "legacy-byron-genesis-delegate-key-type"
<> Opt.help "Use a Byron-era genesis delegate key, in legacy SL format."
)
pByronKeyFile :: Parser (SomeKeyFile In)
pByronKeyFile =
(ASigningKeyFile <$> pByronSigningKeyFile)
<|> (AVerificationKeyFile <$> pByronVerificationKeyFile)
pByronSigningKeyFile :: Parser (SigningKeyFile In)
pByronSigningKeyFile =
fmap File $ Opt.strOption $ mconcat
[ Opt.long "byron-signing-key-file"
, Opt.metavar "FILE"
, Opt.help "Input filepath of the Byron-format signing key."
, Opt.completer (Opt.bashCompleter "file")
]
pByronVerificationKeyFile :: Parser (VerificationKeyFile In)
pByronVerificationKeyFile =
fmap File $ Opt.strOption $ mconcat
[ Opt.long "byron-verification-key-file"
, Opt.metavar "FILE"
, Opt.help "Input filepath of the Byron-format verification key."
, Opt.completer (Opt.bashCompleter "file")
]
pKeyConvertByronGenesisVKey :: Parser KeyCmd
pKeyConvertByronGenesisVKey =
KeyConvertByronGenesisVKey
<$> pByronGenesisVKeyBase64
<*> pOutputFile
pByronGenesisVKeyBase64 :: Parser VerificationKeyBase64
pByronGenesisVKeyBase64 =
VerificationKeyBase64 <$>
Opt.strOption
( Opt.long "byron-genesis-verification-key"
<> Opt.metavar "BASE64"
<> Opt.help "Base64 string for the Byron genesis verification key."
)
pKeyConvertITNKey :: Parser KeyCmd
pKeyConvertITNKey =
KeyConvertITNStakeKey
<$> pITNKeyFIle
<*> pOutputFile
pKeyConvertITNExtendedKey :: Parser KeyCmd
pKeyConvertITNExtendedKey =
KeyConvertITNExtendedToStakeKey
<$> pITNSigningKeyFile
<*> pOutputFile
pKeyConvertITNBip32Key :: Parser KeyCmd
pKeyConvertITNBip32Key =
KeyConvertITNBip32ToStakeKey
<$> pITNSigningKeyFile
<*> pOutputFile
pITNKeyFIle :: Parser (SomeKeyFile direction)
pITNKeyFIle = pITNSigningKeyFile
<|> pITNVerificationKeyFile
pITNSigningKeyFile :: Parser (SomeKeyFile direction)
pITNSigningKeyFile =
fmap (ASigningKeyFile . File) $ Opt.strOption $ mconcat
[ Opt.long "itn-signing-key-file"
, Opt.metavar "FILE"
, Opt.help "Filepath of the ITN signing key."
, Opt.completer (Opt.bashCompleter "file")
]
pITNVerificationKeyFile :: Parser (SomeKeyFile direction)
pITNVerificationKeyFile =
fmap (AVerificationKeyFile . File) $ Opt.strOption $ mconcat
[ Opt.long "itn-verification-key-file"
, Opt.metavar "FILE"
, Opt.help "Filepath of the ITN verification key."
, Opt.completer (Opt.bashCompleter "file")
]
pKeyConvertCardanoAddressSigningKey :: Parser KeyCmd
pKeyConvertCardanoAddressSigningKey =
KeyConvertCardanoAddressSigningKey
<$> pCardanoAddressKeyType
<*> pSigningKeyFileIn
<*> pOutputFile
pCardanoAddressKeyType :: Parser CardanoAddressKeyType
pCardanoAddressKeyType =
Opt.flag' CardanoAddressShelleyPaymentKey
( Opt.long "shelley-payment-key"
<> Opt.help "Use a Shelley-era extended payment key."
)
<|> Opt.flag' CardanoAddressShelleyStakeKey
( Opt.long "shelley-stake-key"
<> Opt.help "Use a Shelley-era extended stake key."
)
<|> Opt.flag' CardanoAddressIcarusPaymentKey
( Opt.long "icarus-payment-key"
<> Opt.help "Use a Byron-era extended payment key formatted in the Icarus style."
)
<|> Opt.flag' CardanoAddressByronPaymentKey
( Opt.long "byron-payment-key"
<> Opt.help "Use a Byron-era extended payment key formatted in the deprecated Byron style."
)
pTransaction :: EnvCli -> Parser TransactionCmd
pTransaction envCli =
asum
[ subParser "build-raw"
$ Opt.info pTransactionBuildRaw $ Opt.progDescDoc $ Just $ mconcat
[ pretty @String "Build a transaction (low-level, inconvenient)"
, line
, line
, H.yellow $ mconcat
[ "Please note the order of some cmd options is crucial. If used incorrectly may produce "
, "undesired tx body. See nested [] notation above for details."
]
]
, subParser "build"
$ Opt.info pTransactionBuild $ Opt.progDescDoc $ Just $ mconcat
[ pretty @String "Build a balanced transaction (automatically calculates fees)"
, line
, line
, H.yellow $ mconcat
[ "Please note "
, H.underline "the order"
, " of some cmd options is crucial. If used incorrectly may produce "
, "undesired tx body. See nested [] notation above for details."
]
]
, subParser "sign"
(Opt.info pTransactionSign $ Opt.progDesc "Sign a transaction")
, subParser "witness"
(Opt.info pTransactionCreateWitness $ Opt.progDesc "Create a transaction witness")
, subParser "assemble"
(Opt.info pTransactionAssembleTxBodyWit
$ Opt.progDesc "Assemble a tx body and witness(es) to form a transaction")
, pSignWitnessBackwardCompatible
, subParser "submit"
(Opt.info pTransactionSubmit . Opt.progDesc $
mconcat
[ "Submit a transaction to the local node whose Unix domain socket "
, "is obtained from the CARDANO_NODE_SOCKET_PATH environment variable."
]
)
, subParser "policyid"
(Opt.info pTransactionPolicyId $ Opt.progDesc "Calculate the PolicyId from the monetary policy script.")
, subParser "calculate-min-fee"
(Opt.info pTransactionCalculateMinFee $ Opt.progDesc "Calculate the minimum fee for a transaction.")
, subParser "calculate-min-required-utxo"
(Opt.info pTransactionCalculateMinReqUTxO $ Opt.progDesc "Calculate the minimum required UTxO for a transaction output.")
, pCalculateMinRequiredUtxoBackwardCompatible
, subParser "hash-script-data"
(Opt.info pTxHashScriptData $ Opt.progDesc "Calculate the hash of script data.")
, subParser "txid"
(Opt.info pTransactionId $ Opt.progDesc "Print a transaction identifier.")
, subParser "view" $
Opt.info pTransactionView $ Opt.progDesc "Print a transaction."
]
where
-- Backwards compatible parsers
calcMinValueInfo :: ParserInfo TransactionCmd
calcMinValueInfo =
Opt.info pTransactionCalculateMinReqUTxO
$ Opt.progDesc "DEPRECATED: Use 'calculate-min-required-utxo' instead."
pCalculateMinRequiredUtxoBackwardCompatible :: Parser TransactionCmd
pCalculateMinRequiredUtxoBackwardCompatible =
Opt.subparser
$ Opt.command "calculate-min-value" calcMinValueInfo <> Opt.internal
assembleInfo :: ParserInfo TransactionCmd
assembleInfo =
Opt.info pTransactionAssembleTxBodyWit
$ Opt.progDesc "Assemble a tx body and witness(es) to form a transaction"
pSignWitnessBackwardCompatible :: Parser TransactionCmd
pSignWitnessBackwardCompatible =
Opt.subparser
$ Opt.command "sign-witness" assembleInfo <> Opt.internal
pScriptValidity :: Parser ScriptValidity
pScriptValidity = asum
[ Opt.flag' ScriptValid $ mconcat
[ Opt.long "script-valid"
, Opt.help "Assertion that the script is valid. (default)"
]
, Opt.flag' ScriptInvalid $ mconcat
[ Opt.long "script-invalid"
, Opt.help $ mconcat
[ "Assertion that the script is invalid. "
, "If a transaction is submitted with such a script, "
, "the script will fail and the collateral will be taken."
]
]
]
pTransactionBuild :: Parser TransactionCmd
pTransactionBuild =
TxBuild <$> pSocketPath envCli
<*> pCardanoEra
<*> pConsensusModeParams
<*> pNetworkId envCli
<*> optional pScriptValidity
<*> optional pWitnessOverride
<*> some (pTxIn AutoBalance)
<*> many pReadOnlyReferenceTxIn
<*> many pRequiredSigner
<*> many pTxInCollateral
<*> optional pReturnCollateral
<*> optional pTotalCollateral
<*> many pTxOut
<*> pChangeAddress
<*> optional (pMintMultiAsset AutoBalance)
<*> optional pInvalidBefore
<*> optional pInvalidHereafter
<*> many (pCertificateFile AutoBalance)
<*> many (pWithdrawal AutoBalance)
<*> pTxMetadataJsonSchema
<*> many (pScriptFor
"auxiliary-script-file"
Nothing
"Filepath of auxiliary script(s)")
<*> many pMetadataFile
<*> optional pProtocolParamsFile
<*> optional pUpdateProposalFile
<*> optional pActionFileIn
<*> optional pVoteFileIn
<*> (OutputTxBodyOnly <$> pTxBodyFileOut <|> pCalculatePlutusScriptCost)
pChangeAddress :: Parser TxOutChangeAddress
pChangeAddress =
TxOutChangeAddress <$>
Opt.option (readerFromParsecParser parseAddressAny)
( Opt.long "change-address"
<> Opt.metavar "ADDRESS"
<> Opt.help "Address where ADA in excess of the tx fee will go to."
)
pTransactionBuildRaw :: Parser TransactionCmd
pTransactionBuildRaw =
TxBuildRaw
<$> pCardanoEra
<*> optional pScriptValidity
<*> some (pTxIn ManualBalance)
<*> many pReadOnlyReferenceTxIn
<*> many pTxInCollateral
<*> optional pReturnCollateral
<*> optional pTotalCollateral
<*> many pRequiredSigner
<*> many pTxOut
<*> optional (pMintMultiAsset ManualBalance)
<*> optional pInvalidBefore
<*> optional pInvalidHereafter
<*> optional pTxFee
<*> many (pCertificateFile ManualBalance )
<*> many (pWithdrawal ManualBalance)
<*> pTxMetadataJsonSchema
<*> many (pScriptFor "auxiliary-script-file" Nothing "Filepath of auxiliary script(s)")
<*> many pMetadataFile
<*> optional pProtocolParamsFile
<*> optional pUpdateProposalFile
<*> optional pActionFileIn
<*> optional pVoteFileIn
<*> pTxBodyFileOut
pTransactionSign :: Parser TransactionCmd
pTransactionSign =
TxSign
<$> pInputTxOrTxBodyFile
<*> many pWitnessSigningData
<*> optional (pNetworkId envCli)
<*> pTxFileOut
pTransactionCreateWitness :: Parser TransactionCmd
pTransactionCreateWitness =
TxCreateWitness
<$> pTxBodyFileIn
<*> pWitnessSigningData
<*> optional (pNetworkId envCli)
<*> pOutputFile
pTransactionAssembleTxBodyWit :: Parser TransactionCmd
pTransactionAssembleTxBodyWit =
TxAssembleTxBodyWitness
<$> pTxBodyFileIn
<*> many pWitnessFile
<*> pOutputFile
pTransactionSubmit :: Parser TransactionCmd
pTransactionSubmit =
TxSubmit
<$> pSocketPath envCli
<*> pConsensusModeParams
<*> pNetworkId envCli
<*> pTxSubmitFile
pTransactionPolicyId :: Parser TransactionCmd
pTransactionPolicyId = TxMintedPolicyId <$> pScript
pTransactionCalculateMinFee :: Parser TransactionCmd
pTransactionCalculateMinFee =
TxCalculateMinFee
<$> pTxBodyFileIn
<*> pNetworkId envCli
<*> pProtocolParamsFile
<*> pTxInCount
<*> pTxOutCount
<*> pTxShelleyWitnessCount
<*> pTxByronWitnessCount
pTransactionCalculateMinReqUTxO :: Parser TransactionCmd
pTransactionCalculateMinReqUTxO = TxCalculateMinRequiredUTxO
<$> pCardanoEra
<*> pProtocolParamsFile
<*> pTxOut
pTxHashScriptData :: Parser TransactionCmd
pTxHashScriptData = TxHashScriptData <$>
pScriptDataOrFile
"script-data"
"The script data, in JSON syntax."
"The script data, in the given JSON file."
pTransactionId :: Parser TransactionCmd
pTransactionId = TxGetTxId <$> pInputTxOrTxBodyFile
pTransactionView :: Parser TransactionCmd
pTransactionView = TxView <$> pInputTxOrTxBodyFile
pGovernanceCcCmd :: Parser CcCmd
pGovernanceCcCmd =
asum
[ subParser "key-gen" . Opt.info pKeyGenOperator . Opt.progDesc $ mconcat
[ "Create a key pair for a CCM's offline "
, "key and a new certificate issue counter"
]
, subParser "key-gen-VRF" . Opt.info pKeyGenVRF . Opt.progDesc $ mconcat
[ "Create a key pair for a CCM VRF operational key"
]
, subParser "key-hash-VRF". Opt.info pKeyHashVRF . Opt.progDesc $ mconcat
[ "Print hash of a CCM's operational VRF key."
]
, subParser "new-counter" . Opt.info pNewCounter . Opt.progDesc $ mconcat
[ "Create a new certificate issue counter"
]
, subParser "issue-op-cert" . Opt.info pIssueOpCert . Opt.progDesc $ mconcat
[ "Issue a CCM operational certificate"
]
]
where
pKeyGenOperator :: Parser CcCmd
pKeyGenOperator =
CcKeyGenCold
<$> pColdVerificationKeyFile
<*> pColdSigningKeyFile
<*> pOperatorCertIssueCounterFile
pKeyGenVRF :: Parser CcCmd
pKeyGenVRF =
CcKeyGenVRF
<$> pVerificationKeyFileOut
<*> pSigningKeyFileOut
pKeyHashVRF :: Parser CcCmd
pKeyHashVRF =
CcKeyHashVRF
<$> pVerificationKeyOrFile AsVrfKey
<*> pMaybeOutputFile
pNewCounter :: Parser CcCmd
pNewCounter =
CcNewCounter
<$> pColdVerificationKeyOrFile
<*> pCounterValue
<*> pOperatorCertIssueCounterFile
pCounterValue :: Parser Word
pCounterValue =
Opt.option Opt.auto $ mconcat
[ Opt.long "counter-value"
, Opt.metavar "INT"
, Opt.help "The next certificate issue counter value to use."
]
pIssueOpCert :: Parser CcCmd
pIssueOpCert =
CcIssueOpCert
<$> pKesVerificationKeyOrFile
<*> pColdSigningKeyFile
<*> pOperatorCertIssueCounterFile
<*> pKesPeriod
<*> pOutputFile
pNodeCmd :: Parser NodeCmd
pNodeCmd =
asum
[ subParser "key-gen" . Opt.info pKeyGenOperator . Opt.progDesc $ mconcat
[ "Create a key pair for a node operator's offline "
, "key and a new certificate issue counter"
]
, subParser "key-gen-KES" . Opt.info pKeyGenKES . Opt.progDesc $ mconcat
[ "Create a key pair for a node KES operational key"
]
, subParser "key-gen-VRF" . Opt.info pKeyGenVRF . Opt.progDesc $ mconcat
[ "Create a key pair for a node VRF operational key"
]
, subParser "key-hash-VRF". Opt.info pKeyHashVRF . Opt.progDesc $ mconcat
[ "Print hash of a node's operational VRF key."
]
, subParser "new-counter" . Opt.info pNewCounter . Opt.progDesc $ mconcat
[ "Create a new certificate issue counter"
]
, subParser "issue-op-cert" . Opt.info pIssueOpCert . Opt.progDesc $ mconcat
[ "Issue a node operational certificate"
]
]
where
pKeyGenOperator :: Parser NodeCmd
pKeyGenOperator =
NodeKeyGenCold
<$> pColdVerificationKeyFile
<*> pColdSigningKeyFile
<*> pOperatorCertIssueCounterFile
pKeyGenKES :: Parser NodeCmd
pKeyGenKES =
NodeKeyGenKES <$> pVerificationKeyFileOut <*> pSigningKeyFileOut
pKeyGenVRF :: Parser NodeCmd
pKeyGenVRF =
NodeKeyGenVRF <$> pVerificationKeyFileOut <*> pSigningKeyFileOut
pKeyHashVRF :: Parser NodeCmd
pKeyHashVRF =
NodeKeyHashVRF <$> pVerificationKeyOrFile AsVrfKey <*> pMaybeOutputFile
pNewCounter :: Parser NodeCmd
pNewCounter =
NodeNewCounter <$> pColdVerificationKeyOrFile
<*> pCounterValue
<*> pOperatorCertIssueCounterFile
pCounterValue :: Parser Word
pCounterValue =
Opt.option Opt.auto
( Opt.long "counter-value"
<> Opt.metavar "INT"
<> Opt.help "The next certificate issue counter value to use."
)
pIssueOpCert :: Parser NodeCmd
pIssueOpCert =
NodeIssueOpCert <$> pKesVerificationKeyOrFile
<*> pColdSigningKeyFile
<*> pOperatorCertIssueCounterFile
<*> pKesPeriod
<*> pOutputFile
pPoolCmd :: EnvCli -> Parser PoolCmd
pPoolCmd envCli =
asum
[ subParser "registration-certificate"
(Opt.info (pStakePoolRegistrationCert envCli) $ Opt.progDesc "Create a stake pool registration certificate")
, subParser "deregistration-certificate"
(Opt.info pStakePoolRetirementCert $ Opt.progDesc "Create a stake pool deregistration certificate")
, subParser "id"
(Opt.info pId $ Opt.progDesc "Build pool id from the offline key")
, subParser "metadata-hash"
(Opt.info pPoolMetadataHashSubCmd $ Opt.progDesc "Print the hash of pool metadata.")
]
where
pId :: Parser PoolCmd
pId = PoolGetId <$> pPoolVerificationKeyOrFile <*> pOutputFormat
pPoolMetadataHashSubCmd :: Parser PoolCmd
pPoolMetadataHashSubCmd = PoolMetadataHash <$> pPoolMetadataFile <*> pMaybeOutputFile
pQueryCmd :: EnvCli -> Parser QueryCmd
pQueryCmd envCli =
asum
[ subParser "protocol-parameters"
(Opt.info pQueryProtocolParameters $ Opt.progDesc "Get the node's current protocol parameters")
, subParser "tip"
(Opt.info pQueryTip $ Opt.progDesc "Get the node's current tip (slot no, hash, block no)")
, subParser "stake-pools"
(Opt.info pQueryStakePools $ Opt.progDesc "Get the node's current set of stake pool ids")
, subParser "stake-distribution"
(Opt.info pQueryStakeDistribution $ Opt.progDesc "Get the node's current aggregated stake distribution")