@@ -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 ( .. ) )
4242import Control.DeepSeq (NFData )
4343import Data.Aeson (FromJSON (.. ), ToJSON )
4444import Data.Maybe (fromMaybe )
@@ -76,7 +76,7 @@ type WithinBounds n a = (MinBound a <= n, n <= MaxBound a)
7676
7777newtype NonZero a = NonZero { unNonZero :: a }
7878 deriving (Eq , Ord , Show , NoThunks , NFData )
79- deriving newtype (EncCBOR , ToJSON )
79+ deriving newtype (EncCBOR , ToCBOR , ToJSON )
8080
8181class HasZero a where
8282 isZero :: a -> Bool
@@ -103,6 +103,9 @@ instance HasZero a => HasZero (Ratio a) where
103103instance (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+
106109instance (FromJSON a , HasZero a ) => FromJSON (NonZero a ) where
107110 parseJSON v = parseJSON v >>= nonZeroM
108111
0 commit comments