Skip to content

Commit c11286c

Browse files
committed
Generalize the registerAny function.
1 parent 6d9c5d7 commit c11286c

File tree

1 file changed

+24
-9
lines changed
  • ouroboros-consensus-cardano/src/ouroboros-consensus-cardano/Ouroboros/Consensus/Cardano

1 file changed

+24
-9
lines changed

ouroboros-consensus-cardano/src/ouroboros-consensus-cardano/Ouroboros/Consensus/Cardano/Node.hs

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
{-# LANGUAGE TypeApplications #-}
1414
{-# LANGUAGE TypeFamilies #-}
1515
{-# LANGUAGE TypeOperators #-}
16+
{-# LANGUAGE UndecidableSuperClasses #-}
1617
{-# OPTIONS_GHC -Wno-orphans #-}
1718

1819
-- Disable completeness checks on GHC versions pre-9.6, where this can be
@@ -969,19 +970,20 @@ protocolInfoCardano paramsCardano
969970

970971
registerAny :: NP (LedgerState -.-> LedgerState) (CardanoShelleyEras c)
971972
registerAny =
972-
injectIntoTestState transitionConfigShelley
973-
:* injectIntoTestState transitionConfigAllegra
974-
:* injectIntoTestState transitionConfigMary
975-
:* injectIntoTestState transitionConfigAlonzo
976-
:* injectIntoTestState transitionConfigBabbage
977-
:* injectIntoTestState transitionConfigConway
978-
:* Nil
973+
hcmap (Proxy @IsShelleyBlock) injectIntoTestState $
974+
WrapTransitionConfig transitionConfigShelley
975+
:* WrapTransitionConfig transitionConfigAllegra
976+
:* WrapTransitionConfig transitionConfigMary
977+
:* WrapTransitionConfig transitionConfigAlonzo
978+
:* WrapTransitionConfig transitionConfigBabbage
979+
:* WrapTransitionConfig transitionConfigConway
980+
:* Nil
979981

980982
injectIntoTestState ::
981983
L.EraTransition era
982-
=> L.TransitionConfig era
984+
=> WrapTransitionConfig (ShelleyBlock proto era)
983985
-> (LedgerState -.-> LedgerState) (ShelleyBlock proto era)
984-
injectIntoTestState cfg = fn $ \st -> st {
986+
injectIntoTestState (WrapTransitionConfig cfg) = fn $ \st -> st {
985987
Shelley.shelleyLedgerState = L.injectIntoTestState cfg (Shelley.shelleyLedgerState st)
986988
}
987989

@@ -1110,3 +1112,16 @@ mkPartialLedgerConfigShelley transitionConfig maxMajorProtVer shelleyTriggerHard
11101112
maxMajorProtVer
11111113
, shelleyTriggerHardFork = shelleyTriggerHardFork
11121114
}
1115+
1116+
class
1117+
( ShelleyBasedEra (ShelleyBlockLedgerEra blk)
1118+
, blk ~ ShelleyBlock (BlockProtocol blk) (ShelleyBlockLedgerEra blk)
1119+
) => IsShelleyBlock blk
1120+
instance ShelleyBasedEra era => IsShelleyBlock (ShelleyBlock proto era)
1121+
1122+
type family ShelleyBlockLedgerEra blk where
1123+
ShelleyBlockLedgerEra (ShelleyBlock proto era) = era
1124+
1125+
-- | We need this wrapper to partially apply a 'TransitionConfig' in an NP.
1126+
newtype WrapTransitionConfig blk =
1127+
WrapTransitionConfig (L.TransitionConfig (ShelleyBlockLedgerEra blk))

0 commit comments

Comments
 (0)