Skip to content

Commit d5e0a29

Browse files
committed
Add function to access anchor data from GovAction and fix typo
1 parent 3bf693a commit d5e0a29

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

cardano-api/internal/Cardano/Api/Certificate.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ instance Error AnchorDataFromCertificateError where
743743
prettyError (InvalidPoolMetadataHashError url hash) =
744744
"Invalid pool metadata hash for URL " <> fromString (show url) <> ": " <> fromString (show hash)
745745

746-
-- | Get anchor data hash from a certificate. A return value of `Nothing`
746+
-- | Get anchor data url and hash from a certificate. A return value of `Nothing`
747747
-- means that the certificate does not contain anchor data.
748748
getAnchorDataFromCertificate
749749
:: Certificate era

cardano-api/internal/Cardano/Api/Governance/Actions/ProposalProcedure.hs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,3 +230,19 @@ createAnchor url anchorData =
230230
{ anchorUrl = url
231231
, anchorDataHash = hashAnchorData $ Ledger.AnchorData anchorData
232232
}
233+
234+
-- | Get anchor data url and hash from a governance action. A return value of `Nothing`
235+
-- means that the governance action does not contain anchor data.
236+
getAnchorDataFromGovernanceAction
237+
:: EraCrypto (ShelleyLedgerEra era) ~ StandardCrypto
238+
=> Gov.GovAction (ShelleyLedgerEra era)
239+
-> Maybe (Ledger.Anchor StandardCrypto)
240+
getAnchorDataFromGovernanceAction govAction =
241+
case govAction of
242+
Gov.ParameterChange{} -> Nothing
243+
Gov.HardForkInitiation _ _ -> Nothing
244+
Gov.TreasuryWithdrawals _ _ -> Nothing
245+
Gov.NoConfidence _ -> Nothing
246+
Gov.UpdateCommittee{} -> Nothing
247+
Gov.NewConstitution _ constitution -> Just $ Ledger.constitutionAnchor constitution
248+
Gov.InfoAction -> Nothing

cardano-api/src/Cardano/Api.hs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,9 @@ module Cardano.Api
999999
, DRepMetadataReference
10001000
, hashDRepMetadata
10011001

1002+
-- ** Governance actions
1003+
, getAnchorDataFromGovernanceAction
1004+
10021005
-- ** Governance related certificates
10031006
, AnchorDataHash (..)
10041007
, AnchorUrl (..)

0 commit comments

Comments
 (0)