Skip to content

Commit

Permalink
Merge pull request #307 from input-output-hk/newhoggy/delete-EraCast-…
Browse files Browse the repository at this point in the history
…instance-for-Certificate

Delete `EraCast` instance for `Certificate`
  • Loading branch information
newhoggy authored Oct 9, 2023
2 parents f9572d5 + fd3b5dc commit 2c214be
Showing 1 changed file with 0 additions and 148 deletions.
148 changes: 0 additions & 148 deletions cardano-api/internal/Cardano/Api/Certificate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ import Cardano.Api.DRepMetadata
import Cardano.Api.Eon.ConwayEraOnwards
import Cardano.Api.Eon.ShelleyBasedEra
import Cardano.Api.Eon.ShelleyToBabbageEra
import Cardano.Api.EraCast
import Cardano.Api.Eras
import Cardano.Api.Eras.Constraints
import Cardano.Api.Governance.Actions.VotingProcedure
Expand Down Expand Up @@ -182,153 +181,6 @@ instance
ConwayCertificate _ (Ledger.ConwayTxCertPool Ledger.RegPool{}) -> "Pool registration"
ConwayCertificate _ (Ledger.ConwayTxCertPool Ledger.RetirePool{}) -> "Pool retirement"

castShelleyTxCert :: ()
=> EraCrypto srcLedgerEra ~ StandardCrypto
=> EraCrypto tgtLedgerEra ~ StandardCrypto
=> Ledger.ShelleyTxCert srcLedgerEra
-> Ledger.ShelleyTxCert tgtLedgerEra
castShelleyTxCert = \case
Ledger.ShelleyTxCertDelegCert c ->
Ledger.ShelleyTxCertDelegCert c
Ledger.ShelleyTxCertPool c ->
Ledger.ShelleyTxCertPool c
Ledger.ShelleyTxCertGenesisDeleg c ->
Ledger.ShelleyTxCertGenesisDeleg c
Ledger.ShelleyTxCertMir c ->
Ledger.ShelleyTxCertMir c

castConwayTxCert :: ()
=> EraCrypto srcLedgerEra ~ StandardCrypto
=> EraCrypto tgtLedgerEra ~ StandardCrypto
=> Ledger.ConwayTxCert srcLedgerEra
-> Ledger.ConwayTxCert tgtLedgerEra
castConwayTxCert = \case
Ledger.ConwayTxCertDeleg c ->
Ledger.ConwayTxCertDeleg c
Ledger.ConwayTxCertPool c ->
Ledger.ConwayTxCertPool c
Ledger.ConwayTxCertGov c ->
Ledger.ConwayTxCertGov c

castShelleyToConwayTxCert :: ()
=> EraCrypto srcLedgerEra ~ StandardCrypto
=> EraCrypto tgtLedgerEra ~ StandardCrypto
=> Ledger.ShelleyTxCert srcLedgerEra
-> Maybe (Ledger.ConwayTxCert tgtLedgerEra)
castShelleyToConwayTxCert = \case
Ledger.ShelleyTxCertDelegCert c ->
fmap Ledger.ConwayTxCertDeleg
$ case c of
Ledger.ShelleyRegCert sc ->
Just $ Ledger.ConwayRegCert sc Ledger.SNothing
Ledger.ShelleyUnRegCert sc ->
Just $ Ledger.ConwayUnRegCert sc Ledger.SNothing
Ledger.ShelleyDelegCert sc ph ->
Just $ Ledger.ConwayDelegCert sc (Ledger.DelegStake ph)
Ledger.ShelleyTxCertPool c ->
Just $ Ledger.ConwayTxCertPool c
Ledger.ShelleyTxCertGenesisDeleg _ ->
Nothing
Ledger.ShelleyTxCertMir _ ->
Nothing

castConwayToShelleyTxCert :: ()
=> EraCrypto srcLedgerEra ~ StandardCrypto
=> EraCrypto tgtLedgerEra ~ StandardCrypto
=> Ledger.ConwayTxCert srcLedgerEra
-> Maybe (Ledger.ShelleyTxCert tgtLedgerEra)
castConwayToShelleyTxCert = \case
Ledger.ConwayTxCertDeleg txCert ->
fmap Ledger.ShelleyTxCertDelegCert
$ case txCert of
Ledger.ConwayRegCert stakeCred mCoin ->
case mCoin of
Ledger.SNothing ->
Just $ Ledger.ShelleyRegCert stakeCred
Ledger.SJust {} ->
Nothing
Ledger.ConwayUnRegCert stakeCred mCoin ->
case mCoin of
Ledger.SNothing ->
Just $ Ledger.ShelleyUnRegCert stakeCred
Ledger.SJust {} ->
Nothing
Ledger.ConwayDelegCert stakeCred delegCert ->
case delegCert of
Ledger.DelegStake poolHash ->
Just $ Ledger.ShelleyDelegCert stakeCred poolHash
Ledger.DelegVote {} ->
Nothing
Ledger.DelegStakeVote {} ->
Nothing
Ledger.ConwayRegDelegCert {} ->
Nothing
Ledger.ConwayTxCertPool poolCert ->
Just $ Ledger.ShelleyTxCertPool poolCert
Ledger.ConwayTxCertGov {} ->
Nothing

instance EraCast Certificate where
eraCast targetEra cert =
case cert of
ShelleyRelatedCertificate sourceWit sourceLedgerCert ->
shelleyToBabbageEraConstraints sourceWit
$ forEraInEon targetEra
( forEraInEon targetEra
( Left $ EraCastError
{ originalValue = cert
, fromEra = shelleyToBabbageEraToCardanoEra sourceWit
, toEra = targetEra
}
)
(\tgtw ->
conwayEraOnwardsConstraints tgtw
$ case castShelleyToConwayTxCert sourceLedgerCert of
Just targetLedgerCert -> Right $ ConwayCertificate tgtw targetLedgerCert
Nothing ->
Left $ EraCastError
{ originalValue = cert
, fromEra = shelleyToBabbageEraToCardanoEra sourceWit
, toEra = targetEra
}
)
)
(\targetWit ->
Right
$ ShelleyRelatedCertificate targetWit
$ shelleyToBabbageEraConstraints targetWit
$ castShelleyTxCert sourceLedgerCert
)

ConwayCertificate sourceWit sourceLedgerCert ->
conwayEraOnwardsConstraints sourceWit
$ forEraInEon targetEra
( forEraInEon targetEra
( Left $ EraCastError
{ originalValue = cert
, fromEra = conwayEraOnwardsToCardanoEra sourceWit
, toEra = targetEra
}
)
(\targetWit ->
shelleyToBabbageEraConstraints targetWit
$ case castConwayToShelleyTxCert sourceLedgerCert of
Just targetLedgerCert -> Right $ ShelleyRelatedCertificate targetWit targetLedgerCert
Nothing ->
Left $ EraCastError
{ originalValue = cert
, fromEra = conwayEraOnwardsToCardanoEra sourceWit
, toEra = targetEra
}
)
)
(\targetWit ->
Right
$ ConwayCertificate targetWit
$ conwayEraOnwardsConstraints targetWit
$ castConwayTxCert sourceLedgerCert
)

-- ----------------------------------------------------------------------------
-- Stake pool parameters
--
Expand Down

0 comments on commit 2c214be

Please sign in to comment.