diff --git a/shelley/chain-and-ledger/executable-spec/src/Cardano/Ledger/API/Mempool.hs b/shelley/chain-and-ledger/executable-spec/src/Cardano/Ledger/API/Mempool.hs index 2a33ccac29b..ad8f4cc2fd7 100644 --- a/shelley/chain-and-ledger/executable-spec/src/Cardano/Ledger/API/Mempool.hs +++ b/shelley/chain-and-ledger/executable-spec/src/Cardano/Ledger/API/Mempool.hs @@ -17,8 +17,9 @@ module Cardano.Ledger.API.Mempool ) where -import Cardano.Binary (Annotator, FromCBOR (..), ToCBOR (..)) +import Cardano.Binary (FromCBOR (..), ToCBOR (..)) import Cardano.Crypto.Hash (Hash) +import Cardano.Ledger.Core (AnnotatedData, SerialisableData, ChainData) import Cardano.Ledger.Crypto (Crypto, HASH) import Cardano.Ledger.Shelley (ShelleyBased, ShelleyEra) import Control.Arrow (left) @@ -32,7 +33,6 @@ import Control.State.Transition.Extended ) import Data.Sequence (Seq) import Data.Typeable (Typeable) -import NoThunks.Class (NoThunks) import Shelley.Spec.Ledger.BaseTypes (Globals) import Shelley.Spec.Ledger.Keys (DSignable) import Shelley.Spec.Ledger.LedgerState (NewEpochState) @@ -45,16 +45,12 @@ import Shelley.Spec.Ledger.TxBody (EraIndependentTxBody) -- TODO #1304: add reapplyTxs class - ( Eq (Tx era), - Show (Tx era), - NoThunks (Tx era), - FromCBOR (Annotator (Tx era)), - ToCBOR (Tx era), + ( ChainData (Tx era), + AnnotatedData (Tx era), Eq (ApplyTxError era), Show (ApplyTxError era), - FromCBOR (ApplyTxError era), - ToCBOR (ApplyTxError era), - Typeable (ApplyTxError era) + Typeable (ApplyTxError era), + SerialisableData (ApplyTxError era) ) => ApplyTx era where diff --git a/shelley/chain-and-ledger/executable-spec/src/Cardano/Ledger/API/Protocol.hs b/shelley/chain-and-ledger/executable-spec/src/Cardano/Ledger/API/Protocol.hs index 9cd6ad00067..fbe25bbb789 100644 --- a/shelley/chain-and-ledger/executable-spec/src/Cardano/Ledger/API/Protocol.hs +++ b/shelley/chain-and-ledger/executable-spec/src/Cardano/Ledger/API/Protocol.hs @@ -30,6 +30,7 @@ module Cardano.Ledger.API.Protocol where import Cardano.Binary (FromCBOR (..), ToCBOR (..), encodeListLen) +import Cardano.Ledger.Core (SerialisableData, ChainData) import qualified Cardano.Ledger.Crypto as CC (Crypto) import Cardano.Ledger.Era (Crypto) import Cardano.Ledger.Shelley (ShelleyBased, ShelleyEra) @@ -77,9 +78,8 @@ import Shelley.Spec.Ledger.Serialization (decodeRecordNamed) import Shelley.Spec.Ledger.Slot (SlotNo) class - ( Eq (ChainDepState (Crypto era)), - Show (ChainDepState (Crypto era)), - NoThunks (ChainDepState (Crypto era)), + ( ChainData (ChainDepState (Crypto era)), + SerialisableData (ChainDepState (Crypto era)), Eq (ChainTransitionError (Crypto era)), Show (ChainTransitionError (Crypto era)), Show (LedgerView (Crypto era)), diff --git a/shelley/chain-and-ledger/executable-spec/src/Cardano/Ledger/API/Validation.hs b/shelley/chain-and-ledger/executable-spec/src/Cardano/Ledger/API/Validation.hs index edb48e55531..5356490e631 100644 --- a/shelley/chain-and-ledger/executable-spec/src/Cardano/Ledger/API/Validation.hs +++ b/shelley/chain-and-ledger/executable-spec/src/Cardano/Ledger/API/Validation.hs @@ -19,8 +19,8 @@ module Cardano.Ledger.API.Validation ) where -import Cardano.Binary (Annotator, FromCBOR (..), ToCBOR (..)) import Cardano.Crypto.Hash (Hash) +import Cardano.Ledger.Core (ChainData, SerialisableData, AnnotatedData) import Cardano.Ledger.Crypto (HASH) import qualified Cardano.Ledger.Crypto as CC (Crypto) import Cardano.Ledger.Era (Crypto, Era) @@ -47,27 +47,14 @@ import Shelley.Spec.Ledger.TxBody (EraIndependentTxBody) -------------------------------------------------------------------------------} class - ( Eq (Block era), - Show (Block era), - NoThunks (Block era), - FromCBOR (Annotator (Block era)), - ToCBOR (Block era), - Eq (BHeader (Crypto era)), - Show (BHeader (Crypto era)), - NoThunks (BHeader (Crypto era)), - FromCBOR (Annotator (BHeader (Crypto era))), - ToCBOR (Block era), - Eq (NewEpochState era), - Show (NewEpochState era), - NoThunks (NewEpochState era), - FromCBOR (NewEpochState era), - ToCBOR (NewEpochState era), - Eq (BlockTransitionError era), - Show (BlockTransitionError era), - NoThunks (BlockTransitionError era), - Eq (STS.PredicateFailure (STS.CHAIN era)), - Show (STS.PredicateFailure (STS.CHAIN era)), - NoThunks (STS.PredicateFailure (STS.CHAIN era)) + ( ChainData (Block era), + AnnotatedData (Block era), + ChainData (BHeader (Crypto era)), + AnnotatedData (BHeader (Crypto era)), + ChainData (NewEpochState era), + SerialisableData (NewEpochState era), + ChainData (BlockTransitionError era), + ChainData (STS.PredicateFailure (STS.CHAIN era)) ) => ApplyBlock era where diff --git a/shelley/chain-and-ledger/executable-spec/src/Cardano/Ledger/Core.hs b/shelley/chain-and-ledger/executable-spec/src/Cardano/Ledger/Core.hs index 2e1cd7211d2..a8d8c269ae1 100644 --- a/shelley/chain-and-ledger/executable-spec/src/Cardano/Ledger/Core.hs +++ b/shelley/chain-and-ledger/executable-spec/src/Cardano/Ledger/Core.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE TypeFamilies #-} @@ -16,12 +17,17 @@ module Cardano.Ledger.Core Compact (..), TxBody, Value, + -- * Constraint synonyms + ChainData, + SerialisableData, + AnnotatedData, ) where -import Cardano.Binary (FromCBOR (..), ToCBOR (..)) +import Cardano.Binary (FromCBOR (..), ToCBOR (..), Annotator) import Data.Kind (Type) import Data.Typeable (Typeable) +import NoThunks.Class (NoThunks) -- | A value is something which quantifies a transaction output. type family Value era :: Type @@ -61,3 +67,19 @@ instance -- TODO: consider if this is better the other way around instance (Eq a, Compactible a) => Eq (CompactForm a) where a == b = fromCompact a == fromCompact b + +------------------------------------------------------------------------------- +-- * Constraint synonyms +------------------------------------------------------------------------------- + +-- | Common constraints +-- +-- NOTE: 'Ord' is not included, as 'Ord' for a 'Block' or a 'NewEpochState' +-- doesn't make sense. +type ChainData t = (Eq t, Show t, NoThunks t, Typeable t) + +-- | Constraints for serialising from/to CBOR +type SerialisableData t = (FromCBOR t, ToCBOR t) + +-- | Constraints for serialising from/to CBOR using 'Annotator' +type AnnotatedData t = (FromCBOR (Annotator t), ToCBOR t)