From 694008ad941d3066315620f77a2dbe05f96ed2b6 Mon Sep 17 00:00:00 2001 From: Pablo Lamela Date: Thu, 31 Oct 2024 14:15:22 +0100 Subject: [PATCH] Add function to access anchor data from `GovAction` and fix typo --- cardano-api/internal/Cardano/Api/Certificate.hs | 2 +- .../Api/Governance/Actions/ProposalProcedure.hs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/cardano-api/internal/Cardano/Api/Certificate.hs b/cardano-api/internal/Cardano/Api/Certificate.hs index 94ef89fab7..dc1c7ee494 100644 --- a/cardano-api/internal/Cardano/Api/Certificate.hs +++ b/cardano-api/internal/Cardano/Api/Certificate.hs @@ -743,7 +743,7 @@ instance Error AnchorDataFromCertificateError where prettyError (InvalidPoolMetadataHashError url hash) = "Invalid pool metadata hash for URL " <> fromString (show url) <> ": " <> fromString (show hash) --- | Get anchor data hash from a certificate. A return value of `Nothing` +-- | Get anchor data url and hash from a certificate. A return value of `Nothing` -- means that the certificate does not contain anchor data. getAnchorDataFromCertificate :: Certificate era diff --git a/cardano-api/internal/Cardano/Api/Governance/Actions/ProposalProcedure.hs b/cardano-api/internal/Cardano/Api/Governance/Actions/ProposalProcedure.hs index 6f4b202ae0..fb4ff3b934 100644 --- a/cardano-api/internal/Cardano/Api/Governance/Actions/ProposalProcedure.hs +++ b/cardano-api/internal/Cardano/Api/Governance/Actions/ProposalProcedure.hs @@ -230,3 +230,19 @@ createAnchor url anchorData = { anchorUrl = url , anchorDataHash = hashAnchorData $ Ledger.AnchorData anchorData } + +-- | Get anchor data url and hash from a governance action. A return value of `Nothing` +-- means that the governance action does not contain anchor data. +getAnchorDataFromGovernanceAction + :: EraCrypto (ShelleyLedgerEra era) ~ StandardCrypto + => Gov.GovAction (ShelleyLedgerEra era) + -> Maybe (Ledger.Anchor StandardCrypto) +getAnchorDataFromGovernanceAction govAction = + case govAction of + Gov.ParameterChange{} -> Nothing + Gov.HardForkInitiation _ _ -> Nothing + Gov.TreasuryWithdrawals _ _ -> Nothing + Gov.NoConfidence _ -> Nothing + Gov.UpdateCommittee{} -> Nothing + Gov.NewConstitution _ constitution -> Just $ Ledger.constitutionAnchor constitution + Gov.InfoAction -> Nothing