Skip to content

Commit

Permalink
Introduce SomeProtocolVersion definition
Browse files Browse the repository at this point in the history
Jimbo4350 committed Dec 13, 2023
1 parent 86adc33 commit 1d8b171
Showing 4 changed files with 77 additions and 3 deletions.
1 change: 1 addition & 0 deletions cardano-api/cardano-api.cabal
Original file line number Diff line number Diff line change
@@ -118,6 +118,7 @@ library internal
Cardano.Api.OperationalCertificate
Cardano.Api.Pretty
Cardano.Api.Protocol
Cardano.Api.Protocol.Version
Cardano.Api.ProtocolParameters
Cardano.Api.Query
Cardano.Api.Query.Expr
63 changes: 63 additions & 0 deletions cardano-api/internal/Cardano/Api/Protocol/Version.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}



module Cardano.Api.Protocol.Version where

import Cardano.Api.Eon.ShelleyBasedEra
import qualified Cardano.Api.Eras.Core as Api
import Cardano.Api.Script
import Cardano.Api.TxBody

import qualified Data.Set as Set
import GHC.TypeLits

-- Users interacting with Cardano are likely only interested in using the latest
-- features available on mainnet and experimenting with the upcoming era as this becomes
-- available. Therefore we restrict the choices of protocol version to what is currently
-- on mainnet and what is in the upcoming era.

-- | Minimum supported version. Corresponds to Babbage era.
type MinSupportedVersion = 8 :: Nat

-- | Maximum supported version. Corresponds to Conway era.
type MaxSupportedVersion = 9 :: Nat

type BabbageEra = 8 :: Nat
type ConwayEra = 9 :: Nat

type SupportedProtocolVersionRange version =
( MinSupportedVersion <= version
, version <= MaxSupportedVersion
)

data SomeProtocolVersion version where
CurrentProtocolVersion
:: SupportedProtocolVersionRange BabbageEra
=> SomeProtocolVersion BabbageEra
ExperimentalProtocolVersion
:: SupportedProtocolVersionRange ConwayEra
=> SomeProtocolVersion ConwayEra


type family VersionToEra version where
VersionToEra BabbageEra = Api.BabbageEra
VersionToEra ConwayEra = Api.ConwayEra

protocolVersionToSbe
:: VersionToEra version ~ era
=> SomeProtocolVersion version
-> ShelleyBasedEra era
protocolVersionToSbe CurrentProtocolVersion = ShelleyBasedEraBabbage
protocolVersionToSbe ExperimentalProtocolVersion = ShelleyBasedEraConway

createSingleProtVerProxy
:: Proxy version -> SingleProtVer version
createSingleProtVerProxy _ = SingleProtVer
7 changes: 4 additions & 3 deletions cardano-api/internal/Cardano/Api/ReexposeLedger.hs
Original file line number Diff line number Diff line change
@@ -94,6 +94,7 @@ module Cardano.Api.ReexposeLedger
, urlToText
, textToUrl
, portToWord16
, ProtVer(..)
, strictMaybeToMaybe
, maybeToStrictMaybe

@@ -118,9 +119,9 @@ import Cardano.Ledger.Api.Tx.Cert (pattern AuthCommitteeHotKeyTxCert,
pattern ResignCommitteeColdTxCert, pattern RetirePoolTxCert,
pattern UnRegDRepTxCert, pattern UnRegDepositTxCert, pattern UnRegTxCert)
import Cardano.Ledger.Babbage.Core (CoinPerByte (..))
import Cardano.Ledger.BaseTypes (DnsName, Network (..), StrictMaybe (..), Url,
boundRational, dnsToText, maybeToStrictMaybe, portToWord16, strictMaybeToMaybe,
textToDns, textToUrl, unboundRational, urlToText)
import Cardano.Ledger.BaseTypes (DnsName, Network (..), ProtVer (..), StrictMaybe (..),
Url, boundRational, dnsToText, maybeToStrictMaybe, portToWord16,
strictMaybeToMaybe, textToDns, textToUrl, unboundRational, urlToText)
import Cardano.Ledger.Binary (Annotated (..))
import Cardano.Ledger.CertState (DRepState, csCommitteeCredsL)
import Cardano.Ledger.Coin (Coin (..), addDeltaCoin, toDeltaCoin)
9 changes: 9 additions & 0 deletions cardano-api/internal/Cardano/Api/TxBody.hs
Original file line number Diff line number Diff line change
@@ -152,6 +152,15 @@ module Cardano.Api.TxBody (
AsType(AsTxId, AsTxBody, AsByronTxBody, AsShelleyTxBody, AsMaryTxBody),

getTxBodyContent,

-- Temp
validateTxIns,
guardShelleyTxInsOverflow,
validateTxOuts,
validateMetadata,
validateMintValue,
validateTxInsCollateral,
validateProtocolParameters,
) where

import Cardano.Api.Address

0 comments on commit 1d8b171

Please sign in to comment.