Skip to content

Commit 5784d62

Browse files
committed
Update to use getAnchorDataFromCertificate from cardano-api and prettyException
1 parent 4da36e3 commit 5784d62

File tree

5 files changed

+19
-54
lines changed

5 files changed

+19
-54
lines changed

cabal.project

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,13 @@ index-state:
1919
packages:
2020
cardano-cli
2121

22+
source-repository-package
23+
type: git
24+
location: https://github.com/IntersectMBO/cardano-api
25+
tag: b00053d15adc71c835eba64e7c9cf68af296ea63
26+
subdir: cardano-api
27+
--sha256: sha256-pSJeH9qpc0Vs4FkfUdRvX50uWfATcZarBf85p2U/x1I=
28+
2229
program-options
2330
ghc-options: -Werror
2431

cardano-cli/cardano-cli.cabal

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ library
8484
Cardano.CLI.EraBased.Commands.StakePool
8585
Cardano.CLI.EraBased.Commands.TextView
8686
Cardano.CLI.EraBased.Commands.Transaction
87-
Cardano.CLI.EraBased.HashChecking
8887
Cardano.CLI.EraBased.Options.Common
8988
Cardano.CLI.EraBased.Options.Genesis
9089
Cardano.CLI.EraBased.Options.Governance
@@ -114,6 +113,7 @@ library
114113
Cardano.CLI.EraBased.Run.StakePool
115114
Cardano.CLI.EraBased.Run.TextView
116115
Cardano.CLI.EraBased.Run.Transaction
116+
Cardano.CLI.EraBased.Transaction.HashCheck
117117
Cardano.CLI.Helpers
118118
Cardano.CLI.IO.Compat
119119
Cardano.CLI.IO.Lazy
@@ -208,7 +208,6 @@ library
208208
cardano-crypto-wrapper ^>=1.5.1,
209209
cardano-data >=1.1,
210210
cardano-git-rev ^>=0.2.2,
211-
cardano-ledger-api,
212211
cardano-ping ^>=0.5,
213212
cardano-prelude,
214213
cardano-slotting ^>=0.2.0.0,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ import Cardano.Api.Shelley
4343

4444
import qualified Cardano.Binary as CBOR
4545
import qualified Cardano.CLI.EraBased.Commands.Transaction as Cmd
46-
import Cardano.CLI.EraBased.HashChecking (checkCertificateHashes, checkProposalHashes,
47-
checkVotingProcedureHashes)
4846
import Cardano.CLI.EraBased.Run.Genesis.Common (readProtocolParameters)
4947
import Cardano.CLI.EraBased.Run.Query
48+
import Cardano.CLI.EraBased.Transaction.HashCheck (checkCertificateHashes,
49+
checkProposalHashes, checkVotingProcedureHashes)
5050
import Cardano.CLI.Read
5151
import Cardano.CLI.Types.Common
5252
import Cardano.CLI.Types.Errors.BootstrapWitnessError

cardano-cli/src/Cardano/CLI/EraBased/HashChecking.hs renamed to cardano-cli/src/Cardano/CLI/EraBased/Transaction/HashCheck.hs

Lines changed: 5 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{-# LANGUAGE ScopedTypeVariables #-}
22

3-
module Cardano.CLI.EraBased.HashChecking
3+
module Cardano.CLI.EraBased.Transaction.HashCheck
44
( checkCertificateHashes
55
, checkVotingProcedureHashes
66
, checkProposalHashes
@@ -14,10 +14,9 @@ import qualified Cardano.Api.Shelley as Shelley
1414
import Cardano.CLI.Run.Hash (carryHashChecks)
1515
import Cardano.CLI.Types.Common (MustCheckHash (..), PotentiallyCheckedAnchor (..))
1616
import Cardano.CLI.Types.Errors.TxCmdError (TxCmdError (..))
17-
import qualified Cardano.Ledger.Api.Governance as L
1817

1918
import Control.Monad (forM_)
20-
import Control.Monad.Trans.Except.Extra (left)
19+
import qualified Cardano.Api as L
2120

2221
-- | Check the hash of the anchor data against the hash in the anchor
2322
checkAnchorMetadataHash :: L.Anchor L.StandardCrypto -> ExceptT TxCmdError IO ()
@@ -33,48 +32,9 @@ checkAnchorMetadataHash anchor =
3332
-- | Find references to anchor data and check the hashes are valid
3433
-- and they match the linked data.
3534
checkCertificateHashes :: Certificate era -> ExceptT TxCmdError IO ()
36-
checkCertificateHashes c =
37-
case c of
38-
ShelleyRelatedCertificate _ shelleyCert ->
39-
case shelleyCert of
40-
L.ShelleyTxCertDelegCert shelleyDelegCert ->
41-
case shelleyDelegCert of
42-
L.ShelleyRegCert _ -> return ()
43-
L.ShelleyUnRegCert _ -> return ()
44-
L.ShelleyDelegCert _ _ -> return ()
45-
L.ShelleyTxCertPool shelleyPoolCert ->
46-
case shelleyPoolCert of
47-
L.RegPool poolParams -> forM_ (L.ppMetadata poolParams) checkPoolMetadataHash
48-
L.RetirePool _ _ -> return ()
49-
L.ShelleyTxCertGenesisDeleg _ -> return ()
50-
L.ShelleyTxCertMir _ -> return ()
51-
ConwayCertificate ceo conwayCert ->
52-
Shelley.conwayEraOnwardsConstraints ceo $
53-
case conwayCert of
54-
L.ConwayTxCertDeleg _ -> return ()
55-
L.ConwayTxCertPool conwayPoolCert ->
56-
case conwayPoolCert of
57-
L.RegPool poolParams -> forM_ (L.ppMetadata poolParams) checkPoolMetadataHash
58-
L.RetirePool _ _ -> return ()
59-
L.ConwayTxCertGov govCert ->
60-
case govCert of
61-
L.ConwayRegDRep _ _ mAnchor -> forM_ mAnchor checkAnchorMetadataHash
62-
L.ConwayUnRegDRep _ _ -> return ()
63-
L.ConwayUpdateDRep _ mAnchor -> forM_ mAnchor checkAnchorMetadataHash
64-
L.ConwayAuthCommitteeHotKey _ _ -> return ()
65-
L.ConwayResignCommitteeColdKey _ mAnchor -> forM_ mAnchor checkAnchorMetadataHash
66-
where
67-
checkPoolMetadataHash :: L.PoolMetadata -> ExceptT TxCmdError IO ()
68-
checkPoolMetadataHash (L.PoolMetadata{L.pmUrl = url, L.pmHash = hashBytes}) = do
69-
let mHash = L.hashFromBytes hashBytes
70-
hash <- maybe (left $ TxCmdPoolMetadataHashError url) return mHash
71-
let safeHash = L.unsafeMakeSafeHash hash
72-
checkAnchorMetadataHash
73-
( L.Anchor
74-
{ L.anchorUrl = url
75-
, L.anchorDataHash = safeHash
76-
}
77-
)
35+
checkCertificateHashes cert = do
36+
mAnchor <- L.withExceptT TxCmdPoolMetadataHashError $ L.getAnchorDataFromCertificate cert
37+
maybe (return mempty) checkAnchorMetadataHash mAnchor
7838

7939
-- | Find references to anchor data in voting procedures and check the hashes are valid
8040
-- and they match the linked data.

cardano-cli/src/Cardano/CLI/Types/Errors/TxCmdError.hs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import Cardano.CLI.Types.TxFeature
3131
import qualified Cardano.Prelude as List
3232
import Ouroboros.Consensus.Cardano.Block (EraMismatch (..))
3333

34-
import Control.Exception (displayException)
3534
import Data.Text (Text)
3635

3736
{- HLINT ignore "Use let" -}
@@ -87,7 +86,7 @@ data TxCmdError
8786
| TxCmdProtocolParamsConverstionError ProtocolParametersConversionError
8887
| forall era. TxCmdTxGovDuplicateVotes (TxGovDuplicateVotes era)
8988
| forall era. TxCmdFeeEstimationError (TxFeeEstimationError era)
90-
| TxCmdPoolMetadataHashError L.Url
89+
| TxCmdPoolMetadataHashError AnchorDataFromCertificateException
9190
| TxCmdHashCheckError L.Url HashCheckError
9291

9392
renderTxCmdError :: TxCmdError -> Doc ann
@@ -222,10 +221,10 @@ renderTxCmdError = \case
222221
prettyError e
223222
TxCmdFeeEstimationError e ->
224223
prettyError e
225-
TxCmdPoolMetadataHashError url ->
226-
"Hash of the pool metadata file is not valid. Url:" <+> pretty (L.urlToText url)
224+
TxCmdPoolMetadataHashError e ->
225+
"Hash of the pool metadata hash is not valid:" <+> prettyException e
227226
TxCmdHashCheckError url e ->
228-
"Hash of the file is not valid. Url:" <+> pretty (L.urlToText url) <+> pretty (displayException e)
227+
"Hash of the file is not valid. Url:" <+> pretty (L.urlToText url) <+> prettyException e
229228

230229
prettyPolicyIdList :: [PolicyId] -> Doc ann
231230
prettyPolicyIdList =

0 commit comments

Comments
 (0)