/
Commands.hs
473 lines (413 loc) · 14.9 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
{-# 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 (..)
, WitnessFile (..)
, TxBodyFile (..)
, TxFile (..)
, VerificationKeyBase64 (..)
, GenesisKeyFile (..)
, MetaDataFile (..)
, PoolId (..)
, PoolMetaDataFile (..)
, PrivKeyFile (..)
, BlockId (..)
, WitnessSigningData (..)
, ColdVerificationKeyOrFile (..)
) where
import Data.Text (Text)
import Prelude
import Cardano.Api.Typed hiding (PoolId)
import Cardano.Api.Protocol (Protocol)
import Ouroboros.Consensus.BlockchainTime (SystemStart (..))
import Cardano.CLI.Shelley.Key (VerificationKeyOrFile, VerificationKeyOrHashOrFile,
VerificationKeyTextOrFile)
import Cardano.CLI.Types
import Shelley.Spec.Ledger.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 (Eq, 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
VerificationKeyTextOrFile
(Maybe (VerificationKeyOrFile StakeKey))
NetworkId
(Maybe OutputFile)
| AddressBuildMultiSig ScriptFile NetworkId (Maybe OutputFile)
| AddressInfo Text (Maybe OutputFile)
deriving (Eq, 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 (VerificationKeyOrFile StakeKey) NetworkId (Maybe OutputFile)
| StakeKeyRegistrationCert (VerificationKeyOrFile StakeKey) OutputFile
| StakeKeyDelegationCert
(VerificationKeyOrFile StakeKey)
(VerificationKeyOrHashOrFile StakePoolKey)
OutputFile
| StakeKeyDeRegistrationCert (VerificationKeyOrFile StakeKey) OutputFile
deriving (Eq, Show)
renderStakeAddressCmd :: StakeAddressCmd -> Text
renderStakeAddressCmd cmd =
case cmd of
StakeAddressKeyGen {} -> "stake-address key-gen"
StakeAddressKeyHash {} -> "stake-address key-hash"
StakeAddressBuild {} -> "stake-address build"
StakeKeyRegistrationCert {} -> "stake-address registration-certificate"
StakeKeyDelegationCert {} -> "stake-address delegation-certificate"
StakeKeyDeRegistrationCert {} -> "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 (Eq, 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
[TxIn]
[TxOut ShelleyEra]
(Maybe String) -- Placeholder for multi asset Values
SlotNo
Lovelace
[CertificateFile]
[(StakeAddress, Lovelace)]
TxMetadataJsonSchema
[MetaDataFile]
(Maybe UpdateProposalFile)
TxBodyFile
| TxSign TxBodyFile [WitnessSigningData] (Maybe NetworkId) TxFile
| TxCreateWitness TxBodyFile WitnessSigningData (Maybe NetworkId) OutputFile
| TxAssembleTxBodyWitness TxBodyFile [WitnessFile] OutputFile
| TxSubmit Protocol NetworkId FilePath
| TxMintedPolicyId ScriptFile
| TxCalculateMinFee
TxBodyFile
(Maybe NetworkId)
ProtocolParamsFile
TxInCount
TxOutCount
TxShelleyWitnessCount
TxByronWitnessCount
| TxGetTxId TxBodyFile
deriving (Eq, Show)
renderTransactionCmd :: TransactionCmd -> Text
renderTransactionCmd cmd =
case cmd of
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"
TxGetTxId {} -> "transaction txid"
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 (Eq, 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 (Eq, 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 =
QueryProtocolParameters Protocol NetworkId (Maybe OutputFile)
| QueryTip Protocol NetworkId (Maybe OutputFile)
| QueryStakeDistribution Protocol NetworkId (Maybe OutputFile)
| QueryStakeAddressInfo Protocol StakeAddress NetworkId (Maybe OutputFile)
| QueryUTxO Protocol QueryFilter NetworkId (Maybe OutputFile)
| QueryLedgerState Protocol NetworkId (Maybe OutputFile)
| QueryProtocolState Protocol NetworkId (Maybe OutputFile)
deriving (Eq, Show)
renderQueryCmd :: QueryCmd -> Text
renderQueryCmd cmd =
case cmd of
QueryProtocolParameters {} -> "query protocol-parameters "
QueryTip {} -> "query tip"
QueryStakeDistribution {} -> "query stake-distribution"
QueryStakeAddressInfo {} -> "query stake-address-info"
QueryUTxO {} -> "query utxo"
QueryLedgerState {} -> "query ledger-state"
QueryProtocolState {} -> "query protocol-state"
data GovernanceCmd
= GovernanceMIRCertificate MIRPot [VerificationKeyFile] [Lovelace] OutputFile
| GovernanceGenesisKeyDelegationCertificate
(VerificationKeyOrHashOrFile GenesisKey)
(VerificationKeyOrHashOrFile GenesisDelegateKey)
(VerificationKeyOrHashOrFile VrfKey)
OutputFile
| GovernanceUpdateProposal OutputFile EpochNo
[VerificationKeyFile]
ProtocolParametersUpdate
deriving (Eq, Show)
renderGovernanceCmd :: GovernanceCmd -> Text
renderGovernanceCmd cmd =
case cmd of
GovernanceGenesisKeyDelegationCertificate {} -> "governance create-genesis-key-delegation-certificate"
GovernanceMIRCertificate {} -> "governance create-mir-certificate"
GovernanceUpdateProposal {} -> "governance create-update-proposal"
data TextViewCmd
= TextViewInfo !FilePath (Maybe OutputFile)
deriving (Eq, 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 (Eq, 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 (Eq, Show)
newtype TxOutCount
= TxOutCount Int
deriving (Eq, Show)
newtype TxShelleyWitnessCount
= TxShelleyWitnessCount Int
deriving (Eq, Show)
newtype TxByronWitnessCount
= TxByronWitnessCount Int
deriving (Eq, Show)
newtype BlockId
= BlockId String -- Probably not a String
deriving (Eq, Show)
newtype GenesisKeyFile
= GenesisKeyFile FilePath
deriving (Eq, Show)
data MetaDataFile = MetaDataFileJSON FilePath
| MetaDataFileCBOR FilePath
deriving (Eq, Show)
newtype OutputFile
= OutputFile FilePath
deriving (Eq, Show)
newtype PoolId
= PoolId String -- Probably not a String
deriving (Eq, Show)
newtype PoolMetaDataFile = PoolMetaDataFile
{ unPoolMetaDataFile :: FilePath }
deriving (Eq, Show)
newtype GenesisDir
= GenesisDir FilePath
deriving (Eq, 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 (Eq, Show)
data AddressKeyType
= AddressKeyShelley
| AddressKeyShelleyExtended
| AddressKeyByron
deriving (Eq, Show)
data ByronKeyType
= ByronPaymentKey ByronKeyFormat
| ByronGenesisKey ByronKeyFormat
| ByronDelegateKey ByronKeyFormat
deriving (Eq, Show)
data ByronKeyFormat = NonLegacyByronKeyFormat
| LegacyByronKeyFormat
deriving (Eq, Show)
-- | The type of @cardano-address@ key.
data CardanoAddressKeyType
= CardanoAddressShelleyPaymentKey
| CardanoAddressShelleyStakeKey
| CardanoAddressIcarusPaymentKey
| CardanoAddressByronPaymentKey
deriving (Eq, Show)
newtype OpCertCounterFile
= OpCertCounterFile FilePath
deriving (Eq, Show)
newtype PrivKeyFile
= PrivKeyFile FilePath
deriving (Eq, Show)
newtype WitnessFile
= WitnessFile FilePath
deriving (Eq, Show)
newtype TxBodyFile
= TxBodyFile FilePath
deriving (Eq, Show)
newtype TxFile
= TxFile FilePath
deriving (Eq, Show)
-- | A raw verification key given in Base64, and decoded into a ByteString.
newtype VerificationKeyBase64
= VerificationKeyBase64 String
deriving (Eq, 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.
| ScriptWitnessSigningData !ScriptFile
deriving (Eq, 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 (Eq, Show)