From 1f3c509a1ff829b0375d835526da347b57fa5a08 Mon Sep 17 00:00:00 2001 From: teodanciu Date: Tue, 24 Oct 2023 13:53:07 +0100 Subject: [PATCH] Add `getCommitteeCold\HotCredentialFromVerKeyHashOrFile` to `Read` --- cardano-cli/src/Cardano/CLI/Read.hs | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/cardano-cli/src/Cardano/CLI/Read.hs b/cardano-cli/src/Cardano/CLI/Read.hs index 499fa84616..ec7c0643c5 100644 --- a/cardano-cli/src/Cardano/CLI/Read.hs +++ b/cardano-cli/src/Cardano/CLI/Read.hs @@ -79,6 +79,10 @@ module Cardano.CLI.Read -- * DRep credentials , getDRepCredentialFromVerKeyHashOrFile + -- * Committee credentials + , getCommitteeColdCredentialFromVerKeyHashOrFile + , getCommitteeHotCredentialFromVerKeyHashOrFile + , ReadSafeHashError(..) , readHexAsSafeHash , readSafeHash @@ -803,7 +807,7 @@ readVoteHashSource = \case VoteHashSourceHash h -> return h VoteHashSourceText c -> return $ Ledger.hashAnchorData $ Ledger.AnchorData $ Text.encodeUtf8 c VoteHashSourceFile fp -> do - cBs <- firstExceptT VoteErrorFile . newExceptT $ readByteStringFile fp + cBs <- firstExceptT VoteErrorFile . newExceptT $ readByteStringFile fp _utf8EncodedText <- firstExceptT VoteErrorTextNotUnicode . hoistEither $ Text.decodeUtf8' cBs return $ Ledger.hashAnchorData $ Ledger.AnchorData cBs @@ -1020,6 +1024,28 @@ getDRepCredentialFromVerKeyHashOrFile = \case pure . Ledger.KeyHashObj . unDRepKeyHash $ verificationKeyHash drepVerKey VerificationKeyHash kh -> pure . Ledger.KeyHashObj $ unDRepKeyHash kh +getCommitteeColdCredentialFromVerKeyHashOrFile :: () + => VerificationKeyOrHashOrFile CommitteeColdKey + -> ExceptT (FileError InputDecodeError) IO (Ledger.Credential Ledger.ColdCommitteeRole Ledger.StandardCrypto) +getCommitteeColdCredentialFromVerKeyHashOrFile = \case + VerificationKeyOrFile verKeyOrFile -> do + commmitteeColdVerKey <- + ExceptT (readVerificationKeyOrFile AsCommitteeColdKey verKeyOrFile) + let CommitteeColdKeyHash kh = verificationKeyHash commmitteeColdVerKey + pure $ Ledger.KeyHashObj kh + VerificationKeyHash (CommitteeColdKeyHash kh) -> pure $ Ledger.KeyHashObj kh + +getCommitteeHotCredentialFromVerKeyHashOrFile :: () + => VerificationKeyOrHashOrFile CommitteeHotKey + -> ExceptT (FileError InputDecodeError) IO (Ledger.Credential Ledger.HotCommitteeRole Ledger.StandardCrypto) +getCommitteeHotCredentialFromVerKeyHashOrFile = \case + VerificationKeyOrFile verKeyOrFile -> do + commmitteeHotVerKey <- + ExceptT (readVerificationKeyOrFile AsCommitteeHotKey verKeyOrFile) + let CommitteeHotKeyHash kh = verificationKeyHash commmitteeHotVerKey + pure $ Ledger.KeyHashObj kh + VerificationKeyHash (CommitteeHotKeyHash kh) -> pure $ Ledger.KeyHashObj kh + data ReadSafeHashError = ReadSafeHashErrorNotHex ByteString String | ReadSafeHashErrorInvalidHash Text