Skip to content

Commit

Permalink
Add function to access anchor data from GovAction and fix typo
Browse files Browse the repository at this point in the history
  • Loading branch information
palas committed Nov 4, 2024
1 parent aa84fe9 commit 62a42f4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cardano-api/internal/Cardano/Api/Certificate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 3 additions & 0 deletions cardano-api/src/Cardano/Api.hs
Original file line number Diff line number Diff line change
Expand Up @@ -999,6 +999,9 @@ module Cardano.Api
, DRepMetadataReference
, hashDRepMetadata

-- ** Governance actions
, getAnchorDataFromGovernanceAction

-- ** Governance related certificates
, AnchorDataHash (..)
, AnchorUrl (..)
Expand Down

0 comments on commit 62a42f4

Please sign in to comment.