Skip to content

Commit

Permalink
Strengthen Eq instance for MemoBytes
Browse files Browse the repository at this point in the history
  • Loading branch information
lehins committed Nov 29, 2022
1 parent 57cd740 commit 338f4a8
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 11 deletions.
2 changes: 1 addition & 1 deletion eras/alonzo/impl/src/Cardano/Ledger/Alonzo/Data.hs
Expand Up @@ -389,7 +389,7 @@ instance (EraCrypto era ~ c) => HashAnnotated (AuxiliaryData era) EraIndependent

deriving newtype instance NFData (Script era) => NFData (AuxiliaryData era)

deriving instance Eq (AuxiliaryData era)
deriving instance Eq (Script era) => Eq (AuxiliaryData era)

deriving instance (Show (Script era), HashAlgorithm (HASH (EraCrypto era))) => Show (AuxiliaryData era)

Expand Down
4 changes: 3 additions & 1 deletion eras/alonzo/impl/src/Cardano/Ledger/Alonzo/TxBody.hs
Expand Up @@ -260,7 +260,9 @@ instance CC.Crypto c => AlonzoEraTxBody (AlonzoEra c) where
lensTxBodyRaw atbrTxNetworkId (\txBodyRaw networkId -> txBodyRaw {atbrTxNetworkId = networkId})
{-# INLINEABLE networkIdTxBodyL #-}

deriving newtype instance CC.Crypto (EraCrypto era) => Eq (AlonzoTxBody era)
deriving newtype instance
(Era era, Eq (Core.TxOut era), Eq (PParamsUpdate era), Eq (Value era), Compactible (Value era)) =>
Eq (AlonzoTxBody era)

deriving instance
(Era era, NoThunks (Core.TxOut era), NoThunks (PParamsUpdate era)) =>
Expand Down
6 changes: 5 additions & 1 deletion eras/alonzo/impl/src/Cardano/Ledger/Alonzo/TxWits.hs
Expand Up @@ -306,7 +306,11 @@ deriving stock instance

instance (Era era, NoThunks (Core.Script era)) => NoThunks (TxWitnessRaw era)

deriving newtype instance Eq (AlonzoTxWits era)
deriving newtype instance
( Era era,
Eq (Core.Script era)
) =>
Eq (AlonzoTxWits era)

deriving newtype instance
(Era era, Show (Core.Script era)) =>
Expand Down
4 changes: 3 additions & 1 deletion eras/babbage/impl/src/Cardano/Ledger/Babbage/TxBody.hs
Expand Up @@ -490,7 +490,9 @@ type TxBody era = BabbageTxBody era

{-# DEPRECATED TxBody "Use `BabbageTxBody` instead" #-}

deriving newtype instance CC.Crypto (EraCrypto era) => Eq (BabbageTxBody era)
deriving newtype instance
(Era era, Eq (Script era), Eq (PParamsUpdate era), Eq (CompactForm (Value era))) =>
Eq (BabbageTxBody era)

deriving instance (Era era, NoThunks (PParamsUpdate era)) => NoThunks (BabbageTxBody era)

Expand Down
Expand Up @@ -95,7 +95,7 @@ type instance MemoHashIndex AuxiliaryDataRaw = EraIndependentTxAuxData
instance (c ~ EraCrypto era) => HashAnnotated (AllegraTxAuxData era) EraIndependentTxAuxData c where
hashAnnotated (AuxiliaryDataWithBytes mb) = mbHash mb

deriving newtype instance Eq (AllegraTxAuxData era)
deriving newtype instance Eq (Script era) => Eq (AllegraTxAuxData era)

deriving newtype instance (Show (Script era), HashAlgorithm (HASH (EraCrypto era))) => Show (AllegraTxAuxData era)

Expand Down
4 changes: 3 additions & 1 deletion eras/shelley-ma/impl/src/Cardano/Ledger/ShelleyMA/TxBody.hs
Expand Up @@ -220,7 +220,9 @@ type TxBody era = MATxBody era

{-# DEPRECATED TxBody "Use `MATxBody` instead" #-}

deriving instance Eq (MATxBody era)
deriving instance
(Era era, Eq (PParamsUpdate era), Eq (Value era), Eq (CompactForm (Value era))) =>
Eq (MATxBody era)

deriving instance
(Era era, Show (Value era), Compactible (Value era), Show (PParamsUpdate era)) =>
Expand Down
8 changes: 7 additions & 1 deletion eras/shelley/impl/src/Cardano/Ledger/Shelley/Tx.hs
Expand Up @@ -224,7 +224,13 @@ deriving newtype instance
) =>
NFData (ShelleyTx era)

deriving newtype instance Eq (ShelleyTx era)
deriving newtype instance
( Era era,
Eq (Core.TxBody era),
Eq (TxWits era),
Eq (TxAuxData era)
) =>
Eq (ShelleyTx era)

deriving newtype instance
(Era era, Show (Core.TxBody era), Show (TxWits era), Show (TxAuxData era)) =>
Expand Down
2 changes: 1 addition & 1 deletion eras/shelley/impl/src/Cardano/Ledger/Shelley/TxBody.hs
Expand Up @@ -330,7 +330,7 @@ deriving newtype instance EraTxBody era => NFData (TxBody era)

deriving instance EraTxBody era => Show (TxBody era)

deriving instance Eq (TxBody era)
deriving instance (Era era, Eq (PParamsUpdate era), Eq (CompactForm (Value era))) => Eq (TxBody era)

deriving via Mem ShelleyTxBodyRaw era instance EraTxBody era => FromCBOR (Annotator (TxBody era))

Expand Down
6 changes: 3 additions & 3 deletions libs/cardano-ledger-core/src/Cardano/Ledger/MemoBytes.hs
Expand Up @@ -102,9 +102,9 @@ instance
(Annotator getT, Annotator getBytes) <- withSlice fromCBOR
pure (Annotator (\fullbytes -> mkMemoBytes (getT fullbytes) (getBytes fullbytes)))

-- | Binary representation is compared, rather than the Haskell type
instance Eq (MemoBytes t era) where
x == y = mbBytes x == mbBytes y
-- | Both binary representation and Haskell types are compared.
instance Eq (t era) => Eq (MemoBytes t era) where
x == y = mbBytes x == mbBytes y && mbType x == mbType y

instance (Show (t era), HashAlgorithm (HASH (EraCrypto era))) => Show (MemoBytes t era) where
show (Memo' y _ h) = show y <> " (" <> hashAlgorithmName (Proxy :: Proxy (HASH (EraCrypto era))) <> ": " <> show h <> ")"
Expand Down

0 comments on commit 338f4a8

Please sign in to comment.