Skip to content

Commit 833aa4e

Browse files
committed
Add Dijkstra era support to experimental eras
1 parent ca7297f commit 833aa4e

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

cardano-api/src/Cardano/Api/Experimental/Era.hs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ module Cardano.Api.Experimental.Era
2626
, DeprecatedEra (..)
2727
, EraCommonConstraints
2828
, obtainCommonConstraints
29+
, obtainConwayConstraints
2930
, eraToSbe
3031
, eraToBabbageEraOnwards
3132
, sbeToEra
@@ -289,7 +290,10 @@ obtainCommonConstraints
289290
-> a
290291
obtainCommonConstraints = \case
291292
ConwayEra -> id
292-
_ -> const $ error "obtainCommonConstraints: Dijkstra era not yet supported"
293+
DijkstraEra -> id
294+
295+
obtainConwayConstraints :: Era ConwayEra -> (EraConwayConstraints => a) -> a
296+
obtainConwayConstraints ConwayEra a = a
293297

294298
type EraCommonConstraints era =
295299
( L.AllegraEraScript (LedgerEra era)
@@ -298,7 +302,6 @@ type EraCommonConstraints era =
298302
, L.BabbageEraTxBody (LedgerEra era)
299303
, L.ConwayEraTxBody (LedgerEra era)
300304
, L.ConwayEraTxCert (LedgerEra era)
301-
, L.TxCert (LedgerEra era) ~ L.ConwayTxCert (LedgerEra era)
302305
, L.Era (LedgerEra era)
303306
, L.EraScript (LedgerEra era)
304307
, L.EraTx (LedgerEra era)
@@ -308,11 +311,16 @@ type EraCommonConstraints era =
308311
, FromCBOR (ChainDepState (ConsensusProtocol era))
309312
, L.NativeScript (LedgerEra era) ~ L.Timelock (LedgerEra era)
310313
, PraosProtocolSupportsNode (ConsensusProtocol era)
311-
, L.ShelleyEraTxCert (LedgerEra era)
312314
, ShelleyLedgerEra era ~ LedgerEra era
313315
, ToJSON (ChainDepState (ConsensusProtocol era))
314316
, L.HashAnnotated (Ledger.TxBody (LedgerEra era)) L.EraIndependentTxBody
315317
, Api.IsCardanoEra era
316318
, Api.IsShelleyBasedEra era
317319
, IsEra era
318320
)
321+
322+
type EraConwayConstraints =
323+
( EraCommonConstraints ConwayEra
324+
, L.TxCert (LedgerEra ConwayEra) ~ L.ConwayTxCert (LedgerEra ConwayEra)
325+
, L.ShelleyEraTxCert (LedgerEra ConwayEra)
326+
)

cardano-api/src/Cardano/Api/Experimental/Tx/Internal/Certificate.hs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@ instance
8383
shelleyBasedEraConstraints (shelleyBasedEra @era) $ Certificate <$> CBOR.decodeFull' bs
8484

8585
convertToOldApiCertificate :: Era era -> Certificate (LedgerEra era) -> Api.Certificate era
86-
convertToOldApiCertificate e (Certificate cert) =
87-
obtainCommonConstraints e $ Api.ConwayCertificate (convert e) cert
86+
convertToOldApiCertificate e@ConwayEra (Certificate cert) =
87+
obtainConwayConstraints e $ Api.ConwayCertificate (convert e) cert
88+
convertToOldApiCertificate DijkstraEra _ = error "Dijkstra era not supported yet"
8889

8990
convertToNewCertificate :: Era era -> Api.Certificate era -> Certificate (LedgerEra era)
9091
convertToNewCertificate era (Api.ConwayCertificate _ cert) =
@@ -113,8 +114,8 @@ getStakeCred
113114
Api.BuildTx
114115
(Maybe (Api.StakeCredential, Api.Witness Api.WitCtxStake era))
115116
)
116-
getStakeCred e (Certificate cert, witness) = do
117-
let oldApiCert = obtainCommonConstraints e $ Api.ConwayCertificate (convert e) cert
117+
getStakeCred e@ConwayEra (Certificate cert, witness) = do
118+
let oldApiCert = obtainConwayConstraints e $ Api.ConwayCertificate (convert e) cert
118119
mStakeCred = Api.selectStakeCredentialWitness oldApiCert
119120
wit =
120121
case witness of
@@ -127,6 +128,7 @@ getStakeCred e (Certificate cert, witness) = do
127128
Api.ScriptWitness Api.ScriptWitnessForStakeAddr $
128129
newToOldPlutusCertificateScriptWitness e psw
129130
(oldApiCert, pure $ (,wit) <$> mStakeCred)
131+
getStakeCred DijkstraEra _ = error "Dijkstra era not supported yet"
130132

131133
newToOldSimpleScriptWitness
132134
:: L.AllegraEraScript (LedgerEra era)

cardano-api/src/Cardano/Api/Ledger/Internal/Reexport.hs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ module Cardano.Api.Ledger.Internal.Reexport
6464
, fromEraCBOR
6565
, ppMinFeeAL
6666
, ppMinUTxOValueL
67+
-- Dijkstra
68+
, DijkstraPlutusPurpose (..)
6769
-- Conway
6870
, Anchor (..)
6971
, Committee (..)
@@ -320,6 +322,7 @@ import Cardano.Ledger.Core
320322
)
321323
import Cardano.Ledger.Credential (Credential (..), credToText)
322324
import Cardano.Ledger.DRep (DRep (..), drepAnchorL, drepDepositL, drepExpiryL)
325+
import Cardano.Ledger.Dijkstra.Scripts (DijkstraPlutusPurpose (..))
323326
import Cardano.Ledger.Hashes
324327
( ADDRHASH
325328
, SafeHash
@@ -339,7 +342,6 @@ import Cardano.Ledger.Keys
339342
import Cardano.Ledger.Mary.Value (MultiAsset (..))
340343
import Cardano.Ledger.Plutus.Data (Data (..), unData)
341344
import Cardano.Ledger.Plutus.Language (Language, Plutus, languageToText, plutusBinary)
342-
import Cardano.Ledger.State (PoolMetadata (..), PoolParams (..), StakePoolRelay (..))
343345
import Cardano.Ledger.Shelley.API
344346
( ChainAccountState (..)
345347
, GenDelegPair (..)
@@ -348,7 +350,6 @@ import Cardano.Ledger.Shelley.API
348350
, WitVKey (..)
349351
, hashKey
350352
, hashVerKeyVRF
351-
, ChainAccountState (..)
352353
)
353354
import Cardano.Ledger.Shelley.Genesis
354355
( ShelleyGenesisStaking (..)
@@ -365,6 +366,7 @@ import Cardano.Ledger.Shelley.TxCert
365366
, ShelleyEraTxCert (..)
366367
, ShelleyTxCert (..)
367368
)
369+
import Cardano.Ledger.State (PoolMetadata (..), PoolParams (..), StakePoolRelay (..))
368370
import Cardano.Ledger.TxIn (TxId (..), TxIn (..))
369371
import Cardano.Protocol.Crypto (Crypto, StandardCrypto)
370372
import Cardano.Slotting.Slot (EpochNo (..))

cardano-api/src/Cardano/Api/Query/Internal/Type/QueryInMode.hs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -395,12 +395,12 @@ newtype PoolState era = PoolState L.QueryPoolStateResult
395395

396396
decodePoolState
397397
:: forall era
398-
. ()
399-
=> Core.Era (ShelleyLedgerEra era)
400-
=> SerialisedPoolState
398+
. ShelleyBasedEra era
399+
-> SerialisedPoolState
401400
-> Either DecoderError (PoolState era)
402-
decodePoolState (SerialisedPoolState (Serialised ls)) =
403-
PoolState <$> decodeFull (Core.eraProtVerLow @(ShelleyLedgerEra era)) ls
401+
decodePoolState sbe (SerialisedPoolState (Serialised ls)) =
402+
shelleyBasedEraConstraints sbe $
403+
PoolState <$> decodeFull (Core.eraProtVerLow @(ShelleyLedgerEra era)) ls
404404

405405
newtype SerialisedPoolDistribution era
406406
= SerialisedPoolDistribution

0 commit comments

Comments
 (0)