-
Notifications
You must be signed in to change notification settings - Fork 721
/
Commands.hs
567 lines (506 loc) · 18.6 KB
/
Commands.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
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}
-- | Shelley CLI command types
module Cardano.CLI.Shelley.Commands
( -- * CLI command types
ShelleyCommand (..)
, AddressCmd (..)
, StakeAddressCmd (..)
, KeyCmd (..)
, TransactionCmd (..)
, NodeCmd (..)
, PoolCmd (..)
, QueryCmd (..)
, GovernanceCmd (..)
, GenesisCmd (..)
, TextViewCmd (..)
, renderShelleyCommand
-- * CLI flag types
, AddressKeyType (..)
, ByronKeyType (..)
, ByronKeyFormat (..)
, CardanoAddressKeyType (..)
, GenesisDir (..)
, TxInCount (..)
, TxOutCount (..)
, TxShelleyWitnessCount (..)
, TxByronWitnessCount (..)
, SomeKeyFile (..)
, OpCertCounterFile (..)
, OutputFile (..)
, ProtocolParamsFile (..)
, ProtocolParamsSourceSpec (..)
, WitnessFile (..)
, TxBodyFile (..)
, TxFile (..)
, InputTxFile (..)
, VerificationKeyBase64 (..)
, GenesisKeyFile (..)
, MetadataFile (..)
, PoolMetadataFile (..)
, PrivKeyFile (..)
, BlockId (..)
, WitnessSigningData (..)
, ColdVerificationKeyOrFile (..)
) where
import Data.Text (Text)
import Prelude
import Cardano.Api.Shelley
import Ouroboros.Consensus.BlockchainTime (SystemStart (..))
import Cardano.CLI.Shelley.Key (PaymentVerifier, StakeVerifier, VerificationKeyOrFile,
VerificationKeyOrHashOrFile, VerificationKeyTextOrFile)
import Cardano.CLI.Types
import Cardano.Ledger.Shelley.TxBody (MIRPot)
--
-- Shelley CLI command data types
--
-- | All the CLI subcommands under \"shelley\".
--
data ShelleyCommand
= AddressCmd AddressCmd
| StakeAddressCmd StakeAddressCmd
| KeyCmd KeyCmd
| TransactionCmd TransactionCmd
| NodeCmd NodeCmd
| PoolCmd PoolCmd
| QueryCmd QueryCmd
| GovernanceCmd GovernanceCmd
| GenesisCmd GenesisCmd
| TextViewCmd TextViewCmd
deriving Show
renderShelleyCommand :: ShelleyCommand -> Text
renderShelleyCommand sc =
case sc of
AddressCmd cmd -> renderAddressCmd cmd
StakeAddressCmd cmd -> renderStakeAddressCmd cmd
KeyCmd cmd -> renderKeyCmd cmd
TransactionCmd cmd -> renderTransactionCmd cmd
NodeCmd cmd -> renderNodeCmd cmd
PoolCmd cmd -> renderPoolCmd cmd
QueryCmd cmd -> renderQueryCmd cmd
GovernanceCmd cmd -> renderGovernanceCmd cmd
GenesisCmd cmd -> renderGenesisCmd cmd
TextViewCmd cmd -> renderTextViewCmd cmd
data AddressCmd
= AddressKeyGen AddressKeyType VerificationKeyFile SigningKeyFile
| AddressKeyHash VerificationKeyTextOrFile (Maybe OutputFile)
| AddressBuild
PaymentVerifier
(Maybe StakeVerifier)
NetworkId
(Maybe OutputFile)
| AddressBuildMultiSig ScriptFile NetworkId (Maybe OutputFile)
| AddressInfo Text (Maybe OutputFile)
deriving Show
renderAddressCmd :: AddressCmd -> Text
renderAddressCmd cmd =
case cmd of
AddressKeyGen {} -> "address key-gen"
AddressKeyHash {} -> "address key-hash"
AddressBuild {} -> "address build"
AddressBuildMultiSig {} -> "address build-script"
AddressInfo {} -> "address info"
data StakeAddressCmd
= StakeAddressKeyGen VerificationKeyFile SigningKeyFile
| StakeAddressKeyHash (VerificationKeyOrFile StakeKey) (Maybe OutputFile)
| StakeAddressBuild StakeVerifier NetworkId (Maybe OutputFile)
| StakeRegistrationCert StakeVerifier OutputFile
| StakeCredentialDelegationCert
StakeVerifier
(VerificationKeyOrHashOrFile StakePoolKey)
OutputFile
| StakeCredentialDeRegistrationCert StakeVerifier OutputFile
deriving Show
renderStakeAddressCmd :: StakeAddressCmd -> Text
renderStakeAddressCmd cmd =
case cmd of
StakeAddressKeyGen {} -> "stake-address key-gen"
StakeAddressKeyHash {} -> "stake-address key-hash"
StakeAddressBuild {} -> "stake-address build"
StakeRegistrationCert {} -> "stake-address registration-certificate"
StakeCredentialDelegationCert {} -> "stake-address delegation-certificate"
StakeCredentialDeRegistrationCert {} -> "stake-address deregistration-certificate"
data KeyCmd
= KeyGetVerificationKey SigningKeyFile VerificationKeyFile
| KeyNonExtendedKey VerificationKeyFile VerificationKeyFile
| KeyConvertByronKey (Maybe Text) ByronKeyType SomeKeyFile OutputFile
| KeyConvertByronGenesisVKey VerificationKeyBase64 OutputFile
| KeyConvertITNStakeKey SomeKeyFile OutputFile
| KeyConvertITNExtendedToStakeKey SomeKeyFile OutputFile
| KeyConvertITNBip32ToStakeKey SomeKeyFile OutputFile
| KeyConvertCardanoAddressSigningKey CardanoAddressKeyType SigningKeyFile OutputFile
deriving Show
renderKeyCmd :: KeyCmd -> Text
renderKeyCmd cmd =
case cmd of
KeyGetVerificationKey {} -> "key verification-key"
KeyNonExtendedKey {} -> "key non-extended-key"
KeyConvertByronKey {} -> "key convert-byron-key"
KeyConvertByronGenesisVKey {} -> "key convert-byron-genesis-key"
KeyConvertITNStakeKey {} -> "key convert-itn-key"
KeyConvertITNExtendedToStakeKey {} -> "key convert-itn-extended-key"
KeyConvertITNBip32ToStakeKey {} -> "key convert-itn-bip32-key"
KeyConvertCardanoAddressSigningKey {} -> "key convert-cardano-address-signing-key"
data TransactionCmd
= TxBuildRaw
AnyCardanoEra
(Maybe ScriptValidity) -- ^ Mark script as expected to pass or fail validation
[(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
-- ^ Transaction inputs with optional spending scripts
[TxIn]
-- ^ Transaction inputs for collateral, only key witnesses, no scripts.
[RequiredSigner]
-- ^ Required signers
[TxOutAnyEra]
(Maybe (Value, [ScriptWitnessFiles WitCtxMint]))
-- ^ Multi-Asset value with script witness
(Maybe SlotNo)
-- ^ Transaction lower bound
(Maybe SlotNo)
-- ^ Transaction upper bound
(Maybe Lovelace)
-- ^ Tx fee
[(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
-- ^ Certificates with potential script witness
[(StakeAddress, Lovelace, Maybe (ScriptWitnessFiles WitCtxStake))]
TxMetadataJsonSchema
[ScriptFile]
-- ^ Auxillary scripts
[MetadataFile]
(Maybe ProtocolParamsSourceSpec)
(Maybe UpdateProposalFile)
OutputSerialisation
TxBodyFile
-- | Like 'TxBuildRaw' but without the fee, and with a change output.
| TxBuild
AnyCardanoEra
AnyConsensusModeParams
NetworkId
(Maybe ScriptValidity) -- ^ Mark script as expected to pass or fail validation
(Maybe Word)
-- ^ Override the required number of tx witnesses
[(TxIn, Maybe (ScriptWitnessFiles WitCtxTxIn))]
-- ^ Required signers
[RequiredSigner]
-- ^ Transaction inputs with optional spending scripts
[TxIn]
-- ^ Transaction inputs for collateral, only key witnesses, no scripts.
[TxOutAnyEra]
-- ^ Normal outputs
TxOutChangeAddress
-- ^ A change output
(Maybe (Value, [ScriptWitnessFiles WitCtxMint]))
-- ^ Multi-Asset value with script witness
(Maybe SlotNo)
-- ^ Transaction lower bound
(Maybe SlotNo)
-- ^ Transaction upper bound
[(CertificateFile, Maybe (ScriptWitnessFiles WitCtxStake))]
-- ^ Certificates with potential script witness
[(StakeAddress, Lovelace, Maybe (ScriptWitnessFiles WitCtxStake))]
-- ^ Withdrawals with potential script witness
TxMetadataJsonSchema
[ScriptFile]
-- ^ Auxillary scripts
[MetadataFile]
(Maybe ProtocolParamsSourceSpec)
(Maybe UpdateProposalFile)
OutputSerialisation
TxBodyFile
| TxSign TxBodyFile [WitnessSigningData] (Maybe NetworkId) TxFile
| TxCreateWitness TxBodyFile WitnessSigningData (Maybe NetworkId) OutputFile
| TxAssembleTxBodyWitness TxBodyFile [WitnessFile] OutputFile
| TxSubmit AnyConsensusModeParams NetworkId FilePath
| TxMintedPolicyId ScriptFile
| TxCalculateMinFee
TxBodyFile
(Maybe NetworkId)
ProtocolParamsSourceSpec
TxInCount
TxOutCount
TxShelleyWitnessCount
TxByronWitnessCount
| TxCalculateMinRequiredUTxO
AnyCardanoEra
ProtocolParamsSourceSpec
TxOutAnyEra
| TxHashScriptData
ScriptDataOrFile
| TxGetTxId InputTxFile
| TxView InputTxFile
deriving Show
data InputTxFile = InputTxBodyFile TxBodyFile | InputTxFile TxFile
deriving Show
data ProtocolParamsSourceSpec
= ParamsFromGenesis !GenesisFile
-- ^ We allow an appropriately forewarned user to obtain protocol params
-- directly from the genesis file, which allows them to avoid running
-- the node in case they would like to estimate the fee using the
-- blockchain's initial protocol parameters.
| ParamsFromFile !ProtocolParamsFile
-- ^ Obtain protocol parameters from a file structured by the
-- 'cardano-api' 'ProtocolParameters' data type.
deriving Show
renderTransactionCmd :: TransactionCmd -> Text
renderTransactionCmd cmd =
case cmd of
TxBuild {} -> "transaction build"
TxBuildRaw {} -> "transaction build-raw"
TxSign {} -> "transaction sign"
TxCreateWitness {} -> "transaction witness"
TxAssembleTxBodyWitness {} -> "transaction sign-witness"
TxSubmit {} -> "transaction submit"
TxMintedPolicyId {} -> "transaction policyid"
TxCalculateMinFee {} -> "transaction calculate-min-fee"
TxCalculateMinRequiredUTxO {} -> "transaction calculate-min-value"
TxHashScriptData {} -> "transaction hash-script-data"
TxGetTxId {} -> "transaction txid"
TxView {} -> "transaction view"
data NodeCmd
= NodeKeyGenCold VerificationKeyFile SigningKeyFile OpCertCounterFile
| NodeKeyGenKES VerificationKeyFile SigningKeyFile
| NodeKeyGenVRF VerificationKeyFile SigningKeyFile
| NodeKeyHashVRF (VerificationKeyOrFile VrfKey) (Maybe OutputFile)
| NodeNewCounter ColdVerificationKeyOrFile Word OpCertCounterFile
| NodeIssueOpCert (VerificationKeyOrFile KesKey) SigningKeyFile OpCertCounterFile
KESPeriod OutputFile
deriving Show
renderNodeCmd :: NodeCmd -> Text
renderNodeCmd cmd = do
case cmd of
NodeKeyGenCold {} -> "node key-gen"
NodeKeyGenKES {} -> "node key-gen-KES"
NodeKeyGenVRF {} -> "node key-gen-VRF"
NodeKeyHashVRF {} -> "node key-hash-VRF"
NodeNewCounter {} -> "node new-counter"
NodeIssueOpCert{} -> "node issue-op-cert"
data PoolCmd
= PoolRegistrationCert
(VerificationKeyOrFile StakePoolKey)
-- ^ Stake pool verification key.
(VerificationKeyOrFile VrfKey)
-- ^ VRF Verification key.
Lovelace
-- ^ Pool pledge.
Lovelace
-- ^ Pool cost.
Rational
-- ^ Pool margin.
(VerificationKeyOrFile StakeKey)
-- ^ Reward account verification staking key.
[VerificationKeyOrFile StakeKey]
-- ^ Pool owner verification staking key(s).
[StakePoolRelay]
-- ^ Stake pool relays.
(Maybe StakePoolMetadataReference)
-- ^ Stake pool metadata.
NetworkId
OutputFile
| PoolRetirementCert
(VerificationKeyOrFile StakePoolKey)
-- ^ Stake pool verification key.
EpochNo
-- ^ Epoch in which to retire the stake pool.
OutputFile
| PoolGetId (VerificationKeyOrFile StakePoolKey) OutputFormat
| PoolMetadataHash PoolMetadataFile (Maybe OutputFile)
deriving Show
renderPoolCmd :: PoolCmd -> Text
renderPoolCmd cmd =
case cmd of
PoolRegistrationCert {} -> "stake-pool registration-certificate"
PoolRetirementCert {} -> "stake-pool deregistration-certificate"
PoolGetId {} -> "stake-pool id"
PoolMetadataHash {} -> "stake-pool metadata-hash"
data QueryCmd =
QueryLeadershipSchedule
AnyConsensusModeParams
NetworkId
GenesisFile
(VerificationKeyOrHashOrFile StakePoolKey)
SigningKeyFile
EpochLeadershipSchedule
| QueryProtocolParameters' AnyConsensusModeParams NetworkId (Maybe OutputFile)
| QueryTip AnyConsensusModeParams NetworkId (Maybe OutputFile)
| QueryStakePools' AnyConsensusModeParams NetworkId (Maybe OutputFile)
| QueryStakeDistribution' AnyConsensusModeParams NetworkId (Maybe OutputFile)
| QueryStakeAddressInfo AnyConsensusModeParams StakeAddress NetworkId (Maybe OutputFile)
| QueryUTxO' AnyConsensusModeParams QueryUTxOFilter NetworkId (Maybe OutputFile)
| QueryDebugLedgerState' AnyConsensusModeParams NetworkId (Maybe OutputFile)
| QueryProtocolState' AnyConsensusModeParams NetworkId (Maybe OutputFile)
| QueryStakeSnapshot' AnyConsensusModeParams NetworkId (Hash StakePoolKey)
| QueryPoolParams' AnyConsensusModeParams NetworkId (Hash StakePoolKey)
deriving Show
renderQueryCmd :: QueryCmd -> Text
renderQueryCmd cmd =
case cmd of
QueryLeadershipSchedule {} -> "query leadership-schedule"
QueryProtocolParameters' {} -> "query protocol-parameters "
QueryTip {} -> "query tip"
QueryStakePools' {} -> "query stake-pools"
QueryStakeDistribution' {} -> "query stake-distribution"
QueryStakeAddressInfo {} -> "query stake-address-info"
QueryUTxO' {} -> "query utxo"
QueryDebugLedgerState' {} -> "query ledger-state"
QueryProtocolState' {} -> "query protocol-state"
QueryStakeSnapshot' {} -> "query stake-snapshot"
QueryPoolParams' {} -> "query pool-params"
data GovernanceCmd
= GovernanceMIRPayStakeAddressesCertificate
MIRPot
[StakeAddress]
[Lovelace]
OutputFile
| GovernanceMIRTransfer Lovelace OutputFile TransferDirection
| GovernanceGenesisKeyDelegationCertificate
(VerificationKeyOrHashOrFile GenesisKey)
(VerificationKeyOrHashOrFile GenesisDelegateKey)
(VerificationKeyOrHashOrFile VrfKey)
OutputFile
| GovernanceUpdateProposal OutputFile EpochNo
[VerificationKeyFile]
ProtocolParametersUpdate
deriving Show
renderGovernanceCmd :: GovernanceCmd -> Text
renderGovernanceCmd cmd =
case cmd of
GovernanceGenesisKeyDelegationCertificate {} -> "governance create-genesis-key-delegation-certificate"
GovernanceMIRPayStakeAddressesCertificate {} -> "governance create-mir-certificate stake-addresses"
GovernanceMIRTransfer _ _ TransferToTreasury -> "governance create-mir-certificate transfer-to-treasury"
GovernanceMIRTransfer _ _ TransferToReserves -> "governance create-mir-certificate transfer-to-reserves"
GovernanceUpdateProposal {} -> "governance create-update-proposal"
data TextViewCmd
= TextViewInfo !FilePath (Maybe OutputFile)
deriving Show
renderTextViewCmd :: TextViewCmd -> Text
renderTextViewCmd (TextViewInfo _ _) = "text-view decode-cbor"
data GenesisCmd
= GenesisCreate GenesisDir Word Word (Maybe SystemStart) (Maybe Lovelace) NetworkId
| GenesisCreateStaked GenesisDir Word Word Word Word (Maybe SystemStart) (Maybe Lovelace) Lovelace NetworkId Word Word Word
| GenesisKeyGenGenesis VerificationKeyFile SigningKeyFile
| GenesisKeyGenDelegate VerificationKeyFile SigningKeyFile OpCertCounterFile
| GenesisKeyGenUTxO VerificationKeyFile SigningKeyFile
| GenesisCmdKeyHash VerificationKeyFile
| GenesisVerKey VerificationKeyFile SigningKeyFile
| GenesisTxIn VerificationKeyFile NetworkId (Maybe OutputFile)
| GenesisAddr VerificationKeyFile NetworkId (Maybe OutputFile)
| GenesisHashFile GenesisFile
deriving Show
renderGenesisCmd :: GenesisCmd -> Text
renderGenesisCmd cmd =
case cmd of
GenesisCreate {} -> "genesis create"
GenesisCreateStaked {} -> "genesis create-staked"
GenesisKeyGenGenesis {} -> "genesis key-gen-genesis"
GenesisKeyGenDelegate {} -> "genesis key-gen-delegate"
GenesisKeyGenUTxO {} -> "genesis key-gen-utxo"
GenesisCmdKeyHash {} -> "genesis key-hash"
GenesisVerKey {} -> "genesis get-ver-key"
GenesisTxIn {} -> "genesis initial-txin"
GenesisAddr {} -> "genesis initial-addr"
GenesisHashFile {} -> "genesis hash"
--
-- Shelley CLI flag/option data types
--
newtype ProtocolParamsFile
= ProtocolParamsFile FilePath
deriving (Show, Eq)
newtype TxInCount
= TxInCount Int
deriving Show
newtype TxOutCount
= TxOutCount Int
deriving Show
newtype TxShelleyWitnessCount
= TxShelleyWitnessCount Int
deriving Show
newtype TxByronWitnessCount
= TxByronWitnessCount Int
deriving Show
newtype BlockId
= BlockId String -- Probably not a String
deriving Show
newtype GenesisKeyFile
= GenesisKeyFile FilePath
deriving Show
data MetadataFile = MetadataFileJSON FilePath
| MetadataFileCBOR FilePath
deriving Show
newtype OutputFile
= OutputFile FilePath
deriving Show
newtype PoolMetadataFile = PoolMetadataFile
{ unPoolMetadataFile :: FilePath }
deriving Show
newtype GenesisDir
= GenesisDir FilePath
deriving Show
-- | Either a verification or signing key, used for conversions and other
-- commands that make sense for both.
--
data SomeKeyFile
= AVerificationKeyFile VerificationKeyFile
| ASigningKeyFile SigningKeyFile
deriving Show
data AddressKeyType
= AddressKeyShelley
| AddressKeyShelleyExtended
| AddressKeyByron
deriving Show
data ByronKeyType
= ByronPaymentKey ByronKeyFormat
| ByronGenesisKey ByronKeyFormat
| ByronDelegateKey ByronKeyFormat
deriving Show
data ByronKeyFormat = NonLegacyByronKeyFormat
| LegacyByronKeyFormat
deriving Show
-- | The type of @cardano-address@ key.
data CardanoAddressKeyType
= CardanoAddressShelleyPaymentKey
| CardanoAddressShelleyStakeKey
| CardanoAddressIcarusPaymentKey
| CardanoAddressByronPaymentKey
deriving Show
newtype OpCertCounterFile
= OpCertCounterFile FilePath
deriving Show
newtype PrivKeyFile
= PrivKeyFile FilePath
deriving Show
newtype WitnessFile
= WitnessFile FilePath
deriving Show
newtype TxBodyFile
= TxBodyFile FilePath
deriving Show
newtype TxFile
= TxFile FilePath
deriving Show
-- | A raw verification key given in Base64, and decoded into a ByteString.
newtype VerificationKeyBase64
= VerificationKeyBase64 String
deriving Show
-- | Data required to construct a witness.
data WitnessSigningData
= KeyWitnessSigningData
!SigningKeyFile
-- ^ Path to a file that should contain a signing key.
!(Maybe (Address ByronAddr))
-- ^ An optionally specified Byron address.
--
-- If specified, both the network ID and derivation path are extracted
-- from the address and used in the construction of the Byron witness.
deriving Show
-- | Either a stake pool verification key, genesis delegate verification key,
-- or a path to a cold verification key file.
--
-- Note that a "cold verification key" refers to either a stake pool or
-- genesis delegate verification key.
--
-- TODO: A genesis delegate extended key should also be valid here.
data ColdVerificationKeyOrFile
= ColdStakePoolVerificationKey !(VerificationKey StakePoolKey)
| ColdGenesisDelegateVerificationKey !(VerificationKey GenesisDelegateKey)
| ColdVerificationKeyFile !VerificationKeyFile
deriving Show