From d5ba87416863e54eb978a57aa746ef3914a7d010 Mon Sep 17 00:00:00 2001 From: Jordan Millar Date: Tue, 22 Aug 2023 12:20:26 -0400 Subject: [PATCH 1/2] Update createAnchor to use hashAnchorData --- .../Governance/Actions/ProposalProcedure.hs | 18 +++--------------- cardano-api/src/Cardano/Api/Shelley.hs | 1 - 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/cardano-api/internal/Cardano/Api/Governance/Actions/ProposalProcedure.hs b/cardano-api/internal/Cardano/Api/Governance/Actions/ProposalProcedure.hs index 1a37290361..3bd28b7edc 100644 --- a/cardano-api/internal/Cardano/Api/Governance/Actions/ProposalProcedure.hs +++ b/cardano-api/internal/Cardano/Api/Governance/Actions/ProposalProcedure.hs @@ -25,7 +25,6 @@ import Cardano.Api.TxIn import Cardano.Api.Value import qualified Cardano.Binary as CBOR -import qualified Cardano.Crypto.Hash.Class as Crypto import qualified Cardano.Ledger.Address as L import Cardano.Ledger.BaseTypes import qualified Cardano.Ledger.Conway as Conway @@ -34,9 +33,8 @@ import qualified Cardano.Ledger.Conway.Governance as Ledger import Cardano.Ledger.Core (EraCrypto) import qualified Cardano.Ledger.Core as Shelley import qualified Cardano.Ledger.Credential as L -import Cardano.Ledger.Crypto (HASH, StandardCrypto) +import Cardano.Ledger.Crypto (StandardCrypto) import Cardano.Ledger.Keys (HasKeyRole (coerceKeyRole), KeyRole (ColdCommitteeRole)) -import Cardano.Ledger.SafeHash import Data.ByteString (ByteString) import Data.Map.Strict (Map) @@ -234,7 +232,7 @@ createAnchor :: Url -> ByteString -> Anchor StandardCrypto createAnchor url anchorData = Ledger.Anchor { anchorUrl = url - , anchorDataHash = unsafeBytesToSafeHash anchorData + , anchorDataHash = hashAnchorData $ Ledger.AnchorData anchorData } -- ---------------------------------------------------------------------------- @@ -249,14 +247,4 @@ fromCommitteeMember = (. coerceKeyRole) $ \case L.KeyHashObj keyhash -> StakeKeyHash keyhash L.ScriptHashObj _scripthash -> error "TODO script committee members not yet supported" --- | TODO: I'm very unsure whether it's correct to use 'unsafeMakeSafeHash' --- here? I've asked Alexey if maybe this doesn't need to actually be a --- 'SafeHash', which would let us remove it. -unsafeBytesToSafeHash - :: Crypto.HashAlgorithm (HASH c) - => ByteString - -> SafeHash c a -unsafeBytesToSafeHash bs = case Crypto.hashFromBytes bs of - Nothing -> - error "unsafeBytesToSafeHash: input data is not a valid hash" - Just h -> unsafeMakeSafeHash h + diff --git a/cardano-api/src/Cardano/Api/Shelley.hs b/cardano-api/src/Cardano/Api/Shelley.hs index 235c002c43..87e39af4b3 100644 --- a/cardano-api/src/Cardano/Api/Shelley.hs +++ b/cardano-api/src/Cardano/Api/Shelley.hs @@ -196,7 +196,6 @@ module Cardano.Api.Shelley createAnchor, createPreviousGovernanceActionId, createGovernanceActionId, - unsafeBytesToSafeHash, -- * DRep DRepMetadata(DRepMetadata), From a0457d32c7eedb1ae3e84fd636188da54982f420 Mon Sep 17 00:00:00 2001 From: Jordan Millar Date: Tue, 22 Aug 2023 12:11:17 -0400 Subject: [PATCH 2/2] Update Cardano.Api.ReexposeLedger to expose more ledger types --- .../internal/Cardano/Api/ReexposeLedger.hs | 47 +++++++++++++++++-- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/cardano-api/internal/Cardano/Api/ReexposeLedger.hs b/cardano-api/internal/Cardano/Api/ReexposeLedger.hs index 1df99282c5..674c507081 100644 --- a/cardano-api/internal/Cardano/Api/ReexposeLedger.hs +++ b/cardano-api/internal/Cardano/Api/ReexposeLedger.hs @@ -1,6 +1,7 @@ +{-# LANGUAGE PatternSynonyms #-} + module Cardano.Api.ReexposeLedger - ( module Cardano.Ledger.Api - , Credential (..) + ( Credential (..) , KeyHash(..) , KeyRole(..) , ShelleyTxCert(..) @@ -16,23 +17,46 @@ module Cardano.Api.ReexposeLedger , PoolMetadata(..) , EraTxCert(..) , StrictMaybe(..) + , pattern DelegTxCert + , pattern RegPoolTxCert + , pattern RetirePoolTxCert + , pattern RegDepositTxCert + , pattern UnRegDepositTxCert + , pattern UnRegDRepTxCert + , pattern AuthCommitteeHotKeyTxCert + , pattern ResignCommitteeColdTxCert + , pattern RegTxCert + , pattern UnRegTxCert + , pattern RegDepositDelegTxCert + , pattern RegDRepTxCert -- Core , Coin (..) , EraCrypto , Network(..) , PoolCert(..) + , PParams(..) , addDeltaCoin , toDeltaCoin , toEraCBOR , fromEraCBOR -- Conway + , Delegatee(..) , DRep(..) , ConwayTxCert(..) , ConwayDelegCert(..) , ConwayEraTxCert(..) , ConwayGovCert(..) + , GovActionId(..) + , Vote (..) + , Voter (..) + , VotingProcedure(..) + -- Babbage + , CoinPerByte (..) + + -- Alonzo + , CoinPerWord (..) -- Base , boundRational @@ -50,21 +74,33 @@ module Cardano.Api.ReexposeLedger -- Crypto , hashToBytes , hashFromBytes + , Crypto + , StandardCrypto -- Slotting , EpochNo(..) ) where import Cardano.Crypto.Hash.Class (hashFromBytes, hashToBytes) -import Cardano.Ledger.Api +import Cardano.Ledger.Alonzo.Core (CoinPerWord (..)) +import Cardano.Ledger.Api.Tx.Cert (pattern AuthCommitteeHotKeyTxCert, pattern DelegTxCert, + pattern RegDRepTxCert, pattern RegDepositDelegTxCert, pattern RegDepositTxCert, + pattern RegPoolTxCert, pattern RegTxCert, pattern ResignCommitteeColdTxCert, + pattern RetirePoolTxCert, pattern UnRegDRepTxCert, pattern UnRegDepositTxCert, + pattern UnRegTxCert) +import Cardano.Ledger.Babbage.Core (CoinPerByte (..)) import Cardano.Ledger.BaseTypes (DnsName, Network (..), StrictMaybe (..), Url, boundRational, dnsToText, maybeToStrictMaybe, portToWord16, strictMaybeToMaybe, textToDns, textToUrl, unboundRational, urlToText) import Cardano.Ledger.Coin (Coin (..), addDeltaCoin, toDeltaCoin) +import Cardano.Ledger.Conway.Governance (GovActionId (..), Vote (..), Voter (..), + VotingProcedure (..)) import Cardano.Ledger.Conway.TxCert (ConwayDelegCert (..), ConwayEraTxCert (..), - ConwayGovCert (..), ConwayTxCert (..)) -import Cardano.Ledger.Core (DRep (..), EraCrypto, PoolCert (..), fromEraCBOR, toEraCBOR) + ConwayGovCert (..), ConwayTxCert (..), Delegatee (..)) +import Cardano.Ledger.Core (DRep (..), EraCrypto, PParams (..), PoolCert (..), + fromEraCBOR, toEraCBOR) import Cardano.Ledger.Credential (Credential (..)) +import Cardano.Ledger.Crypto (Crypto, StandardCrypto) import Cardano.Ledger.Keys (HasKeyRole (..), KeyHash (..), KeyRole (..)) import Cardano.Ledger.PoolParams (PoolMetadata (..), PoolParams (..), StakePoolRelay (..)) import Cardano.Ledger.Shelley.TxCert (EraTxCert (..), GenesisDelegCert (..), MIRCert (..), @@ -72,3 +108,4 @@ import Cardano.Ledger.Shelley.TxCert (EraTxCert (..), GenesisDelegCert ShelleyTxCert (..)) import Cardano.Slotting.Slot (EpochNo (..)) +