/
Parsers.hs
2350 lines (2086 loc) · 77.1 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 FlexibleContexts #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Cardano.CLI.Shelley.Parsers
( -- * CLI command parser
parseShelleyCommands
-- * CLI command and flag types
, module Cardano.CLI.Shelley.Commands
-- * Field parser and renderers
, parseTxIn
, renderTxIn
) where
import Cardano.Prelude hiding (All, Any, option)
import Prelude (String)
import Cardano.Api.CliMode (CliMode (..))
import Cardano.Api.Typed hiding (PoolId)
import Cardano.Chain.Slotting (EpochSlots (..))
import Cardano.CLI.Shelley.Commands
import Cardano.CLI.Shelley.Key (InputFormat (..), VerificationKeyOrFile (..),
VerificationKeyOrHashOrFile (..), VerificationKeyTextOrFile (..),
deserialiseInput, renderInputDecodeError)
import Cardano.CLI.Types
import Control.Monad.Fail (fail)
import Data.Attoparsec.Combinator ((<?>))
import Data.Time.Clock (UTCTime)
import Data.Time.Format (defaultTimeLocale, iso8601DateFormat, parseTimeOrError)
import Network.Socket (PortNumber)
import Options.Applicative hiding (str)
import Ouroboros.Consensus.BlockchainTime (SystemStart (..))
import qualified Data.Attoparsec.ByteString.Char8 as Atto
import qualified Data.ByteString.Char8 as BSC
import qualified Data.Char as Char
import qualified Data.IP as IP
import qualified Data.List.NonEmpty as NE
import qualified Data.Set as Set
import qualified Data.Text as Text
import qualified Data.Text.Encoding as Text
import qualified Options.Applicative as Opt
import qualified Shelley.Spec.Ledger.BaseTypes as Shelley
import qualified Shelley.Spec.Ledger.TxBody as Shelley
--
-- Shelley CLI command parsers
--
parseShelleyCommands :: Parser ShelleyCommand
parseShelleyCommands =
Opt.subparser $
mconcat
[ Opt.command "address"
(Opt.info (AddressCmd <$> pAddressCmd) $ Opt.progDesc "Shelley payment address commands")
, Opt.command "stake-address"
(Opt.info (StakeAddressCmd <$> pStakeAddress) $ Opt.progDesc "Shelley stake address commands")
, Opt.command "key"
(Opt.info (KeyCmd <$> pKeyCmd) $ Opt.progDesc "Shelley key utility commands")
, Opt.command "transaction"
(Opt.info (TransactionCmd <$> pTransaction) $ Opt.progDesc "Shelley transaction commands")
, Opt.command "node"
(Opt.info (NodeCmd <$> pNodeCmd) $ Opt.progDesc "Shelley node operaton commands")
, Opt.command "stake-pool"
(Opt.info (PoolCmd <$> pPoolCmd) $ Opt.progDesc "Shelley stake pool commands")
, Opt.command "query"
(Opt.info (QueryCmd <$> pQueryCmd) . Opt.progDesc $
mconcat
[ "Shelley node query commands. Will query the local node whose Unix domain socket "
, "is obtained from the CARDANO_NODE_SOCKET_PATH enviromnent variable."
]
)
, Opt.command "genesis"
(Opt.info (GenesisCmd <$> pGenesisCmd) $ Opt.progDesc "Shelley genesis block commands")
, Opt.command "governance"
(Opt.info (GovernanceCmd <$> pGovernanceCmd) $ Opt.progDesc "Shelley 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 =
Opt.subparser $
mconcat
[ Opt.command "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 :: Parser AddressCmd
pAddressCmd =
Opt.subparser $
mconcat
[ Opt.command "key-gen"
(Opt.info pAddressKeyGen $ Opt.progDesc "Create an address key pair.")
, Opt.command "key-hash"
(Opt.info pAddressKeyHash $ Opt.progDesc "Print the hash of an address key.")
, Opt.command "build"
(Opt.info pAddressBuild $ Opt.progDesc "Build a Shelley payment address, with optional delegation to a stake address.")
, Opt.command "build-script"
(Opt.info pAddressBuildScript $ Opt.progDesc "Build a Shelley script address.")
, Opt.command "info"
(Opt.info pAddressInfo $ Opt.progDesc "Print information about an address.")
]
where
pAddressKeyGen :: Parser AddressCmd
pAddressKeyGen = AddressKeyGen <$> pAddressKeyType
<*> pVerificationKeyFile Output
<*> pSigningKeyFile Output
pAddressKeyHash :: Parser AddressCmd
pAddressKeyHash =
AddressKeyHash
<$> pPaymentVerificationKeyTextOrFile
<*> pMaybeOutputFile
pAddressBuild :: Parser AddressCmd
pAddressBuild =
AddressBuild
<$> pPaymentVerificationKeyTextOrFile
<*> Opt.optional pStakeVerificationKeyOrFile
<*> pNetworkId
<*> pMaybeOutputFile
pAddressBuildScript :: Parser AddressCmd
pAddressBuildScript = AddressBuildMultiSig
<$> pScript
<*> pNetworkId
<*> pMaybeOutputFile
pAddressInfo :: Parser AddressCmd
pAddressInfo = AddressInfo <$> pAddress <*> pMaybeOutputFile
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
pPaymentVerificationKeyFile =
VerificationKeyFile <$>
( Opt.strOption
( Opt.long "payment-verification-key-file"
<> Opt.metavar "FILE"
<> Opt.help "Filepath of the payment verification key."
<> Opt.completer (Opt.bashCompleter "file")
)
<|>
Opt.strOption
( Opt.long "verification-key-file"
<> Opt.internal
)
)
pScript :: Parser ScriptFile
pScript = ScriptFile <$> Opt.strOption
( Opt.long "script-file"
<> Opt.metavar "FILE"
<> Opt.help "Filepath of the script."
<> Opt.completer (Opt.bashCompleter "file")
)
pStakeAddress :: Parser StakeAddressCmd
pStakeAddress =
Opt.subparser $
mconcat
[ Opt.command "key-gen"
(Opt.info pStakeAddressKeyGen $ Opt.progDesc "Create a stake address key pair")
, Opt.command "build"
(Opt.info pStakeAddressBuild $ Opt.progDesc "Build a stake address")
, Opt.command "key-hash"
(Opt.info pStakeAddressKeyHash $ Opt.progDesc "Print the hash of a stake address key.")
, Opt.command "registration-certificate"
(Opt.info pStakeAddressRegistrationCert $ Opt.progDesc "Create a stake address registration certificate")
, Opt.command "deregistration-certificate"
(Opt.info pStakeAddressDeregistrationCert $ Opt.progDesc "Create a stake address deregistration certificate")
, Opt.command "delegation-certificate"
(Opt.info pStakeAddressDelegationCert $ Opt.progDesc "Create a stake address delegation certificate")
]
where
pStakeAddressKeyGen :: Parser StakeAddressCmd
pStakeAddressKeyGen = StakeAddressKeyGen
<$> pVerificationKeyFile Output
<*> pSigningKeyFile Output
pStakeAddressKeyHash :: Parser StakeAddressCmd
pStakeAddressKeyHash = StakeAddressKeyHash <$> pStakeVerificationKeyOrFile <*> pMaybeOutputFile
pStakeAddressBuild :: Parser StakeAddressCmd
pStakeAddressBuild = StakeAddressBuild <$> pStakeVerificationKeyOrFile
<*> pNetworkId
<*> pMaybeOutputFile
pStakeAddressRegistrationCert :: Parser StakeAddressCmd
pStakeAddressRegistrationCert = StakeKeyRegistrationCert
<$> pStakeVerificationKeyOrFile
<*> pOutputFile
pStakeAddressDeregistrationCert :: Parser StakeAddressCmd
pStakeAddressDeregistrationCert = StakeKeyDeRegistrationCert
<$> pStakeVerificationKeyOrFile
<*> pOutputFile
pStakeAddressDelegationCert :: Parser StakeAddressCmd
pStakeAddressDelegationCert = StakeKeyDelegationCert
<$> pStakeVerificationKeyOrFile
<*> pStakePoolVerificationKeyOrHashOrFile
<*> pOutputFile
pKeyCmd :: Parser KeyCmd
pKeyCmd =
Opt.subparser $
mconcat
[ Opt.command "verification-key" $
Opt.info pKeyGetVerificationKey $
Opt.progDesc $ "Get a verification key from a signing key. This "
++ " supports all key types."
, Opt.command "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."
, Opt.command "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."
, Opt.command "convert-byron-genesis-vkey" $
Opt.info pKeyConvertByronGenesisVKey $
Opt.progDesc $ "Convert a Base64-encoded Byron genesis "
++ "verification key to a Shelley genesis "
++ "verification key"
, Opt.command "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"
, Opt.command "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"
, Opt.command "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"
, Opt.command "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
<$> pSigningKeyFile Input
<*> pVerificationKeyFile Output
pKeyNonExtendedKey :: Parser KeyCmd
pKeyNonExtendedKey =
KeyNonExtendedKey
<$> pExtendedVerificationKeyFile Input
<*> pVerificationKeyFile Output
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
pByronKeyFile =
(ASigningKeyFile <$> pByronSigningKeyFile)
<|> (AVerificationKeyFile <$> pByronVerificationKeyFile)
pByronSigningKeyFile :: Parser SigningKeyFile
pByronSigningKeyFile =
SigningKeyFile <$>
Opt.strOption
( 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
pByronVerificationKeyFile =
VerificationKeyFile <$>
Opt.strOption
( 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
pITNKeyFIle = pITNSigningKeyFile
<|> pITNVerificationKeyFile
pITNSigningKeyFile :: Parser SomeKeyFile
pITNSigningKeyFile =
ASigningKeyFile . SigningKeyFile <$>
Opt.strOption
( 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
pITNVerificationKeyFile =
AVerificationKeyFile . VerificationKeyFile <$>
Opt.strOption
( 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
<*> pSigningKeyFile Input
<*> 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 :: Parser TransactionCmd
pTransaction =
asum
[ subParser "build-raw"
(Opt.info pTransactionBuild $ Opt.progDesc "Build a transaction (low-level, inconvenient)")
, 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 enviromnent 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 "txid"
(Opt.info pTransactionId $ Opt.progDesc "Print a transaction identifier")
]
where
subParser :: String -> ParserInfo TransactionCmd -> Parser TransactionCmd
subParser name pInfo = Opt.subparser $ Opt.command name pInfo
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
pTransactionBuild :: Parser TransactionCmd
pTransactionBuild = TxBuildRaw <$> pUseCardanoEra
<*> some pTxIn
<*> some pTxOut
<*> optional pMintMultiAsset
<*> optional pTxLowerBound
<*> optional pTxUpperBound
<*> optional pTxFee
<*> many pCertificateFile
<*> many pWithdrawal
<*> pTxMetadataJsonSchema
<*> many pScript
<*> many pMetaDataFile
<*> optional pUpdateProposalFile
<*> pTxBodyFile Output
pTransactionSign :: Parser TransactionCmd
pTransactionSign = TxSign <$> pTxBodyFile Input
<*> pSomeWitnessSigningData
<*> optional pNetworkId
<*> pTxFile Output
pTransactionCreateWitness :: Parser TransactionCmd
pTransactionCreateWitness = TxCreateWitness
<$> pTxBodyFile Input
<*> pWitnessSigningData
<*> optional pNetworkId
<*> pOutputFile
pTransactionAssembleTxBodyWit :: Parser TransactionCmd
pTransactionAssembleTxBodyWit = TxAssembleTxBodyWitness
<$> pTxBodyFile Input
<*> some pWitnessFile
<*> pOutputFile
pTransactionSubmit :: Parser TransactionCmd
pTransactionSubmit = TxSubmit <$> pCliMode
<*> pNetworkId
<*> pTxSubmitFile
pTransactionPolicyId :: Parser TransactionCmd
pTransactionPolicyId = TxMintedPolicyId <$> pScript
pTransactionCalculateMinFee :: Parser TransactionCmd
pTransactionCalculateMinFee =
TxCalculateMinFee
<$> pTxBodyFile Input
<*> optional pNetworkId
<*> pProtocolParamsFile
<*> pTxInCount
<*> pTxOutCount
<*> pTxShelleyWitnessCount
<*> pTxByronWitnessCount
pTransactionId :: Parser TransactionCmd
pTransactionId = TxGetTxId <$> pTxBodyFile Input
pNodeCmd :: Parser NodeCmd
pNodeCmd =
Opt.subparser $
mconcat
[ Opt.command "key-gen"
(Opt.info pKeyGenOperator $
Opt.progDesc "Create a key pair for a node operator's offline \
\ key and a new certificate issue counter")
, Opt.command "key-gen-KES"
(Opt.info pKeyGenKES $
Opt.progDesc "Create a key pair for a node KES operational key")
, Opt.command "key-gen-VRF"
(Opt.info pKeyGenVRF $
Opt.progDesc "Create a key pair for a node VRF operational key")
, Opt.command "key-hash-VRF"
(Opt.info pKeyHashVRF $
Opt.progDesc "Print hash of a node's operational VRF key.")
, Opt.command "new-counter"
(Opt.info pNewCounter $
Opt.progDesc "Create a new certificate issue counter")
, Opt.command "issue-op-cert"
(Opt.info pIssueOpCert $
Opt.progDesc "Issue a node operational certificate")
]
where
pKeyGenOperator :: Parser NodeCmd
pKeyGenOperator =
NodeKeyGenCold <$> pColdVerificationKeyFile
<*> pColdSigningKeyFile
<*> pOperatorCertIssueCounterFile
pKeyGenKES :: Parser NodeCmd
pKeyGenKES =
NodeKeyGenKES <$> pVerificationKeyFile Output <*> pSigningKeyFile Output
pKeyGenVRF :: Parser NodeCmd
pKeyGenVRF =
NodeKeyGenVRF <$> pVerificationKeyFile Output <*> pSigningKeyFile Output
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 :: Parser PoolCmd
pPoolCmd =
Opt.subparser $
mconcat
[ Opt.command "registration-certificate"
(Opt.info pStakePoolRegistrationCert $ Opt.progDesc "Create a stake pool registration certificate")
, Opt.command "deregistration-certificate"
(Opt.info pStakePoolRetirementCert $ Opt.progDesc "Create a stake pool deregistration certificate")
, Opt.command "id"
(Opt.info pId $
Opt.progDesc "Build pool id from the offline key")
, Opt.command "metadata-hash"
(Opt.info pPoolMetaDataHashSubCmd $ Opt.progDesc "Print the hash of pool metadata.")
]
where
pId :: Parser PoolCmd
pId = PoolGetId <$> pStakePoolVerificationKeyOrFile <*> pOutputFormat
pPoolMetaDataHashSubCmd :: Parser PoolCmd
pPoolMetaDataHashSubCmd = PoolMetaDataHash <$> pPoolMetaDataFile <*> pMaybeOutputFile
pQueryCmd :: Parser QueryCmd
pQueryCmd =
Opt.subparser $
mconcat
[ Opt.command "protocol-parameters"
(Opt.info pQueryProtocolParameters $ Opt.progDesc "Get the node's current protocol parameters")
, Opt.command "tip"
(Opt.info pQueryTip $ Opt.progDesc "Get the node's current tip (slot no, hash, block no)")
, Opt.command "stake-distribution"
(Opt.info pQueryStakeDistribution $ Opt.progDesc "Get the node's current aggregated stake distribution")
, Opt.command "stake-address-info"
(Opt.info pQueryStakeAddressInfo $ Opt.progDesc "Get the current delegations and \
\reward accounts filtered by stake \
\address.")
, Opt.command "utxo"
(Opt.info pQueryUTxO $ Opt.progDesc "Get the node's current UTxO with the option of \
\filtering by address(es)")
, Opt.command "ledger-state"
(Opt.info pQueryLedgerState $ Opt.progDesc "Dump the current ledger state of the node (Ledger.NewEpochState -- advanced command)")
, Opt.command "protocol-state"
(Opt.info pQueryProtocolState $ Opt.progDesc "Dump the current protocol state of the node (Ledger.ChainDepState -- advanced command)")
]
where
pQueryProtocolParameters :: Parser QueryCmd
pQueryProtocolParameters =
QueryProtocolParameters
<$> pCliMode
<*> pNetworkId
<*> pMaybeOutputFile
pQueryTip :: Parser QueryCmd
pQueryTip = QueryTip <$> pCliMode <*> pNetworkId <*> pMaybeOutputFile
pQueryUTxO :: Parser QueryCmd
pQueryUTxO =
QueryUTxO
<$> pCliMode
<*> pQueryFilter
<*> pNetworkId
<*> pMaybeOutputFile
pQueryStakeDistribution :: Parser QueryCmd
pQueryStakeDistribution =
QueryStakeDistribution
<$> pCliMode
<*> pNetworkId
<*> pMaybeOutputFile
pQueryStakeAddressInfo :: Parser QueryCmd
pQueryStakeAddressInfo =
QueryStakeAddressInfo
<$> pCliMode
<*> pFilterByStakeAddress
<*> pNetworkId
<*> pMaybeOutputFile
pQueryLedgerState :: Parser QueryCmd
pQueryLedgerState = QueryLedgerState <$> pCliMode <*> pNetworkId <*> pMaybeOutputFile
pQueryProtocolState :: Parser QueryCmd
pQueryProtocolState = QueryProtocolState <$> pCliMode <*> pNetworkId <*> pMaybeOutputFile
pGovernanceCmd :: Parser GovernanceCmd
pGovernanceCmd =
Opt.subparser $
mconcat
[ Opt.command "create-mir-certificate"
(Opt.info pMIRCertificate $
Opt.progDesc "Create an MIR (Move Instantaneous Rewards) certificate")
, Opt.command "create-genesis-key-delegation-certificate"
(Opt.info pGovernanceGenesisKeyDelegationCertificate $
Opt.progDesc "Create a genesis key delegation certificate")
, Opt.command "create-update-proposal"
(Opt.info pUpdateProposal $
Opt.progDesc "Create an update proposal")
]
where
pMIRCertificate :: Parser GovernanceCmd
pMIRCertificate = GovernanceMIRCertificate
<$> pMIRPot
<*> some pStakeVerificationKeyFile
<*> some pRewardAmt
<*> pOutputFile
pGovernanceGenesisKeyDelegationCertificate :: Parser GovernanceCmd
pGovernanceGenesisKeyDelegationCertificate =
GovernanceGenesisKeyDelegationCertificate
<$> pGenesisVerificationKeyOrHashOrFile
<*> pGenesisDelegateVerificationKeyOrHashOrFile
<*> pVrfVerificationKeyOrHashOrFile
<*> pOutputFile
pMIRPot :: Parser Shelley.MIRPot
pMIRPot =
Opt.flag' Shelley.ReservesMIR
( Opt.long "reserves"
<> Opt.help "Use the reserves pot."
)
<|> Opt.flag' Shelley.TreasuryMIR
( Opt.long "treasury"
<> Opt.help "Use the treasury pot."
)
pUpdateProposal :: Parser GovernanceCmd
pUpdateProposal = GovernanceUpdateProposal
<$> pOutputFile
<*> pEpochNoUpdateProp
<*> some pGenesisVerificationKeyFile
<*> pShelleyProtocolParametersUpdate
pRewardAmt :: Parser Lovelace
pRewardAmt =
Opt.option (readerFromAttoParser parseLovelace)
( Opt.long "reward"
<> Opt.metavar "LOVELACE"
<> Opt.help "The reward for the relevant reward account."
)
pGenesisCmd :: Parser GenesisCmd
pGenesisCmd =
Opt.subparser $
mconcat
[ Opt.command "key-gen-genesis"
(Opt.info pGenesisKeyGen $
Opt.progDesc "Create a Shelley genesis key pair")
, Opt.command "key-gen-delegate"
(Opt.info pGenesisDelegateKeyGen $
Opt.progDesc "Create a Shelley genesis delegate key pair")
, Opt.command "key-gen-utxo"
(Opt.info pGenesisUTxOKeyGen $
Opt.progDesc "Create a Shelley genesis UTxO key pair")
, Opt.command "key-hash"
(Opt.info pGenesisKeyHash $
Opt.progDesc "Print the identifier (hash) of a public key")
, Opt.command "get-ver-key"
(Opt.info pGenesisVerKey $
Opt.progDesc "Derive the verification key from a signing key")
, Opt.command "initial-addr"
(Opt.info pGenesisAddr $
Opt.progDesc "Get the address for an initial UTxO based on the verification key")
, Opt.command "initial-txin"
(Opt.info pGenesisTxIn $
Opt.progDesc "Get the TxIn for an initial UTxO based on the verification key")
, Opt.command "create"
(Opt.info pGenesisCreate $
Opt.progDesc ("Create a Shelley genesis file from a genesis "
++ "template and genesis/delegation/spending keys."))
, Opt.command "hash"
(Opt.info pGenesisHash $
Opt.progDesc "Compute the hash of a genesis file")
]
where
pGenesisKeyGen :: Parser GenesisCmd
pGenesisKeyGen =
GenesisKeyGenGenesis <$> pVerificationKeyFile Output <*> pSigningKeyFile Output
pGenesisDelegateKeyGen :: Parser GenesisCmd
pGenesisDelegateKeyGen =
GenesisKeyGenDelegate <$> pVerificationKeyFile Output
<*> pSigningKeyFile Output
<*> pOperatorCertIssueCounterFile
pGenesisUTxOKeyGen :: Parser GenesisCmd
pGenesisUTxOKeyGen =
GenesisKeyGenUTxO <$> pVerificationKeyFile Output <*> pSigningKeyFile Output
pGenesisKeyHash :: Parser GenesisCmd
pGenesisKeyHash =
GenesisCmdKeyHash <$> pVerificationKeyFile Input
pGenesisVerKey :: Parser GenesisCmd
pGenesisVerKey =
GenesisVerKey <$> pVerificationKeyFile Output <*> pSigningKeyFile Output
pGenesisAddr :: Parser GenesisCmd
pGenesisAddr =
GenesisAddr <$> pVerificationKeyFile Input <*> pNetworkId <*> pMaybeOutputFile
pGenesisTxIn :: Parser GenesisCmd
pGenesisTxIn =
GenesisTxIn <$> pVerificationKeyFile Input <*> pNetworkId <*> pMaybeOutputFile
pGenesisCreate :: Parser GenesisCmd
pGenesisCreate =
GenesisCreate <$> pGenesisDir
<*> pGenesisNumGenesisKeys
<*> pGenesisNumUTxOKeys
<*> pMaybeSystemStart
<*> pInitialSupply
<*> pNetworkId
pGenesisHash :: Parser GenesisCmd
pGenesisHash =
GenesisHashFile <$> pGenesisFile
pGenesisDir :: Parser GenesisDir
pGenesisDir =
GenesisDir <$>
Opt.strOption
( Opt.long "genesis-dir"
<> Opt.metavar "DIR"
<> Opt.help "The genesis directory containing the genesis template and required genesis/delegation/spending keys."
)
pMaybeSystemStart :: Parser (Maybe SystemStart)
pMaybeSystemStart =
Opt.optional $
SystemStart . convertTime <$>
Opt.strOption
( Opt.long "start-time"
<> Opt.metavar "UTC-TIME"
<> Opt.help "The genesis start time in YYYY-MM-DDThh:mm:ssZ format. If unspecified, will be the current time +30 seconds."
)
pGenesisNumGenesisKeys :: Parser Word
pGenesisNumGenesisKeys =
Opt.option Opt.auto
( Opt.long "gen-genesis-keys"
<> Opt.metavar "INT"
<> Opt.help "The number of genesis keys to make [default is 0]."
<> Opt.value 0
)
pGenesisNumUTxOKeys :: Parser Word
pGenesisNumUTxOKeys =
Opt.option Opt.auto
( Opt.long "gen-utxo-keys"
<> Opt.metavar "INT"
<> Opt.help "The number of UTxO keys to make [default is 0]."
<> Opt.value 0
)
convertTime :: String -> UTCTime
convertTime =
parseTimeOrError False defaultTimeLocale (iso8601DateFormat $ Just "%H:%M:%SZ")
pInitialSupply :: Parser (Maybe Lovelace)
pInitialSupply =
Opt.optional $
Lovelace <$>
Opt.option Opt.auto
( Opt.long "supply"
<> Opt.metavar "LOVELACE"
<> Opt.help "The initial coin supply in Lovelace which will be evenly distributed across initial stake holders."
)
--
-- Shelley CLI flag parsers
--
data FileDirection
= Input
| Output
deriving (Eq, Show)
pAddressKeyType :: Parser AddressKeyType
pAddressKeyType =
Opt.flag' AddressKeyShelley
( Opt.long "normal-key"
<> Opt.help "Use a normal Shelley-era key (default)."
)
<|>
Opt.flag' AddressKeyShelleyExtended
( Opt.long "extended-key"
<> Opt.help "Use an extended ed25519 Shelley-era key."
)
<|>
Opt.flag' AddressKeyByron
( Opt.long "byron-key"
<> Opt.help "Use a Byron-era key."
)
<|>
pure AddressKeyShelley
pProtocolParamsFile :: Parser ProtocolParamsFile
pProtocolParamsFile =
ProtocolParamsFile <$>
Opt.strOption
( Opt.long "protocol-params-file"
<> Opt.metavar "FILE"
<> Opt.help "Filepath of the JSON-encoded protocol parameters file"
<> Opt.completer (Opt.bashCompleter "file")
)
pCertificateFile :: Parser CertificateFile
pCertificateFile =
CertificateFile <$>
( Opt.strOption
( Opt.long "certificate-file"
<> Opt.metavar "FILE"
<> Opt.help "Filepath of the certificate. This encompasses all \
\types of certificates (stake pool certificates, \
\stake key certificates etc)"
<> Opt.completer (Opt.bashCompleter "file")
)
<|>
Opt.strOption
( Opt.long "certificate"
<> Opt.internal
)
)
pPoolMetaDataFile :: Parser PoolMetaDataFile
pPoolMetaDataFile =
PoolMetaDataFile <$>
Opt.strOption
( Opt.long "pool-metadata-file"
<> Opt.metavar "FILE"
<> Opt.help "Filepath of the pool metadata."
<> Opt.completer (Opt.bashCompleter "file")
)
pTxMetadataJsonSchema :: Parser TxMetadataJsonSchema
pTxMetadataJsonSchema =
( Opt.flag' ()
( Opt.long "json-metadata-no-schema"
<> Opt.help "Use the \"no schema\" conversion from JSON to tx metadata."
)
*> pure TxMetadataJsonNoSchema
)
<|>
( Opt.flag' ()
( Opt.long "json-metadata-detailed-schema"
<> Opt.help "Use the \"detailed schema\" conversion from JSON to tx metadata."
)
*> pure TxMetadataJsonDetailedSchema
)
<|>
-- Default to the no-schema conversion.
pure TxMetadataJsonNoSchema
pMetaDataFile :: Parser MetaDataFile
pMetaDataFile =
MetaDataFileJSON <$>
( Opt.strOption
( Opt.long "metadata-json-file"
<> Opt.metavar "FILE"
<> Opt.help "Filepath of the metadata file, in JSON format."
<> Opt.completer (Opt.bashCompleter "file")
)
<|>
Opt.strOption
( Opt.long "metadata-file" -- backward compat name
<> Opt.internal
)
)
<|>
MetaDataFileCBOR <$>
Opt.strOption
( Opt.long "metadata-cbor-file"
<> Opt.metavar "FILE"
<> Opt.help "Filepath of the metadata, in raw CBOR format."
<> Opt.completer (Opt.bashCompleter "file")
)
pWithdrawal :: Parser (StakeAddress, Lovelace)
pWithdrawal =
Opt.option (readerFromAttoParser parseWithdrawal)