Skip to content

Commit a3ab599

Browse files
committed
Add required CBOR instances for NonZero
1 parent 94ac263 commit a3ab599

File tree

1 file changed

+5
-2
lines changed
  • libs/cardano-ledger-core/src/Cardano/Ledger/BaseTypes

1 file changed

+5
-2
lines changed

libs/cardano-ledger-core/src/Cardano/Ledger/BaseTypes/NonZero.hs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ module Cardano.Ledger.BaseTypes.NonZero (
3838
(%?),
3939
) where
4040

41-
import Cardano.Ledger.Binary (DecCBOR (..), EncCBOR)
41+
import Cardano.Ledger.Binary (DecCBOR (..), EncCBOR, FromCBOR (..), ToCBOR (..))
4242
import Control.DeepSeq (NFData)
4343
import Data.Aeson (FromJSON (..), ToJSON)
4444
import Data.Maybe (fromMaybe)
@@ -76,7 +76,7 @@ type WithinBounds n a = (MinBound a <= n, n <= MaxBound a)
7676

7777
newtype NonZero a = NonZero {unNonZero :: a}
7878
deriving (Eq, Ord, Show, NoThunks, NFData)
79-
deriving newtype (EncCBOR, ToJSON)
79+
deriving newtype (EncCBOR, ToCBOR, ToJSON)
8080

8181
class HasZero a where
8282
isZero :: a -> Bool
@@ -103,6 +103,9 @@ instance HasZero a => HasZero (Ratio a) where
103103
instance (Typeable a, DecCBOR a, HasZero a) => DecCBOR (NonZero a) where
104104
decCBOR = decCBOR >>= nonZeroM
105105

106+
instance (HasZero a, FromCBOR a) => FromCBOR (NonZero a) where
107+
fromCBOR = nonZeroM =<< fromCBOR
108+
106109
instance (FromJSON a, HasZero a) => FromJSON (NonZero a) where
107110
parseJSON v = parseJSON v >>= nonZeroM
108111

0 commit comments

Comments
 (0)