Skip to content

Commit

Permalink
Improve show instance for SnapshotNumber
Browse files Browse the repository at this point in the history
This prevents the TUI to display UnsafeSnapshotNumber.
  • Loading branch information
ffakenz committed Aug 14, 2023
1 parent 5ca487f commit 6ab422c
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions hydra-node/src/Hydra/Snapshot.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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

Expand Down

0 comments on commit 6ab422c

Please sign in to comment.