{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP #-}
{-# LANGUAGE DefaultSignatures #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE NoStarIsType #-}
module Cardano.Ledger.Binary.Decoding.DecCBOR (
DecCBOR (..),
fromByronCBOR,
decodeScriptContextFromData,
)
where
import qualified Cardano.Binary as Plain (Decoder, FromCBOR (..))
import Cardano.Crypto.DSIGN.Class (
DSIGNAlgorithm,
SigDSIGN,
SignKeyDSIGN,
SignedDSIGN,
VerKeyDSIGN,
)
import Cardano.Crypto.Hash.Class (Hash, HashAlgorithm)
import Cardano.Crypto.KES.Class (KESAlgorithm, SigKES, VerKeyKES)
import Cardano.Crypto.VRF.Class (
CertVRF,
CertifiedVRF (..),
OutputVRF (..),
SignKeyVRF,
VRFAlgorithm,
VerKeyVRF,
)
import Cardano.Crypto.VRF.Mock (MockVRF)
import qualified Cardano.Crypto.VRF.Praos as Praos
import Cardano.Crypto.VRF.Simple (SimpleVRF)
import Cardano.Ledger.Binary.Crypto
import Cardano.Ledger.Binary.Decoding.Decoder
import Cardano.Ledger.Binary.Version (Version, byronProtVer)
import Cardano.Slotting.Block (BlockNo (..))
import Cardano.Slotting.Slot (
EpochInterval (..),
EpochNo (..),
EpochSize (..),
SlotNo (..),
WithOrigin (..),
)
import Cardano.Slotting.Time (SystemStart (..))
import Codec.CBOR.ByteArray (ByteArray (..))
import Codec.CBOR.ByteArray.Sliced (SlicedByteArray, fromByteArray)
import Codec.CBOR.Term (Term (..))
import Codec.Serialise as Serialise (Serialise (decode))
import qualified Data.ByteString as BS
import qualified Data.ByteString.Lazy as BSL
#if MIN_VERSION_bytestring(0,11,1)
import Data.ByteString.Short (ShortByteString(SBS))
#else
import Data.ByteString.Short.Internal (ShortByteString(SBS))
#endif
import Data.Fixed (Fixed (..))
import Data.IP (IPv4, IPv6)
import Data.Int (Int16, Int32, Int64, Int8)
import Data.List.NonEmpty (NonEmpty)
import qualified Data.Map.Strict as Map
import qualified Data.Maybe.Strict as SMaybe
import qualified Data.Primitive.ByteArray as Prim
import qualified Data.Sequence as Seq
import qualified Data.Sequence.Strict as SSeq
import qualified Data.Set as Set
import Data.Tagged (Tagged (Tagged))
import qualified Data.Text as T
import Data.Time.Clock (UTCTime (..))
import Data.Typeable (Proxy (..), Typeable, typeRep)
import qualified Data.VMap as VMap
import qualified Data.Vector as V
import qualified Data.Vector.Primitive as VP
import qualified Data.Vector.Storable as VS
import qualified Data.Vector.Unboxed as VU
import Data.Void (Void)
import Data.Word (Word16, Word32, Word64, Word8)
import Numeric.Natural (Natural)
import qualified PlutusLedgerApi.V1 as PV1
import qualified PlutusLedgerApi.V2 as PV2
import qualified PlutusLedgerApi.V3 as PV3
import Prelude hiding (decodeFloat)
class Typeable a => DecCBOR a where
decCBOR :: Decoder s a
default decCBOR :: Plain.FromCBOR a => Decoder s a
decCBOR = forall s a. Decoder s a -> Decoder s a
fromPlainDecoder forall a s. FromCBOR a => Decoder s a
Plain.fromCBOR
{-# INLINE decCBOR #-}
dropCBOR :: Proxy a -> Decoder s ()
dropCBOR Proxy a
_ = () forall (f :: Type -> Type) a b. Functor f => a -> f b -> f a
<$ forall a s. DecCBOR a => Decoder s a
decCBOR @a
label :: Proxy a -> T.Text
label = String -> Text
T.pack forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Show a => a -> String
show forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall {k} (proxy :: k -> Type) (a :: k).
Typeable a =>
proxy a -> TypeRep
typeRep
instance DecCBOR Version where
decCBOR :: forall s. Decoder s Version
decCBOR = forall s. Decoder s Version
decodeVersion
{-# INLINE decCBOR #-}
fromByronCBOR :: DecCBOR a => Plain.Decoder s a
fromByronCBOR :: forall a s. DecCBOR a => Decoder s a
fromByronCBOR = forall s a.
Maybe ByteString -> Version -> Decoder s a -> Decoder s a
toPlainDecoder forall a. Maybe a
Nothing Version
byronProtVer forall a s. DecCBOR a => Decoder s a
decCBOR
{-# INLINE fromByronCBOR #-}
instance DecCBOR () where
decCBOR :: forall s. Decoder s ()
decCBOR = forall s. Decoder s ()
decodeNull
{-# INLINE decCBOR #-}
instance DecCBOR Bool where
decCBOR :: forall s. Decoder s Bool
decCBOR = forall s. Decoder s Bool
decodeBool
{-# INLINE decCBOR #-}
instance DecCBOR Integer where
decCBOR :: forall s. Decoder s Integer
decCBOR = forall s. Decoder s Integer
decodeInteger
{-# INLINE decCBOR #-}
instance DecCBOR Natural where
decCBOR :: forall s. Decoder s Natural
decCBOR = forall s. Decoder s Natural
decodeNatural
{-# INLINE decCBOR #-}
instance DecCBOR Word where
decCBOR :: forall s. Decoder s Word
decCBOR = forall s. Decoder s Word
decodeWord
{-# INLINE decCBOR #-}
instance DecCBOR Word8 where
decCBOR :: forall s. Decoder s Word8
decCBOR = forall s. Decoder s Word8
decodeWord8
{-# INLINE decCBOR #-}
instance DecCBOR Word16 where
decCBOR :: forall s. Decoder s Word16
decCBOR = forall s. Decoder s Word16
decodeWord16
{-# INLINE decCBOR #-}
instance DecCBOR Word32 where
decCBOR :: forall s. Decoder s Word32
decCBOR = forall s. Decoder s Word32
decodeWord32
{-# INLINE decCBOR #-}
instance DecCBOR Word64 where
decCBOR :: forall s. Decoder s Word64
decCBOR = forall s. Decoder s Word64
decodeWord64
{-# INLINE decCBOR #-}
instance DecCBOR Int where
decCBOR :: forall s. Decoder s Int
decCBOR = forall s. Decoder s Int
decodeInt
{-# INLINE decCBOR #-}
instance DecCBOR Int8 where
decCBOR :: forall s. Decoder s Int8
decCBOR = forall s. Decoder s Int8
decodeInt8
{-# INLINE decCBOR #-}
instance DecCBOR Int16 where
decCBOR :: forall s. Decoder s Int16
decCBOR = forall s. Decoder s Int16
decodeInt16
{-# INLINE decCBOR #-}
instance DecCBOR Int32 where
decCBOR :: forall s. Decoder s Int32
decCBOR = forall s. Decoder s Int32
decodeInt32
{-# INLINE decCBOR #-}
instance DecCBOR Int64 where
decCBOR :: forall s. Decoder s Int64
decCBOR = forall s. Decoder s Int64
decodeInt64
{-# INLINE decCBOR #-}
instance DecCBOR Float where
decCBOR :: forall s. Decoder s Float
decCBOR = forall s. Decoder s Float
decodeFloat
{-# INLINE decCBOR #-}
instance DecCBOR Double where
decCBOR :: forall s. Decoder s Double
decCBOR = forall s. Decoder s Double
decodeDouble
{-# INLINE decCBOR #-}
instance DecCBOR Rational where
decCBOR :: forall s. Decoder s Rational
decCBOR = forall s. Decoder s Rational
decodeRational
{-# INLINE decCBOR #-}
deriving newtype instance Typeable p => DecCBOR (Fixed p)
instance DecCBOR Void where
decCBOR :: forall s. Decoder s Void
decCBOR = forall (m :: Type -> Type) e a.
(MonadFail m, Buildable e) =>
e -> m a
cborError DecoderError
DecoderErrorVoid
instance DecCBOR Term where
decCBOR :: forall s. Decoder s Term
decCBOR = forall s. Decoder s Term
decodeTerm
{-# INLINE decCBOR #-}
instance DecCBOR IPv4 where
decCBOR :: forall s. Decoder s IPv4
decCBOR = forall s. Decoder s IPv4
decodeIPv4
{-# INLINE decCBOR #-}
instance DecCBOR IPv6 where
decCBOR :: forall s. Decoder s IPv6
decCBOR = forall s. Decoder s IPv6
decodeIPv6
{-# INLINE decCBOR #-}
instance (Typeable s, DecCBOR a) => DecCBOR (Tagged s a) where
decCBOR :: forall s. Decoder s (Tagged s a)
decCBOR = forall {k} (s :: k) b. b -> Tagged s b
Tagged forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a s. DecCBOR a => Decoder s a
decCBOR
{-# INLINE decCBOR #-}
dropCBOR :: forall s. Proxy (Tagged s a) -> Decoder s ()
dropCBOR Proxy (Tagged s a)
_ = forall a s. DecCBOR a => Proxy a -> Decoder s ()
dropCBOR (forall {k} (t :: k). Proxy t
Proxy @a)
instance (DecCBOR a, DecCBOR b) => DecCBOR (a, b) where
decCBOR :: forall s. Decoder s (a, b)
decCBOR = do
forall s. Int -> Decoder s ()
decodeListLenOf Int
2
!a
x <- forall a s. DecCBOR a => Decoder s a
decCBOR
!b
y <- forall a s. DecCBOR a => Decoder s a
decCBOR
forall (m :: Type -> Type) a. Monad m => a -> m a
return (a
x, b
y)
dropCBOR :: forall s. Proxy (a, b) -> Decoder s ()
dropCBOR Proxy (a, b)
_ = forall s. Int -> Decoder s ()
decodeListLenOf Int
2 forall (f :: Type -> Type) a b. Applicative f => f a -> f b -> f a
<* forall a s. DecCBOR a => Proxy a -> Decoder s ()
dropCBOR (forall {k} (t :: k). Proxy t
Proxy @a) forall (f :: Type -> Type) a b. Applicative f => f a -> f b -> f a
<* forall a s. DecCBOR a => Proxy a -> Decoder s ()
dropCBOR (forall {k} (t :: k). Proxy t
Proxy @b)
{-# INLINE decCBOR #-}
instance (DecCBOR a, DecCBOR b, DecCBOR c) => DecCBOR (a, b, c) where
decCBOR :: forall s. Decoder s (a, b, c)
decCBOR = do
forall s. Int -> Decoder s ()
decodeListLenOf Int
3
!a
x <- forall a s. DecCBOR a => Decoder s a
decCBOR
!b
y <- forall a s. DecCBOR a => Decoder s a
decCBOR
!c
z <- forall a s. DecCBOR a => Decoder s a
decCBOR
forall (m :: Type -> Type) a. Monad m => a -> m a
return (a
x, b
y, c
z)
dropCBOR :: forall s. Proxy (a, b, c) -> Decoder s ()
dropCBOR Proxy (a, b, c)
_ =
forall s. Int -> Decoder s ()
decodeListLenOf Int
3
forall (f :: Type -> Type) a b. Applicative f => f a -> f b -> f a
<* forall a s. DecCBOR a => Proxy a -> Decoder s ()
dropCBOR (forall {k} (t :: k). Proxy t
Proxy @a)
forall (f :: Type -> Type) a b. Applicative f => f a -> f b -> f a
<* forall a s. DecCBOR a => Proxy a -> Decoder s ()
dropCBOR (forall {k} (t :: k). Proxy t
Proxy @b)
forall (f :: Type -> Type) a b. Applicative f => f a -> f b -> f a
<* forall a s. DecCBOR a => Proxy a -> Decoder s ()
dropCBOR (forall {k} (t :: k). Proxy t
Proxy @c)
{-# INLINE decCBOR #-}
instance (DecCBOR a, DecCBOR b, DecCBOR c, DecCBOR d) => DecCBOR (a, b, c, d) where
decCBOR :: forall s. Decoder s (a, b, c, d)
decCBOR = do
forall s. Int -> Decoder s ()
decodeListLenOf Int
4
!a
a <- forall a s. DecCBOR a => Decoder s a
decCBOR
!b
b <- forall a s. DecCBOR a => Decoder s a
decCBOR
!c
c <- forall a s. DecCBOR a => Decoder s a
decCBOR
!d
d <- forall a s. DecCBOR a => Decoder s a
decCBOR
forall (m :: Type -> Type) a. Monad m => a -> m a
return (a
a, b
b, c
c, d
d)
dropCBOR :: forall s. Proxy (a, b, c, d) -> Decoder s ()
dropCBOR Proxy (a, b, c, d)
_ =
forall s. Int -> Decoder s ()
decodeListLenOf Int
4
forall (f :: Type -> Type) a b. Applicative f => f a -> f b -> f a
<* forall a s. DecCBOR a => Proxy a -> Decoder s ()
dropCBOR (forall {k} (t :: k). Proxy t
Proxy @a)
forall (f :: Type -> Type) a b. Applicative f => f a -> f b -> f a
<* forall a s. DecCBOR a => Proxy a -> Decoder s ()
dropCBOR (forall {k} (t :: k). Proxy t
Proxy @b)
forall (f :: Type -> Type) a b. Applicative f => f a -> f b -> f a
<* forall a s. DecCBOR a => Proxy a -> Decoder s ()
dropCBOR (forall {k} (t :: k). Proxy t
Proxy @c)
forall (f :: Type -> Type) a b. Applicative f => f a -> f b -> f a
<* forall a s. DecCBOR a => Proxy a -> Decoder s ()
dropCBOR (forall {k} (t :: k). Proxy t
Proxy @d)
{-# INLINE decCBOR #-}
instance
(DecCBOR a, DecCBOR b, DecCBOR c, DecCBOR d, DecCBOR e) =>
DecCBOR (a, b, c, d, e)
where
decCBOR :: forall s. Decoder s (a, b, c, d, e)
decCBOR = do
forall s. Int -> Decoder s ()
decodeListLenOf Int
5
!a
a <- forall a s. DecCBOR a => Decoder s a
decCBOR
!b
b <- forall a s. DecCBOR a => Decoder s a
decCBOR
!c
c <- forall a s. DecCBOR a => Decoder s a
decCBOR
!d
d <- forall a s. DecCBOR a => Decoder s a
decCBOR
!e
e <- forall a s. DecCBOR a => Decoder s a
decCBOR
forall (m :: Type -> Type) a. Monad m => a -> m a
return (a
a, b
b, c
c, d
d, e
e)
dropCBOR :: forall s. Proxy (a, b, c, d, e) -> Decoder s ()
dropCBOR Proxy (a, b, c, d, e)
_ =
forall s. Int -> Decoder s ()
decodeListLenOf Int
5
forall (f :: Type -> Type) a b. Applicative f => f a -> f b -> f a
<* forall a s. DecCBOR a => Proxy a -> Decoder s ()
dropCBOR (forall {k} (t :: k). Proxy t
Proxy @a)
forall (f :: Type -> Type) a b. Applicative f => f a -> f b -> f a
<* forall a s. DecCBOR a => Proxy a -> Decoder s ()
dropCBOR (forall {k} (t :: k). Proxy t
Proxy @b)
forall (f :: Type -> Type) a b. Applicative f => f a -> f b -> f a
<* forall a s. DecCBOR a => Proxy a -> Decoder s ()
dropCBOR (forall {k} (t :: k). Proxy t
Proxy @c)
forall (f :: Type -> Type) a b. Applicative f => f a -> f b -> f a
<* forall a s. DecCBOR a => Proxy a -> Decoder s ()
dropCBOR (forall {k} (t :: k). Proxy t
Proxy @d)
forall (f :: Type -> Type) a b. Applicative f => f a -> f b -> f a
<* forall a s. DecCBOR a => Proxy a -> Decoder s ()
dropCBOR (forall {k} (t :: k). Proxy t
Proxy @e)
{-# INLINE decCBOR #-}
instance
(DecCBOR a, DecCBOR b, DecCBOR c, DecCBOR d, DecCBOR e, DecCBOR f) =>
DecCBOR (a, b, c, d, e, f)
where
decCBOR :: forall s. Decoder s (a, b, c, d, e, f)
decCBOR = do
forall s. Int -> Decoder s ()
decodeListLenOf Int
6
!a
a <- forall a s. DecCBOR a => Decoder s a
decCBOR
!b
b <- forall a s. DecCBOR a => Decoder s a
decCBOR
!c
c <- forall a s. DecCBOR a => Decoder s a
decCBOR
!d
d <- forall a s. DecCBOR a => Decoder s a
decCBOR
!e
e <- forall a s. DecCBOR a => Decoder s a
decCBOR
!f
f <- forall a s. DecCBOR a => Decoder s a
decCBOR
forall (m :: Type -> Type) a. Monad m => a -> m a
return (a
a, b
b, c
c, d
d, e
e, f
f)
dropCBOR :: forall s. Proxy (a, b, c, d, e, f) -> Decoder s ()
dropCBOR Proxy (a, b, c, d, e, f)
_ =
forall s. Int -> Decoder s ()
decodeListLenOf Int
6
forall (f :: Type -> Type) a b. Applicative f => f a -> f b -> f a
<* forall a s. DecCBOR a => Proxy a -> Decoder s ()
dropCBOR (forall {k} (t :: k). Proxy t
Proxy @a)
forall (f :: Type -> Type) a b. Applicative f => f a -> f b -> f a
<* forall a s. DecCBOR a => Proxy a -> Decoder s ()
dropCBOR (forall {k} (t :: k). Proxy t
Proxy @b)
forall (f :: Type -> Type) a b. Applicative f => f a -> f b -> f a
<* forall a s. DecCBOR a => Proxy a -> Decoder s ()
dropCBOR (forall {k} (t :: k). Proxy t
Proxy @c)
forall (f :: Type -> Type) a b. Applicative f => f a -> f b -> f a
<* forall a s. DecCBOR a => Proxy a -> Decoder s ()
dropCBOR (forall {k} (t :: k). Proxy t
Proxy @d)
forall (f :: Type -> Type) a b. Applicative f => f a -> f b -> f a
<* forall a s. DecCBOR a => Proxy a -> Decoder s ()
dropCBOR (forall {k} (t :: k). Proxy t
Proxy @e)
forall (f :: Type -> Type) a b. Applicative f => f a -> f b -> f a
<* forall a s. DecCBOR a => Proxy a -> Decoder s ()
dropCBOR (forall {k} (t :: k). Proxy t
Proxy @f)
{-# INLINE decCBOR #-}
instance
( DecCBOR a
, DecCBOR b
, DecCBOR c
, DecCBOR d
, DecCBOR e
, DecCBOR f
, DecCBOR g
) =>
DecCBOR (a, b, c, d, e, f, g)
where
decCBOR :: forall s. Decoder s (a, b, c, d, e, f, g)
decCBOR = do
forall s. Int -> Decoder s ()
decodeListLenOf Int
7
!a
a <- forall a s. DecCBOR a => Decoder s a
decCBOR
!b
b <- forall a s. DecCBOR a => Decoder s a
decCBOR
!c
c <- forall a s. DecCBOR a => Decoder s a
decCBOR
!d
d <- forall a s. DecCBOR a => Decoder s a
decCBOR
!e
e <- forall a s. DecCBOR a => Decoder s a
decCBOR
!f
f <- forall a s. DecCBOR a => Decoder s a
decCBOR
!g
g <- forall a s. DecCBOR a => Decoder s a
decCBOR
forall (m :: Type -> Type) a. Monad m => a -> m a
return (a
a, b
b, c
c, d
d, e
e, f
f, g
g)
dropCBOR :: forall s. Proxy (a, b, c, d, e, f, g) -> Decoder s ()
dropCBOR Proxy (a, b, c, d, e, f, g)
_ =
forall s. Int -> Decoder s ()
decodeListLenOf Int
7
forall (f :: Type -> Type) a b. Applicative f => f a -> f b -> f a
<* forall a s. DecCBOR a => Proxy a -> Decoder s ()
dropCBOR (forall {k} (t :: k). Proxy t
Proxy @a)
forall (f :: Type -> Type) a b. Applicative f => f a -> f b -> f a
<* forall a s. DecCBOR a => Proxy a -> Decoder s ()
dropCBOR (forall {k} (t :: k). Proxy t
Proxy @b)
forall (f :: Type -> Type) a b. Applicative f => f a -> f b -> f a
<* forall a s. DecCBOR a => Proxy a -> Decoder s ()
dropCBOR (forall {k} (t :: k). Proxy t
Proxy @c)
forall (f :: Type -> Type) a b. Applicative f => f a -> f b -> f a
<* forall a s. DecCBOR a => Proxy a -> Decoder s ()
dropCBOR (forall {k} (t :: k). Proxy t
Proxy @d)
forall (f :: Type -> Type) a b. Applicative f => f a -> f b -> f a
<* forall a s. DecCBOR a => Proxy a -> Decoder s ()
dropCBOR (forall {k} (t :: k). Proxy t
Proxy @e)
forall (f :: Type -> Type) a b. Applicative f => f a -> f b -> f a
<* forall a s. DecCBOR a => Proxy a -> Decoder s ()
dropCBOR (forall {k} (t :: k). Proxy t
Proxy @f)
forall (f :: Type -> Type) a b. Applicative f => f a -> f b -> f a
<* forall a s. DecCBOR a => Proxy a -> Decoder s ()
dropCBOR (forall {k} (t :: k). Proxy t
Proxy @g)
{-# INLINE decCBOR #-}
instance DecCBOR BS.ByteString where
decCBOR :: forall s. Decoder s ByteString
decCBOR = forall s. Decoder s ByteString
decodeBytes
{-# INLINE decCBOR #-}
instance DecCBOR T.Text where
decCBOR :: forall s. Decoder s Text
decCBOR = forall s. Decoder s Text
decodeString
{-# INLINE decCBOR #-}
instance DecCBOR BSL.ByteString where
decCBOR :: forall s. Decoder s ByteString
decCBOR = ByteString -> ByteString
BSL.fromStrict forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall a s. DecCBOR a => Decoder s a
decCBOR
{-# INLINE decCBOR #-}
instance DecCBOR ShortByteString where
decCBOR :: forall s. Decoder s ShortByteString
decCBOR = do
BA (Prim.ByteArray ByteArray#
ba) <- forall s. Decoder s ByteArray
decodeByteArray
forall (m :: Type -> Type) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ ByteArray# -> ShortByteString
SBS ByteArray#
ba
{-# INLINE decCBOR #-}
instance DecCBOR ByteArray where
decCBOR :: forall s. Decoder s ByteArray
decCBOR = forall s. Decoder s ByteArray
decodeByteArray
{-# INLINE decCBOR #-}
instance DecCBOR Prim.ByteArray where
decCBOR :: forall s. Decoder s ByteArray
decCBOR = ByteArray -> ByteArray
unBA forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s. Decoder s ByteArray
decodeByteArray
{-# INLINE decCBOR #-}
instance DecCBOR SlicedByteArray where
decCBOR :: forall s. Decoder s SlicedByteArray
decCBOR = ByteArray -> SlicedByteArray
fromByteArray forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteArray -> ByteArray
unBA forall (f :: Type -> Type) a b. Functor f => (a -> b) -> f a -> f b
<$> forall s. Decoder s ByteArray
decodeByteArray
{-# INLINE decCBOR #-}
instance DecCBOR a => DecCBOR [a] where
decCBOR :: forall s. Decoder s [a]
decCBOR = forall s a. Decoder s a -> Decoder s [a]
decodeList forall a s. DecCBOR a => Decoder s a
decCBOR
{-# INLINE decCBOR #-}
instance (DecCBOR a, DecCBOR b) => DecCBOR (Either a b) where
decCBOR :: forall s. Decoder s (Either a b)
decCBOR = forall s a b. Decoder s a -> Decoder s b -> Decoder s (Either a b)
decodeEither (forall a s. DecCBOR a => Decoder s a
decCBOR forall (m :: Type -> Type) a b. Monad m => m a -> (a -> m b) -> m b
>>= \a
a -> a
a seq :: forall a b. a -> b -> b
`seq` forall (f :: Type -> Type) a. Applicative f => a -> f a
pure a
a) (forall a s. DecCBOR a => Decoder s a
decCBOR forall (m :: Type -> Type) a b. Monad m => m a -> (a -> m b) -> m b
>>= \b
a -> b
a seq :: forall a b. a -> b -> b
`seq` forall (f :: Type -> Type) a. Applicative f => a -> f a
pure b
a)
{-# INLINE decCBOR #-}
dropCBOR :: forall s. Proxy (Either a b) -> Decoder s ()
dropCBOR Proxy (Either a b)
_ = () forall (f :: Type -> Type) a b. Functor f => a -> f b -> f a
<$ forall s a b. Decoder s a -> Decoder s b -> Decoder s (Either a b)
decodeEither (forall a s. DecCBOR a => Proxy a -> Decoder s ()
dropCBOR (forall {k} (t :: k). Proxy t
Proxy :: Proxy a)) (forall a s. DecCBOR a => Proxy a -> Decoder s ()
dropCBOR (forall {k} (t :: k). Proxy t
Proxy :: Proxy b))
instance DecCBOR a => DecCBOR (NonEmpty a) where
decCBOR :: forall s. Decoder s (NonEmpty a)
decCBOR = forall s a. Decoder s a -> Decoder s (NonEmpty a)
decodeNonEmptyList forall a s. DecCBOR a => Decoder s a
decCBOR
{-# INLINE decCBOR #-}
instance DecCBOR a => DecCBOR (Maybe a) where
decCBOR :: forall s. Decoder s (Maybe a)
decCBOR = forall s a. Decoder s a -> Decoder s (Maybe a)
decodeMaybe forall a s. DecCBOR a => Decoder s a
decCBOR
{-# INLINE decCBOR #-}
dropCBOR :: forall s. Proxy (Maybe a) -> Decoder s ()
dropCBOR Proxy (Maybe a)
_ = () forall (f :: Type -> Type) a b. Functor f => a -> f b -> f a
<$ forall s a. Decoder s a -> Decoder s (Maybe a)
decodeMaybe (forall a s. DecCBOR a => Proxy a -> Decoder s ()
dropCBOR (forall {k} (t :: k). Proxy t
Proxy @a))
instance DecCBOR a => DecCBOR (SMaybe.StrictMaybe a) where
decCBOR :: forall s. Decoder s (StrictMaybe a)
decCBOR = forall s a. Decoder s a -> Decoder s (StrictMaybe a)
decodeStrictMaybe forall a s. DecCBOR a => Decoder s a
decCBOR
{-# INLINE decCBOR #-}
dropCBOR :: forall s. Proxy (StrictMaybe a) -> Decoder s ()
dropCBOR Proxy (StrictMaybe a)
_ = () forall (f :: Type -> Type) a b. Functor f => a -> f b -> f a
<$ forall s a. Decoder s a -> Decoder s (StrictMaybe a)
decodeStrictMaybe (forall a s. DecCBOR a => Proxy a -> Decoder s ()
dropCBOR (forall {k} (t :: k). Proxy t
Proxy @a))
instance DecCBOR a => DecCBOR (SSeq.StrictSeq a) where
decCBOR :: forall s. Decoder s (StrictSeq a)
decCBOR = forall s a. Decoder s a -> Decoder s (StrictSeq a)
decodeStrictSeq forall a s. DecCBOR a => Decoder s a
decCBOR
{-# INLINE decCBOR #-}
instance DecCBOR a => DecCBOR (Seq.Seq a) where
decCBOR :: forall s. Decoder s (Seq a)
decCBOR = forall s a. Decoder s a -> Decoder s (Seq a)
decodeSeq forall a s. DecCBOR a => Decoder s a
decCBOR
{-# INLINE decCBOR #-}
instance (Ord a, DecCBOR a) => DecCBOR (Set.Set a) where
decCBOR :: forall s. Decoder s (Set a)
decCBOR = forall a s. Ord a => Decoder s a -> Decoder s (Set a)
decodeSet forall a s. DecCBOR a => Decoder s a
decCBOR
{-# INLINE decCBOR #-}
instance (Ord k, DecCBOR k, DecCBOR v) => DecCBOR (Map.Map k v) where
decCBOR :: forall s. Decoder s (Map k v)
decCBOR = forall k s v.
Ord k =>
Decoder s k -> Decoder s v -> Decoder s (Map k v)
decodeMap forall a s. DecCBOR a => Decoder s a
decCBOR forall a s. DecCBOR a => Decoder s a
decCBOR
{-# INLINE decCBOR #-}
instance
( Ord k
, DecCBOR k
, DecCBOR a
, Typeable kv
, Typeable av
, VMap.Vector kv k
, VMap.Vector av a
) =>
DecCBOR (VMap.VMap kv av k a)
where
decCBOR :: forall s. Decoder s (VMap kv av k a)
decCBOR = forall (kv :: Type -> Type) k (vv :: Type -> Type) v s.
(Vector kv k, Vector vv v, Ord k) =>
Decoder s k -> Decoder s v -> Decoder s (VMap kv vv k v)
decodeVMap forall a s. DecCBOR a => Decoder s a
decCBOR forall a s. DecCBOR a => Decoder s a
decCBOR
{-# INLINE decCBOR #-}
instance DecCBOR a => DecCBOR (V.Vector a) where
decCBOR :: forall s. Decoder s (Vector a)
decCBOR = forall (vec :: Type -> Type) a s.
Vector vec a =>
Decoder s a -> Decoder s (vec a)
decodeVector forall a s. DecCBOR a => Decoder s a
decCBOR
{-# INLINE decCBOR #-}
instance (DecCBOR a, VP.Prim a) => DecCBOR (VP.Vector a) where
decCBOR :: forall s. Decoder s (Vector a)
decCBOR = forall (vec :: Type -> Type) a s.
Vector vec a =>
Decoder s a -> Decoder s (vec a)
decodeVector forall a s. DecCBOR a => Decoder s a
decCBOR
{-# INLINE decCBOR #-}
instance (DecCBOR a, VS.Storable a) => DecCBOR (VS.Vector a) where
decCBOR :: forall s. Decoder s (Vector a)
decCBOR = forall (vec :: Type -> Type) a s.
Vector vec a =>
Decoder s a -> Decoder s (vec a)
decodeVector forall a s. DecCBOR a => Decoder s a
decCBOR
{-# INLINE decCBOR #-}
instance (DecCBOR a, VU.Unbox a) => DecCBOR (VU.Vector a) where
decCBOR :: forall s. Decoder s (Vector a)
decCBOR = forall (vec :: Type -> Type) a s.
Vector vec a =>
Decoder s a -> Decoder s (vec a)
decodeVector forall a s. DecCBOR a => Decoder s a
decCBOR
{-# INLINE decCBOR #-}
instance DecCBOR UTCTime where
decCBOR :: forall s. Decoder s UTCTime
decCBOR = forall s. Decoder s UTCTime
decodeUTCTime
{-# INLINE decCBOR #-}
instance DSIGNAlgorithm v => DecCBOR (VerKeyDSIGN v) where
decCBOR :: forall s. Decoder s (VerKeyDSIGN v)
decCBOR = forall v s. DSIGNAlgorithm v => Decoder s (VerKeyDSIGN v)
decodeVerKeyDSIGN
{-# INLINE decCBOR #-}
instance DSIGNAlgorithm v => DecCBOR (SignKeyDSIGN v) where
decCBOR :: forall s. Decoder s (SignKeyDSIGN v)
decCBOR = forall v s. DSIGNAlgorithm v => Decoder s (SignKeyDSIGN v)
decodeSignKeyDSIGN
{-# INLINE decCBOR #-}
instance DSIGNAlgorithm v => DecCBOR (SigDSIGN v) where
decCBOR :: forall s. Decoder s (SigDSIGN v)
decCBOR = forall v s. DSIGNAlgorithm v => Decoder s (SigDSIGN v)
decodeSigDSIGN
{-# INLINE decCBOR #-}
instance (DSIGNAlgorithm v, Typeable a) => DecCBOR (SignedDSIGN v a) where
decCBOR :: forall s. Decoder s (SignedDSIGN v a)
decCBOR = forall v s a. DSIGNAlgorithm v => Decoder s (SignedDSIGN v a)
decodeSignedDSIGN
{-# INLINE decCBOR #-}
instance (HashAlgorithm h, Typeable a) => DecCBOR (Hash h a)
instance KESAlgorithm k => DecCBOR (VerKeyKES k) where
decCBOR :: forall s. Decoder s (VerKeyKES k)
decCBOR = forall v s. KESAlgorithm v => Decoder s (VerKeyKES v)
decodeVerKeyKES
{-# INLINE decCBOR #-}
instance KESAlgorithm k => DecCBOR (SigKES k) where
decCBOR :: forall s. Decoder s (SigKES k)
decCBOR = forall v s. KESAlgorithm v => Decoder s (SigKES v)
decodeSigKES
{-# INLINE decCBOR #-}
instance DecCBOR (VerKeyVRF SimpleVRF) where
decCBOR :: forall s. Decoder s (VerKeyVRF SimpleVRF)
decCBOR = forall v s. VRFAlgorithm v => Decoder s (VerKeyVRF v)
decodeVerKeyVRF
{-# INLINE decCBOR #-}
instance DecCBOR (SignKeyVRF SimpleVRF) where
decCBOR :: forall s. Decoder s (SignKeyVRF SimpleVRF)
decCBOR = forall v s. VRFAlgorithm v => Decoder s (SignKeyVRF v)
decodeSignKeyVRF
{-# INLINE decCBOR #-}
instance DecCBOR (CertVRF SimpleVRF) where
decCBOR :: forall s. Decoder s (CertVRF SimpleVRF)
decCBOR = forall v s. VRFAlgorithm v => Decoder s (CertVRF v)
decodeCertVRF
{-# INLINE decCBOR #-}
instance DecCBOR (VerKeyVRF MockVRF) where
decCBOR :: forall s. Decoder s (VerKeyVRF MockVRF)
decCBOR = forall v s. VRFAlgorithm v => Decoder s (VerKeyVRF v)
decodeVerKeyVRF
{-# INLINE decCBOR #-}
instance DecCBOR (SignKeyVRF MockVRF) where
decCBOR :: forall s. Decoder s (SignKeyVRF MockVRF)
decCBOR = forall v s. VRFAlgorithm v => Decoder s (SignKeyVRF v)
decodeSignKeyVRF
{-# INLINE decCBOR #-}
instance DecCBOR (CertVRF MockVRF) where
decCBOR :: forall s. Decoder s (CertVRF MockVRF)
decCBOR = forall v s. VRFAlgorithm v => Decoder s (CertVRF v)
decodeCertVRF
{-# INLINE decCBOR #-}
instance DecCBOR Praos.Proof where
decCBOR :: forall s. Decoder s Proof
decCBOR = forall a s. DecCBOR a => Decoder s a
decCBOR forall (m :: Type -> Type) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: Type -> Type). MonadFail m => ByteString -> m Proof
Praos.proofFromBytes
{-# INLINE decCBOR #-}
instance DecCBOR Praos.SignKey where
decCBOR :: forall s. Decoder s SignKey
decCBOR = forall a s. DecCBOR a => Decoder s a
decCBOR forall (m :: Type -> Type) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: Type -> Type). MonadFail m => ByteString -> m SignKey
Praos.skFromBytes
{-# INLINE decCBOR #-}
instance DecCBOR Praos.VerKey where
decCBOR :: forall s. Decoder s VerKey
decCBOR = forall a s. DecCBOR a => Decoder s a
decCBOR forall (m :: Type -> Type) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall (m :: Type -> Type). MonadFail m => ByteString -> m VerKey
Praos.vkFromBytes
{-# INLINE decCBOR #-}
deriving instance DecCBOR (VerKeyVRF Praos.PraosVRF)
deriving instance DecCBOR (SignKeyVRF Praos.PraosVRF)
deriving instance DecCBOR (CertVRF Praos.PraosVRF)
deriving instance Typeable v => DecCBOR (OutputVRF v)
instance (VRFAlgorithm v, Typeable a) => DecCBOR (CertifiedVRF v a) where
decCBOR :: forall s. Decoder s (CertifiedVRF v a)
decCBOR =
forall v a. OutputVRF v -> CertVRF v -> CertifiedVRF v a
CertifiedVRF
forall (f :: Type -> Type) a b. Functor f => a -> f b -> f a
<$ forall s. Text -> Int -> Decoder s ()
enforceSize Text
"CertifiedVRF" Int
2
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> forall a s. DecCBOR a => Decoder s a
decCBOR
forall (f :: Type -> Type) a b.
Applicative f =>
f (a -> b) -> f a -> f b
<*> forall v s. VRFAlgorithm v => Decoder s (CertVRF v)
decodeCertVRF
{-# INLINE decCBOR #-}
instance DecCBOR SlotNo where
decCBOR :: forall s. Decoder s SlotNo
decCBOR = forall s a. Decoder s a -> Decoder s a
fromPlainDecoder forall a s. Serialise a => Decoder s a
Serialise.decode
{-# INLINE decCBOR #-}
instance (Serialise.Serialise t, Typeable t) => DecCBOR (WithOrigin t) where
decCBOR :: forall s. Decoder s (WithOrigin t)
decCBOR = forall s a. Decoder s a -> Decoder s a
fromPlainDecoder forall a s. Serialise a => Decoder s a
Serialise.decode
{-# INLINE decCBOR #-}
deriving instance DecCBOR EpochNo
deriving instance DecCBOR EpochSize
deriving instance DecCBOR SystemStart
instance DecCBOR BlockNo where
decCBOR :: forall s. Decoder s BlockNo
decCBOR = forall s a. Decoder s a -> Decoder s a
fromPlainDecoder forall a s. Serialise a => Decoder s a
decode
{-# INLINE decCBOR #-}
deriving instance DecCBOR EpochInterval
instance DecCBOR PV1.Data where
decCBOR :: forall s. Decoder s Data
decCBOR = forall s a. Decoder s a -> Decoder s a
fromPlainDecoder forall a s. Serialise a => Decoder s a
decode
{-# INLINE decCBOR #-}
instance DecCBOR PV1.ScriptContext where
decCBOR :: forall s. Decoder s ScriptContext
decCBOR = forall a s. DecCBOR a => Decoder s a
decCBOR forall (m :: Type -> Type) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a (m :: Type -> Type).
(FromData a, MonadFail m) =>
Data -> m a
decodeScriptContextFromData
instance DecCBOR PV2.ScriptContext where
decCBOR :: forall s. Decoder s ScriptContext
decCBOR = forall a s. DecCBOR a => Decoder s a
decCBOR forall (m :: Type -> Type) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a (m :: Type -> Type).
(FromData a, MonadFail m) =>
Data -> m a
decodeScriptContextFromData
instance DecCBOR PV3.ScriptContext where
decCBOR :: forall s. Decoder s ScriptContext
decCBOR = forall a s. DecCBOR a => Decoder s a
decCBOR forall (m :: Type -> Type) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a (m :: Type -> Type).
(FromData a, MonadFail m) =>
Data -> m a
decodeScriptContextFromData
decodeScriptContextFromData :: (PV3.FromData a, MonadFail m) => PV3.Data -> m a
decodeScriptContextFromData :: forall a (m :: Type -> Type).
(FromData a, MonadFail m) =>
Data -> m a
decodeScriptContextFromData Data
scriptContextData =
case forall a. FromData a => Data -> Maybe a
PV3.fromData Data
scriptContextData of
Maybe a
Nothing -> forall (m :: Type -> Type) a. MonadFail m => String -> m a
fail forall a b. (a -> b) -> a -> b
$ String
"ScriptContext cannot be decoded from Data: " forall a. Semigroup a => a -> a -> a
<> forall a. Show a => a -> String
show Data
scriptContextData
Just a
scriptContext -> forall (f :: Type -> Type) a. Applicative f => a -> f a
pure a
scriptContext