Skip to content

Commit

Permalink
Implement UseProtocolVersion class and demonstate an alternative class
Browse files Browse the repository at this point in the history
interface that could be expose side by side
  • Loading branch information
Jimbo4350 committed Dec 15, 2023
1 parent 1804be9 commit 46f2eaf
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions cardano-api/internal/Cardano/Api/Protocol/Version.hs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilyDependencies #-}
{-# LANGUAGE TypeOperators #-}

Expand Down Expand Up @@ -128,3 +130,27 @@ example p' txins =
case p' of
CurrentProtocolVersion -> futureValidateTxIns p' txins
UpcomingProtocolVersion -> pure ()

-------------------------------------------------------------------------

-- We also want to expose a class interface to users

class UseProtocolVerion (version :: Nat) where
getProtocolVersion :: SomeProtocolVersion version

instance UseProtocolVerion BabbageEra where
getProtocolVersion = CurrentProtocolVersion

instance UseProtocolVerion ConwayEra where
getProtocolVersion = UpcomingProtocolVersion

-- For the wallet team. Exposing a class interface side by side should be easy.
classExample
:: UseProtocolVerion version
=> [(TxIn, BuildTxWith BuildTx (UpdatedWitness version))]
-> Either TxBodyError ()
classExample = example getProtocolVersion


classExampleUsage :: Either TxBodyError ()
classExampleUsage = classExample @BabbageEra []

0 comments on commit 46f2eaf

Please sign in to comment.