Skip to content

Commit 784f977

Browse files
committed
Generalize the registerAny function.
1 parent 46175dd commit 784f977

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
@@ -953,19 +954,20 @@ protocolInfoCardano paramsCardano
953954

954955
registerAny :: NP (LedgerState -.-> LedgerState) (CardanoShelleyEras c)
955956
registerAny =
956-
injectIntoTestState transitionConfigShelley
957-
:* injectIntoTestState transitionConfigAllegra
958-
:* injectIntoTestState transitionConfigMary
959-
:* injectIntoTestState transitionConfigAlonzo
960-
:* injectIntoTestState transitionConfigBabbage
961-
:* injectIntoTestState transitionConfigConway
962-
:* Nil
957+
hcmap (Proxy @IsShelleyBlock) injectIntoTestState $
958+
WrapTransitionConfig transitionConfigShelley
959+
:* WrapTransitionConfig transitionConfigAllegra
960+
:* WrapTransitionConfig transitionConfigMary
961+
:* WrapTransitionConfig transitionConfigAlonzo
962+
:* WrapTransitionConfig transitionConfigBabbage
963+
:* WrapTransitionConfig transitionConfigConway
964+
:* Nil
963965

964966
injectIntoTestState ::
965967
L.EraTransition era
966-
=> L.TransitionConfig era
968+
=> WrapTransitionConfig (ShelleyBlock proto era)
967969
-> (LedgerState -.-> LedgerState) (ShelleyBlock proto era)
968-
injectIntoTestState cfg = fn $ \st -> st {
970+
injectIntoTestState (WrapTransitionConfig cfg) = fn $ \st -> st {
969971
Shelley.shelleyLedgerState = L.injectIntoTestState cfg (Shelley.shelleyLedgerState st)
970972
}
971973

@@ -1094,3 +1096,16 @@ mkPartialLedgerConfigShelley transitionConfig maxMajorProtVer shelleyTriggerHard
10941096
maxMajorProtVer
10951097
, shelleyTriggerHardFork = shelleyTriggerHardFork
10961098
}
1099+
1100+
class
1101+
( ShelleyBasedEra (ShelleyBlockLedgerEra blk)
1102+
, blk ~ ShelleyBlock (BlockProtocol blk) (ShelleyBlockLedgerEra blk)
1103+
) => IsShelleyBlock blk
1104+
instance ShelleyBasedEra era => IsShelleyBlock (ShelleyBlock proto era)
1105+
1106+
type family ShelleyBlockLedgerEra blk where
1107+
ShelleyBlockLedgerEra (ShelleyBlock proto era) = era
1108+
1109+
-- | We need this wrapper to partially apply a 'TransitionConfig' in an NP.
1110+
newtype WrapTransitionConfig blk =
1111+
WrapTransitionConfig (L.TransitionConfig (ShelleyBlockLedgerEra blk))

0 commit comments

Comments
 (0)