Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve RecentEra docs #4296

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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