Skip to content

Commit

Permalink
Improve RecentEra docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Anviking committed Dec 4, 2023
1 parent ac7576e commit 54a5602
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions lib/balance-tx/lib/internal/Internal/Cardano/Write/Tx.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE EmptyCase #-}
Expand Down Expand Up @@ -291,16 +290,39 @@ type LatestLedgerEra = StandardConway
-- RecentEra
--------------------------------------------------------------------------------

-- | 'RecentEra' respresents the eras we care about constructing transactions
-- for.
-- | We define the term "recent era" to mean one of the /two most recent eras/.
-- This represents eras we care constructing transactions for.
--
-- === Why /two/ eras?
--
-- To have the same software constructing transactions just before and just
-- after a hard-fork, we need to, at that time, support the two latest eras. We
-- could get away with just supporting one era at other times, but for
-- simplicity we stick with always supporting the two latest eras for now.
-- after a hard-fork, we need to, for a time, support two eras.
--
-- === 'RecentEra' the value value vs 'IsRecentEra' the class
--
-- DO:
--
-- @@
-- myTx :: IsRecentEra era => Tx era
-- signByAlice :: IsRecentEra era => Tx era -> Tx era
-- renderCliTx :: IsRecentEra era -> Tx era -> Text
-- myCardanoApiTx :: IsRecentEra era -> RecentEra -> CardanoApi.Tx (CardanoApiEra era)
-- @@
--
-- DON'T:
--
-- @@
-- signByAlice :: RecentEra era -> Tx era -> Tx era
--
-- -- 'RecentEra era' adds boilerplate without improving type inference
-- signByAlice :: IsRecentEra era => RecentEra era -> Tx era -> Tx era
--
-- -- Will always require '@era' type application to disambiguate the type when
-- called:
-- myCardanoApiTx :: IsRecentEra era => CardanoApi.Tx (CardanoApiEra era)
-- @@
--
--
-- NOTE: We /could/ let 'era' refer to eras from the ledger rather than from
-- cardano-api.
data RecentEra era where
RecentEraBabbage :: RecentEra BabbageEra
RecentEraConway :: RecentEra ConwayEra
Expand All @@ -314,6 +336,7 @@ instance TestEquality RecentEra where
testEquality RecentEraBabbage RecentEraConway = Nothing
testEquality RecentEraConway RecentEraBabbage = Nothing

-- | C.f. 'RecentEra'
class
( CardanoApi.IsShelleyBasedEra (CardanoApiEra era)
, CardanoApi.ShelleyLedgerEra (CardanoApiEra era) ~ era
Expand Down

0 comments on commit 54a5602

Please sign in to comment.