Skip to content

Commit 6fafbca

Browse files
committed
Add pool operator extended key support
1 parent 208ed87 commit 6fafbca

84 files changed

Lines changed: 518 additions & 94 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cardano-cli/src/Cardano/CLI/Compatible/StakeAddress/Command.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ data CompatibleStakeAddressCmds era
2626
| CompatibleStakeAddressStakeDelegationCertificateCmd
2727
(ShelleyBasedEra era)
2828
StakeIdentifier
29-
(VerificationKeyOrHashOrFile StakePoolKey)
29+
StakePoolKeyHashSource
3030
(File () Out)
3131
deriving Show
3232

cardano-cli/src/Cardano/CLI/Compatible/StakeAddress/Run.hs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -84,40 +84,45 @@ runStakeAddressStakeDelegationCertificateCmd
8484
=> ShelleyBasedEra era
8585
-> StakeIdentifier
8686
-- ^ Delegator stake verification key, verification key file or script file.
87-
-> VerificationKeyOrHashOrFile StakePoolKey
87+
-> StakePoolKeyHashSource
8888
-- ^ Delegatee stake pool verification key or verification key file or
8989
-- verification key hash.
9090
-> File () Out
9191
-> CIO e ()
9292
runStakeAddressStakeDelegationCertificateCmd sbe stakeVerifier poolVKeyOrHashOrFile outFp =
9393
shelleyBasedEraConstraints sbe $ do
94-
poolStakeVKeyHash <-
95-
fromExceptTCli $
96-
readVerificationKeyOrHashOrFile AsStakePoolKey poolVKeyOrHashOrFile
94+
poolStakeVKeyHash <- getHashFromStakePoolKeyHashSource poolVKeyOrHashOrFile
9795

9896
stakeCred <-
9997
fromExceptTCli $ getStakeCredentialFromIdentifier stakeVerifier
10098

101-
let certificate = createStakeDelegationCertificate stakeCred poolStakeVKeyHash sbe
99+
let certificate =
100+
createStakeDelegationCertificate sbe stakeCred poolStakeVKeyHash
102101

103102
fromEitherIOCli @(FileError ()) $
104103
writeLazyByteStringFile outFp $
105104
textEnvelopeToJSON (Just @TextEnvelopeDescr "Stake Delegation Certificate") certificate
106105

107106
createStakeDelegationCertificate
108-
:: StakeCredential
107+
:: ShelleyBasedEra era
108+
-> StakeCredential
109109
-> Hash StakePoolKey
110-
-> ShelleyBasedEra era
111110
-> Certificate era
112-
createStakeDelegationCertificate stakeCredential (StakePoolKeyHash poolStakeVKeyHash) = do
111+
createStakeDelegationCertificate sbe stakeCredential stakePoolHash = do
113112
caseShelleyToBabbageOrConwayEraOnwards
114113
( \w ->
115114
shelleyToBabbageEraConstraints w $
116115
ShelleyRelatedCertificate w $
117-
L.mkDelegStakeTxCert (toShelleyStakeCredential stakeCredential) poolStakeVKeyHash
116+
L.mkDelegStakeTxCert (toShelleyStakeCredential stakeCredential) (toLedgerHash stakePoolHash)
118117
)
119118
( \w ->
120119
conwayEraOnwardsConstraints w $
121120
ConwayCertificate w $
122-
L.mkDelegTxCert (toShelleyStakeCredential stakeCredential) (L.DelegStake poolStakeVKeyHash)
121+
L.mkDelegTxCert
122+
(toShelleyStakeCredential stakeCredential)
123+
(L.DelegStake (toLedgerHash stakePoolHash))
123124
)
125+
sbe
126+
where
127+
toLedgerHash :: Hash StakePoolKey -> L.KeyHash L.StakePool L.StandardCrypto
128+
toLedgerHash (StakePoolKeyHash poolStakeVKeyHash) = poolStakeVKeyHash

cardano-cli/src/Cardano/CLI/Compatible/StakePool/Command.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ import Prelude
1919

2020
import Data.Text (Text)
2121

22-
data CompatibleStakePoolCmds era
22+
newtype CompatibleStakePoolCmds era
2323
= CompatibleStakePoolRegistrationCertificateCmd
24-
!(CompatibleStakePoolRegistrationCertificateCmdArgs era)
24+
(CompatibleStakePoolRegistrationCertificateCmdArgs era)
2525
deriving Show
2626

2727
data CompatibleStakePoolRegistrationCertificateCmdArgs era
2828
= CompatibleStakePoolRegistrationCertificateCmdArgs
2929
{ sbe :: !(ShelleyBasedEra era)
3030
-- ^ Era in which to register the stake pool.
31-
, poolVerificationKeyOrFile :: !(VerificationKeyOrFile StakePoolKey)
31+
, poolVerificationKeyOrFile :: !StakePoolVerificationKeySource
3232
-- ^ Stake pool verification key.
3333
, vrfVerificationKeyOrFile :: !(VerificationKeyOrFile VrfKey)
3434
-- ^ VRF Verification key.

cardano-cli/src/Cardano/CLI/Compatible/StakePool/Run.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ import Cardano.Api.Shelley
1414
import Cardano.CLI.Compatible.Exception
1515
import Cardano.CLI.Compatible.StakePool.Command
1616
import Cardano.CLI.EraBased.StakePool.Internal.Metadata
17+
import Cardano.CLI.Read
18+
( getVerificationKeyFromStakePoolVerificationKeySource
19+
)
1720
import Cardano.CLI.Type.Common
1821
import Cardano.CLI.Type.Error.StakePoolCmdError
1922
import Cardano.CLI.Type.Key (readVerificationKeyOrFile)
@@ -48,11 +51,8 @@ runStakePoolRegistrationCertificateCmd
4851
} =
4952
shelleyBasedEraConstraints sbe $ do
5053
-- Pool verification key
51-
stakePoolVerKey <-
52-
fromExceptTCli $
53-
firstExceptT StakePoolCmdReadKeyFileError $
54-
readVerificationKeyOrFile AsStakePoolKey poolVerificationKeyOrFile
55-
let stakePoolId' = verificationKeyHash stakePoolVerKey
54+
stakePoolVerKey <- getVerificationKeyFromStakePoolVerificationKeySource poolVerificationKeyOrFile
55+
let stakePoolId' = anyStakePoolVerificationKeyHash stakePoolVerKey
5656

5757
-- VRF verification key
5858
vrfVerKey <-

cardano-cli/src/Cardano/CLI/EraBased/Common/Option.hs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -434,23 +434,40 @@ parseLovelace = do
434434
else return $ L.Coin i
435435

436436
-- | The first argument is the optional prefix.
437-
pStakePoolVerificationKeyOrFile :: Maybe String -> Parser (VerificationKeyOrFile StakePoolKey)
437+
pStakePoolVerificationKeyOrFile
438+
:: Maybe String
439+
-> Parser StakePoolVerificationKeySource
438440
pStakePoolVerificationKeyOrFile prefix =
439441
asum
440-
[ VerificationKeyValue <$> pStakePoolVerificationKey prefix
441-
, VerificationKeyFilePath <$> pStakePoolVerificationKeyFile prefix
442+
[ StakePoolVerificationKeyFromLiteral . AnyStakePoolNormalVerificationKey
443+
<$> pStakePoolVerificationNormalKey prefix
444+
, StakePoolVerificationKeyFromLiteral . AnyStakePoolExtendedVerificationKey
445+
<$> pStakePoolVerificationExtendedKey prefix
446+
, StakePoolVerificationKeyFromFile <$> pStakePoolVerificationKeyFile prefix
442447
]
443448

444449
-- | The first argument is the optional prefix.
445-
pStakePoolVerificationKey :: Maybe String -> Parser (VerificationKey StakePoolKey)
446-
pStakePoolVerificationKey prefix =
450+
pStakePoolVerificationNormalKey
451+
:: Maybe String -> Parser (VerificationKey StakePoolKey)
452+
pStakePoolVerificationNormalKey prefix =
447453
Opt.option (readVerificationKey AsStakePoolKey) $
448454
mconcat
449455
[ Opt.long $ prefixFlag prefix "stake-pool-verification-key"
450456
, Opt.metavar "STRING"
451457
, Opt.help "Stake pool verification key (Bech32 or hex-encoded)."
452458
]
453459

460+
-- | The first argument is the optional prefix.
461+
pStakePoolVerificationExtendedKey
462+
:: Maybe String -> Parser (VerificationKey StakePoolExtendedKey)
463+
pStakePoolVerificationExtendedKey prefix =
464+
Opt.option (readVerificationKey AsStakePoolExtendedKey) $
465+
mconcat
466+
[ Opt.long $ prefixFlag prefix "stake-pool-verification-extended-key"
467+
, Opt.metavar "STRING"
468+
, Opt.help "Stake pool verification extended key (Bech32 or hex-encoded)."
469+
]
470+
454471
-- | The first argument is the optional prefix.
455472
pStakePoolVerificationKeyFile :: Maybe String -> Parser (VerificationKeyFile In)
456473
pStakePoolVerificationKeyFile prefix =
@@ -570,7 +587,10 @@ rVerificationKey a mErrPrefix =
570587
pColdVerificationKeyOrFile :: Maybe String -> Parser ColdVerificationKeyOrFile
571588
pColdVerificationKeyOrFile prefix =
572589
asum
573-
[ ColdStakePoolVerificationKey <$> pStakePoolVerificationKey prefix
590+
[ ColdStakePoolVerificationKey . AnyStakePoolNormalVerificationKey
591+
<$> pStakePoolVerificationNormalKey prefix
592+
, ColdStakePoolVerificationKey . AnyStakePoolExtendedVerificationKey
593+
<$> pStakePoolVerificationExtendedKey prefix
574594
, ColdGenesisDelegateVerificationKey <$> pGenesisDelegateVerificationKey
575595
, ColdVerificationKeyFile <$> pColdVerificationKeyFile
576596
]
@@ -950,11 +970,11 @@ pStakeVerificationKeyHash prefix =
950970

951971
-- | The first argument is the optional prefix.
952972
pStakePoolVerificationKeyOrHashOrFile
953-
:: Maybe String -> Parser (VerificationKeyOrHashOrFile StakePoolKey)
973+
:: Maybe String -> Parser StakePoolKeyHashSource
954974
pStakePoolVerificationKeyOrHashOrFile prefix =
955975
asum
956-
[ VerificationKeyOrFile <$> pStakePoolVerificationKeyOrFile prefix
957-
, VerificationKeyHash <$> pStakePoolVerificationKeyHash prefix
976+
[ StakePoolKeyHashSource <$> pStakePoolVerificationKeyOrFile prefix
977+
, StakePoolKeyHashLiteral <$> pStakePoolVerificationKeyHash prefix
958978
]
959979

960980
--------------------------------------------------------------------------------
@@ -3416,7 +3436,7 @@ pVoterType =
34163436
]
34173437

34183438
-- TODO: Conway era include "normal" stake keys
3419-
pVotingCredential :: Parser (VerificationKeyOrFile StakePoolKey)
3439+
pVotingCredential :: Parser StakePoolVerificationKeySource
34203440
pVotingCredential = pStakePoolVerificationKeyOrFile Nothing
34213441

34223442
pVoteDelegationTarget :: Parser VoteDelegationTarget

cardano-cli/src/Cardano/CLI/EraBased/Genesis/Run.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,8 @@ generateShelleyNodeSecrets shelleyDelegateKeys shelleyGenesisvkeys = do
339339
createOpCert (kesKey, delegateKey) = either (error . show) id eResult
340340
where
341341
eResult = issueOperationalCertificate kesKey (Right delegateKey) (KESPeriod 0) counter
342-
counter = OperationalCertificateIssueCounter 0 (convertFun . getVerificationKey $ delegateKey)
342+
counter =
343+
OperationalCertificateIssueCounter 0 (convertFun . getVerificationKey $ delegateKey)
343344
convertFun
344345
:: VerificationKey GenesisDelegateExtendedKey
345346
-> VerificationKey StakePoolKey

cardano-cli/src/Cardano/CLI/EraBased/Governance/Vote/Run.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import Cardano.Api.Shelley
1818
import Cardano.CLI.EraBased.Governance.Vote.Command qualified as Cmd
1919
import Cardano.CLI.EraBased.Script.Vote.Read
2020
import Cardano.CLI.EraIndependent.Hash.Internal.Common (carryHashChecks)
21+
import Cardano.CLI.Read (getHashFromStakePoolKeyHashSource)
2122
import Cardano.CLI.Type.Common
2223
import Cardano.CLI.Type.Error.CmdError
2324
import Cardano.CLI.Type.Error.GovernanceVoteCmdError
@@ -81,7 +82,8 @@ runGovernanceVoteCreateCmd
8182
drepCred <- readVerificationKeyOrHashOrFileOrScriptHash AsDRepKey unDRepKeyHash stake
8283
pure $ L.DRepVoter drepCred
8384
AnyStakePoolVerificationKeyOrHashOrFile stake -> do
84-
StakePoolKeyHash h <- readVerificationKeyOrHashOrTextEnvFile AsStakePoolKey stake
85+
StakePoolKeyHash h <-
86+
liftIO $ getHashFromStakePoolKeyHashSource stake
8587
pure $ L.StakePoolVoter h
8688
AnyCommitteeHotVerificationKeyOrHashOrFileOrScriptHash stake -> do
8789
hotCred <- readVerificationKeyOrHashOrFileOrScriptHash AsCommitteeHotKey unCommitteeHotKeyHash stake

cardano-cli/src/Cardano/CLI/EraBased/Query/Command.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ data QueryCommons = QueryCommons
8686
data QueryLeadershipScheduleCmdArgs = QueryLeadershipScheduleCmdArgs
8787
{ commons :: !QueryCommons
8888
, genesisFp :: !GenesisFile
89-
, poolColdVerKeyFile :: !(VerificationKeyOrHashOrFile StakePoolKey)
89+
, poolColdVerKeyFile :: !StakePoolKeyHashSource
9090
, vrkSkeyFp :: !(SigningKeyFile In)
9191
, whichSchedule :: !EpochLeadershipSchedule
9292
, format :: Maybe OutputFormatJsonOrText

cardano-cli/src/Cardano/CLI/EraBased/Query/Run.hs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ import Cardano.Binary qualified as CBOR
5151
import Cardano.CLI.EraBased.Genesis.Internal.Common
5252
import Cardano.CLI.EraBased.Query.Command qualified as Cmd
5353
import Cardano.CLI.Helper
54+
import Cardano.CLI.Read
55+
( getHashFromStakePoolKeyHashSource
56+
)
5457
import Cardano.CLI.Type.Common
5558
import Cardano.CLI.Type.Error.NodeEraMismatchError
5659
import Cardano.CLI.Type.Error.QueryCmdError
@@ -551,7 +554,8 @@ runQueryKesPeriodInfoCmd
551554
-- We need the stake pool id to determine what the counter of our SPO
552555
-- should be.
553556
let opCertCounterMap = Consensus.getOpCertCounters (Proxy @(ConsensusProtocol era)) chainDepState
554-
StakePoolKeyHash blockIssuerHash = verificationKeyHash stakePoolVKey
557+
StakePoolKeyHash blockIssuerHash =
558+
verificationKeyHash stakePoolVKey
555559

556560
case Map.lookup (coerce blockIssuerHash) opCertCounterMap of
557561
-- Operational certificate exists in the protocol state
@@ -1416,9 +1420,7 @@ runQueryLeadershipScheduleCmd
14161420
, Cmd.format
14171421
, Cmd.mOutFile
14181422
} = do
1419-
poolid <-
1420-
modifyError QueryCmdTextReadError $
1421-
readVerificationKeyOrHashOrFile AsStakePoolKey poolColdVerKeyFile
1423+
poolid <- getHashFromStakePoolKeyHashSource poolColdVerKeyFile
14221424

14231425
vrkSkey <-
14241426
modifyError QueryCmdTextEnvelopeReadError . hoistIOEither $
@@ -1449,7 +1451,8 @@ runQueryLeadershipScheduleCmd
14491451
CurrentEpoch -> do
14501452
beo <- requireEon BabbageEra era
14511453

1452-
serCurrentEpochState <- easyRunQuery (queryPoolDistribution beo (Just (Set.singleton poolid)))
1454+
serCurrentEpochState <-
1455+
easyRunQuery (queryPoolDistribution beo (Just (Set.singleton poolid)))
14531456

14541457
pure $ do
14551458
schedule <-

cardano-cli/src/Cardano/CLI/EraBased/StakeAddress/Command.hs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ data StakeAddressCmds era
3838
| StakeAddressStakeDelegationCertificateCmd
3939
(ShelleyBasedEra era)
4040
StakeIdentifier
41-
(VerificationKeyOrHashOrFile StakePoolKey)
41+
StakePoolKeyHashSource
4242
(File () Out)
4343
| StakeAddressStakeAndVoteDelegationCertificateCmd
4444
(ConwayEraOnwards era)
4545
StakeIdentifier
46-
(VerificationKeyOrHashOrFile StakePoolKey)
46+
StakePoolKeyHashSource
4747
VoteDelegationTarget
4848
(File () Out)
4949
| StakeAddressVoteDelegationCertificateCmd
@@ -59,7 +59,7 @@ data StakeAddressCmds era
5959
| StakeAddressRegistrationAndDelegationCertificateCmd
6060
(ConwayEraOnwards era)
6161
StakeIdentifier
62-
(VerificationKeyOrHashOrFile StakePoolKey)
62+
StakePoolKeyHashSource
6363
Coin
6464
(File () Out)
6565
| StakeAddressRegistrationAndVoteDelegationCertificateCmd
@@ -71,7 +71,7 @@ data StakeAddressCmds era
7171
| StakeAddressRegistrationStakeAndVoteDelegationCertificateCmd
7272
(ConwayEraOnwards era)
7373
StakeIdentifier
74-
(VerificationKeyOrHashOrFile StakePoolKey)
74+
StakePoolKeyHashSource
7575
VoteDelegationTarget
7676
Coin
7777
(File () Out)

0 commit comments

Comments
 (0)