@@ -56,6 +56,9 @@ module Cardano.Api.Certificate
56
56
, Ledger. MIRPot (.. )
57
57
, selectStakeCredentialWitness
58
58
59
+ -- * Anchor data
60
+ , getAnchorDataFromCertificate
61
+
59
62
-- * Internal conversion functions
60
63
, toShelleyCertificate
61
64
, fromShelleyCertificate
@@ -90,6 +93,7 @@ import Cardano.Api.StakePoolMetadata
90
93
import Cardano.Api.Utils (noInlineMaybeToStrictMaybe )
91
94
import Cardano.Api.Value
92
95
96
+ import Cardano.Ledger.BaseTypes (strictMaybe )
93
97
import qualified Cardano.Ledger.Coin as L
94
98
import qualified Cardano.Ledger.Keys as Ledger
95
99
@@ -724,3 +728,46 @@ fromShelleyPoolParams
724
728
fromShelleyDnsName =
725
729
Text. encodeUtf8
726
730
. Ledger. dnsToText
731
+
732
+ -- | Get anchor data hash from a certificate
733
+ getAnchorDataFromCertificate :: Certificate era -> Maybe (Ledger. Anchor StandardCrypto )
734
+ getAnchorDataFromCertificate =
735
+ \ case
736
+ ShelleyRelatedCertificate _ shelleyCert ->
737
+ case shelleyCert of
738
+ Ledger. ShelleyTxCertDelegCert shelleyDelegCert ->
739
+ case shelleyDelegCert of
740
+ Ledger. ShelleyRegCert _ -> Nothing
741
+ Ledger. ShelleyUnRegCert _ -> Nothing
742
+ Ledger. ShelleyDelegCert _ _ -> Nothing
743
+ Ledger. ShelleyTxCertPool shelleyPoolCert ->
744
+ case shelleyPoolCert of
745
+ Ledger. RegPool poolParams -> strictMaybe Nothing anchorDataFromPoolMetadata $ Ledger. ppMetadata poolParams
746
+ Ledger. RetirePool _ _ -> Nothing
747
+ Ledger. ShelleyTxCertGenesisDeleg _ -> Nothing
748
+ Ledger. ShelleyTxCertMir _ -> Nothing
749
+ ConwayCertificate ceo conwayCert ->
750
+ conwayEraOnwardsConstraints ceo $
751
+ case conwayCert of
752
+ Ledger. ConwayTxCertDeleg _ -> Nothing
753
+ Ledger. ConwayTxCertPool conwayPoolCert ->
754
+ case conwayPoolCert of
755
+ Ledger. RegPool poolParams -> strictMaybe Nothing anchorDataFromPoolMetadata $ Ledger. ppMetadata poolParams
756
+ Ledger. RetirePool _ _ -> Nothing
757
+ Ledger. ConwayTxCertGov govCert ->
758
+ case govCert of
759
+ Ledger. ConwayRegDRep _ _ mAnchor -> Ledger. strictMaybeToMaybe mAnchor
760
+ Ledger. ConwayUnRegDRep _ _ -> Nothing
761
+ Ledger. ConwayUpdateDRep _ mAnchor -> Ledger. strictMaybeToMaybe mAnchor
762
+ Ledger. ConwayAuthCommitteeHotKey _ _ -> Nothing
763
+ Ledger. ConwayResignCommitteeColdKey _ mAnchor -> Ledger. strictMaybeToMaybe mAnchor
764
+ where
765
+ anchorDataFromPoolMetadata :: Ledger. PoolMetadata -> Maybe (Ledger. Anchor StandardCrypto )
766
+ anchorDataFromPoolMetadata (Ledger. PoolMetadata {Ledger. pmUrl = url, Ledger. pmHash = hashBytes}) = do
767
+ hash <- Ledger. hashFromBytes hashBytes
768
+ return
769
+ ( Ledger. Anchor
770
+ { Ledger. anchorUrl = url
771
+ , Ledger. anchorDataHash = Ledger. unsafeMakeSafeHash hash
772
+ }
773
+ )
0 commit comments