From 6ab422c7fcbc1011aa361d5e1a800e010d747c8e Mon Sep 17 00:00:00 2001 From: Franco Testagrossa Date: Mon, 14 Aug 2023 20:33:19 +0200 Subject: [PATCH 1/2] Improve show instance for SnapshotNumber This prevents the TUI to display UnsafeSnapshotNumber. --- hydra-node/src/Hydra/Snapshot.hs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/hydra-node/src/Hydra/Snapshot.hs b/hydra-node/src/Hydra/Snapshot.hs index 0ec9bce2e19..6af88331322 100644 --- a/hydra-node/src/Hydra/Snapshot.hs +++ b/hydra-node/src/Hydra/Snapshot.hs @@ -3,7 +3,7 @@ module Hydra.Snapshot where -import Hydra.Prelude +import Hydra.Prelude hiding (show) import Cardano.Crypto.Util (SignableRepresentation (..)) import Codec.Serialise (serialise) @@ -15,12 +15,19 @@ import Hydra.Ledger (IsTx (..)) import PlutusLedgerApi.V2 (toBuiltin, toData) import Test.QuickCheck (frequency, suchThat) import Test.QuickCheck.Instances.Natural () +import Text.Show (Show (..)) newtype SnapshotNumber = UnsafeSnapshotNumber Natural - deriving (Eq, Show, Ord, Generic) + deriving (Eq, Ord, Generic) deriving newtype (ToJSON, FromJSON, ToCBOR, FromCBOR, Real, Num, Enum, Integral) +instance Show SnapshotNumber where + show (UnsafeSnapshotNumber n) = show n + +instance Arbitrary SnapshotNumber where + arbitrary = UnsafeSnapshotNumber <$> arbitrary + data Snapshot tx = Snapshot { number :: SnapshotNumber , utxo :: UTxOType tx @@ -32,9 +39,6 @@ data Snapshot tx = Snapshot deriving instance IsTx tx => Eq (Snapshot tx) deriving instance IsTx tx => Show (Snapshot tx) -instance Arbitrary SnapshotNumber where - arbitrary = UnsafeSnapshotNumber <$> arbitrary - instance (Arbitrary (TxIdType tx), Arbitrary (UTxOType tx)) => Arbitrary (Snapshot tx) where arbitrary = genericArbitrary From d2dad6b63ec8d590c08198ba99d749933990dce2 Mon Sep 17 00:00:00 2001 From: Franco Testagrossa Date: Wed, 16 Aug 2023 09:31:08 +0200 Subject: [PATCH 2/2] improve by using a newtype deriving Show instead Co-authored-by: Sebastian Nagel --- hydra-node/src/Hydra/Snapshot.hs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/hydra-node/src/Hydra/Snapshot.hs b/hydra-node/src/Hydra/Snapshot.hs index 6af88331322..30d82869fb2 100644 --- a/hydra-node/src/Hydra/Snapshot.hs +++ b/hydra-node/src/Hydra/Snapshot.hs @@ -3,7 +3,7 @@ module Hydra.Snapshot where -import Hydra.Prelude hiding (show) +import Hydra.Prelude import Cardano.Crypto.Util (SignableRepresentation (..)) import Codec.Serialise (serialise) @@ -15,15 +15,11 @@ import Hydra.Ledger (IsTx (..)) import PlutusLedgerApi.V2 (toBuiltin, toData) import Test.QuickCheck (frequency, suchThat) import Test.QuickCheck.Instances.Natural () -import Text.Show (Show (..)) newtype SnapshotNumber = UnsafeSnapshotNumber Natural deriving (Eq, Ord, Generic) - deriving newtype (ToJSON, FromJSON, ToCBOR, FromCBOR, Real, Num, Enum, Integral) - -instance Show SnapshotNumber where - show (UnsafeSnapshotNumber n) = show n + deriving newtype (Show, ToJSON, FromJSON, ToCBOR, FromCBOR, Real, Num, Enum, Integral) instance Arbitrary SnapshotNumber where arbitrary = UnsafeSnapshotNumber <$> arbitrary