{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes #-}
module Cometa.Internal.TransactionFields
( Fields (..),
fields,
Mint,
mkMint,
mintValue,
Entries,
mkEntries,
entries,
BalanceInterval (..),
BodyNetwork (..),
encodeFields,
decodeFields,
validateFields,
encodeIntervals,
decodeIntervals,
)
where
import qualified Codec.CBOR.Decoding as D
import qualified Codec.CBOR.Encoding as E
import Cometa.Address.Reward (RewardAddress)
import qualified Cometa.Address.Reward as Reward
import Cometa.Certificate.Collection (Certificates)
import qualified Cometa.Certificate.Collection as Certificates
import Cometa.Credential (Credential, Guard)
import qualified Cometa.Credential as Credential
import Cometa.Error (Error (..))
import Cometa.Governance.Proposal (Proposals)
import qualified Cometa.Governance.Proposal as Proposal
import Cometa.Governance.Voting (VotingProcedures)
import qualified Cometa.Governance.Voting as Voting
import qualified Cometa.Internal.ProposalCbor as P
import qualified Cometa.Internal.TransactionCbor as Cbor
import qualified Cometa.Internal.TransactionValue as V
import Cometa.PlutusData (EncodedPlutusData)
import qualified Cometa.PlutusData as Data
import Cometa.Transaction.Datum (Hash32)
import qualified Cometa.Transaction.Datum as Datum
import Cometa.Transaction.Input (Input)
import qualified Cometa.Transaction.Input as Input
import Cometa.Transaction.Output (Output)
import qualified Cometa.Transaction.Output as Output
import Cometa.Value (Value)
import qualified Cometa.Value as Value
import Control.Monad (unless, when)
import Data.ByteString (ByteString)
import Data.List (sort, sortOn)
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as Map
import qualified Data.Set as Set
import Data.Word (Word64)
newtype Entries key value = Entries (Map key value) deriving (Entries key value -> Entries key value -> Bool
(Entries key value -> Entries key value -> Bool)
-> (Entries key value -> Entries key value -> Bool)
-> Eq (Entries key value)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall key value.
(Eq key, Eq value) =>
Entries key value -> Entries key value -> Bool
$c== :: forall key value.
(Eq key, Eq value) =>
Entries key value -> Entries key value -> Bool
== :: Entries key value -> Entries key value -> Bool
$c/= :: forall key value.
(Eq key, Eq value) =>
Entries key value -> Entries key value -> Bool
/= :: Entries key value -> Entries key value -> Bool
Eq, Int -> Entries key value -> ShowS
[Entries key value] -> ShowS
Entries key value -> String
(Int -> Entries key value -> ShowS)
-> (Entries key value -> String)
-> ([Entries key value] -> ShowS)
-> Show (Entries key value)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall key value.
(Show key, Show value) =>
Int -> Entries key value -> ShowS
forall key value.
(Show key, Show value) =>
[Entries key value] -> ShowS
forall key value.
(Show key, Show value) =>
Entries key value -> String
$cshowsPrec :: forall key value.
(Show key, Show value) =>
Int -> Entries key value -> ShowS
showsPrec :: Int -> Entries key value -> ShowS
$cshow :: forall key value.
(Show key, Show value) =>
Entries key value -> String
show :: Entries key value -> String
$cshowList :: forall key value.
(Show key, Show value) =>
[Entries key value] -> ShowS
showList :: [Entries key value] -> ShowS
Show)
mkEntries :: (Ord key) => [(key, value)] -> Either Error (Entries key value)
mkEntries :: forall key value.
Ord key =>
[(key, value)] -> Either Error (Entries key value)
mkEntries [(key, value)]
pairs
| [(key, value)] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [(key, value)]
pairs = Error -> Either Error (Entries key value)
forall a b. a -> Either a b
Left (Text -> Error
InvalidTransactionField Text
"Empty transaction association")
| Map key value -> Int
forall k a. Map k a -> Int
Map.size Map key value
result Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
/= [(key, value)] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [(key, value)]
pairs = Error -> Either Error (Entries key value)
forall a b. a -> Either a b
Left (Text -> Error
InvalidTransactionField Text
"Duplicate transaction association key")
| Bool
otherwise = Entries key value -> Either Error (Entries key value)
forall a b. b -> Either a b
Right (Map key value -> Entries key value
forall key value. Map key value -> Entries key value
Entries Map key value
result)
where
result :: Map key value
result = [(key, value)] -> Map key value
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [(key, value)]
pairs
entries :: Entries key value -> [(key, value)]
entries :: forall key value. Entries key value -> [(key, value)]
entries (Entries Map key value
result) = Map key value -> [(key, value)]
forall k a. Map k a -> [(k, a)]
Map.toAscList Map key value
result
newtype Mint = Mint Value deriving (Mint -> Mint -> Bool
(Mint -> Mint -> Bool) -> (Mint -> Mint -> Bool) -> Eq Mint
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Mint -> Mint -> Bool
== :: Mint -> Mint -> Bool
$c/= :: Mint -> Mint -> Bool
/= :: Mint -> Mint -> Bool
Eq, Int -> Mint -> ShowS
[Mint] -> ShowS
Mint -> String
(Int -> Mint -> ShowS)
-> (Mint -> String) -> ([Mint] -> ShowS) -> Show Mint
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Mint -> ShowS
showsPrec :: Int -> Mint -> ShowS
$cshow :: Mint -> String
show :: Mint -> String
$cshowList :: [Mint] -> ShowS
showList :: [Mint] -> ShowS
Show)
mkMint :: Value -> Either Error Mint
mkMint :: Value -> Either Error Mint
mkMint Value
value = Value -> Either Error ()
V.validateMint Value
value Either Error () -> Either Error Mint -> Either Error Mint
forall a b. Either Error a -> Either Error b -> Either Error b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> Mint -> Either Error Mint
forall a. a -> Either Error a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Value -> Mint
Mint Value
value)
mintValue :: Mint -> Value
mintValue :: Mint -> Value
mintValue (Mint Value
result) = Value
result
data BalanceInterval
=
ExactBalance !Word64
|
BalanceRange !(Maybe Word64) !(Maybe Word64)
deriving (BalanceInterval -> BalanceInterval -> Bool
(BalanceInterval -> BalanceInterval -> Bool)
-> (BalanceInterval -> BalanceInterval -> Bool)
-> Eq BalanceInterval
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BalanceInterval -> BalanceInterval -> Bool
== :: BalanceInterval -> BalanceInterval -> Bool
$c/= :: BalanceInterval -> BalanceInterval -> Bool
/= :: BalanceInterval -> BalanceInterval -> Bool
Eq, Int -> BalanceInterval -> ShowS
[BalanceInterval] -> ShowS
BalanceInterval -> String
(Int -> BalanceInterval -> ShowS)
-> (BalanceInterval -> String)
-> ([BalanceInterval] -> ShowS)
-> Show BalanceInterval
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BalanceInterval -> ShowS
showsPrec :: Int -> BalanceInterval -> ShowS
$cshow :: BalanceInterval -> String
show :: BalanceInterval -> String
$cshowList :: [BalanceInterval] -> ShowS
showList :: [BalanceInterval] -> ShowS
Show)
data Fields = Fields
{
Fields -> [Input]
fieldInputs :: ![Input],
Fields -> [Output]
fieldOutputs :: ![Output],
Fields -> Maybe Word64
fieldInvalidAfter :: !(Maybe Word64),
Fields -> Maybe Certificates
fieldCertificates :: !(Maybe Certificates),
Fields -> Maybe (Entries RewardAddress Word64)
fieldWithdrawals :: !(Maybe (Entries RewardAddress Word64)),
Fields -> Maybe Hash32
fieldAuxiliaryDataHash :: !(Maybe Hash32),
Fields -> Maybe Word64
fieldInvalidBefore :: !(Maybe Word64),
Fields -> Maybe Mint
fieldMint :: !(Maybe Mint),
Fields -> Maybe Hash32
fieldScriptDataHash :: !(Maybe Hash32),
Fields -> Maybe [Credential Guard]
fieldGuards :: !(Maybe [Credential Guard]),
Fields -> Maybe BodyNetwork
fieldNetworkId :: !(Maybe BodyNetwork),
Fields -> Maybe [Input]
fieldReferenceInputs :: !(Maybe [Input]),
Fields -> Maybe VotingProcedures
fieldVotingProcedures :: !(Maybe VotingProcedures),
Fields -> Maybe Proposals
fieldProposalProcedures :: !(Maybe Proposals),
Fields -> Maybe Word64
fieldTreasuryValue :: !(Maybe Word64),
Fields -> Maybe Word64
fieldDonation :: !(Maybe Word64),
Fields
-> Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
fieldRequiredTopLevelGuards :: !(Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))),
Fields -> Maybe (Entries RewardAddress Word64)
fieldDirectDeposits :: !(Maybe (Entries RewardAddress Word64)),
Fields -> Maybe (Entries RewardAddress BalanceInterval)
fieldAccountBalanceIntervals :: !(Maybe (Entries RewardAddress BalanceInterval))
}
deriving (Fields -> Fields -> Bool
(Fields -> Fields -> Bool)
-> (Fields -> Fields -> Bool) -> Eq Fields
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Fields -> Fields -> Bool
== :: Fields -> Fields -> Bool
$c/= :: Fields -> Fields -> Bool
/= :: Fields -> Fields -> Bool
Eq, Int -> Fields -> ShowS
[Fields] -> ShowS
Fields -> String
(Int -> Fields -> ShowS)
-> (Fields -> String) -> ([Fields] -> ShowS) -> Show Fields
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Fields -> ShowS
showsPrec :: Int -> Fields -> ShowS
$cshow :: Fields -> String
show :: Fields -> String
$cshowList :: [Fields] -> ShowS
showList :: [Fields] -> ShowS
Show)
data BodyNetwork = Testnet | Mainnet deriving (BodyNetwork -> BodyNetwork -> Bool
(BodyNetwork -> BodyNetwork -> Bool)
-> (BodyNetwork -> BodyNetwork -> Bool) -> Eq BodyNetwork
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: BodyNetwork -> BodyNetwork -> Bool
== :: BodyNetwork -> BodyNetwork -> Bool
$c/= :: BodyNetwork -> BodyNetwork -> Bool
/= :: BodyNetwork -> BodyNetwork -> Bool
Eq, Eq BodyNetwork
Eq BodyNetwork =>
(BodyNetwork -> BodyNetwork -> Ordering)
-> (BodyNetwork -> BodyNetwork -> Bool)
-> (BodyNetwork -> BodyNetwork -> Bool)
-> (BodyNetwork -> BodyNetwork -> Bool)
-> (BodyNetwork -> BodyNetwork -> Bool)
-> (BodyNetwork -> BodyNetwork -> BodyNetwork)
-> (BodyNetwork -> BodyNetwork -> BodyNetwork)
-> Ord BodyNetwork
BodyNetwork -> BodyNetwork -> Bool
BodyNetwork -> BodyNetwork -> Ordering
BodyNetwork -> BodyNetwork -> BodyNetwork
forall a.
Eq a =>
(a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
$ccompare :: BodyNetwork -> BodyNetwork -> Ordering
compare :: BodyNetwork -> BodyNetwork -> Ordering
$c< :: BodyNetwork -> BodyNetwork -> Bool
< :: BodyNetwork -> BodyNetwork -> Bool
$c<= :: BodyNetwork -> BodyNetwork -> Bool
<= :: BodyNetwork -> BodyNetwork -> Bool
$c> :: BodyNetwork -> BodyNetwork -> Bool
> :: BodyNetwork -> BodyNetwork -> Bool
$c>= :: BodyNetwork -> BodyNetwork -> Bool
>= :: BodyNetwork -> BodyNetwork -> Bool
$cmax :: BodyNetwork -> BodyNetwork -> BodyNetwork
max :: BodyNetwork -> BodyNetwork -> BodyNetwork
$cmin :: BodyNetwork -> BodyNetwork -> BodyNetwork
min :: BodyNetwork -> BodyNetwork -> BodyNetwork
Ord, Int -> BodyNetwork -> ShowS
[BodyNetwork] -> ShowS
BodyNetwork -> String
(Int -> BodyNetwork -> ShowS)
-> (BodyNetwork -> String)
-> ([BodyNetwork] -> ShowS)
-> Show BodyNetwork
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> BodyNetwork -> ShowS
showsPrec :: Int -> BodyNetwork -> ShowS
$cshow :: BodyNetwork -> String
show :: BodyNetwork -> String
$cshowList :: [BodyNetwork] -> ShowS
showList :: [BodyNetwork] -> ShowS
Show, Int -> BodyNetwork
BodyNetwork -> Int
BodyNetwork -> [BodyNetwork]
BodyNetwork -> BodyNetwork
BodyNetwork -> BodyNetwork -> [BodyNetwork]
BodyNetwork -> BodyNetwork -> BodyNetwork -> [BodyNetwork]
(BodyNetwork -> BodyNetwork)
-> (BodyNetwork -> BodyNetwork)
-> (Int -> BodyNetwork)
-> (BodyNetwork -> Int)
-> (BodyNetwork -> [BodyNetwork])
-> (BodyNetwork -> BodyNetwork -> [BodyNetwork])
-> (BodyNetwork -> BodyNetwork -> [BodyNetwork])
-> (BodyNetwork -> BodyNetwork -> BodyNetwork -> [BodyNetwork])
-> Enum BodyNetwork
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: BodyNetwork -> BodyNetwork
succ :: BodyNetwork -> BodyNetwork
$cpred :: BodyNetwork -> BodyNetwork
pred :: BodyNetwork -> BodyNetwork
$ctoEnum :: Int -> BodyNetwork
toEnum :: Int -> BodyNetwork
$cfromEnum :: BodyNetwork -> Int
fromEnum :: BodyNetwork -> Int
$cenumFrom :: BodyNetwork -> [BodyNetwork]
enumFrom :: BodyNetwork -> [BodyNetwork]
$cenumFromThen :: BodyNetwork -> BodyNetwork -> [BodyNetwork]
enumFromThen :: BodyNetwork -> BodyNetwork -> [BodyNetwork]
$cenumFromTo :: BodyNetwork -> BodyNetwork -> [BodyNetwork]
enumFromTo :: BodyNetwork -> BodyNetwork -> [BodyNetwork]
$cenumFromThenTo :: BodyNetwork -> BodyNetwork -> BodyNetwork -> [BodyNetwork]
enumFromThenTo :: BodyNetwork -> BodyNetwork -> BodyNetwork -> [BodyNetwork]
Enum, BodyNetwork
BodyNetwork -> BodyNetwork -> Bounded BodyNetwork
forall a. a -> a -> Bounded a
$cminBound :: BodyNetwork
minBound :: BodyNetwork
$cmaxBound :: BodyNetwork
maxBound :: BodyNetwork
Bounded)
fields :: [Input] -> [Output] -> Fields
fields :: [Input] -> [Output] -> Fields
fields [Input]
inputs [Output]
outputs = [Input]
-> [Output]
-> Maybe Word64
-> Maybe Certificates
-> Maybe (Entries RewardAddress Word64)
-> Maybe Hash32
-> Maybe Word64
-> Maybe Mint
-> Maybe Hash32
-> Maybe [Credential Guard]
-> Maybe BodyNetwork
-> Maybe [Input]
-> Maybe VotingProcedures
-> Maybe Proposals
-> Maybe Word64
-> Maybe Word64
-> Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
-> Maybe (Entries RewardAddress Word64)
-> Maybe (Entries RewardAddress BalanceInterval)
-> Fields
Fields ([Input] -> [Input]
forall a. Ord a => [a] -> [a]
sort [Input]
inputs) [Output]
outputs Maybe Word64
forall a. Maybe a
Nothing Maybe Certificates
forall a. Maybe a
Nothing Maybe (Entries RewardAddress Word64)
forall a. Maybe a
Nothing Maybe Hash32
forall a. Maybe a
Nothing Maybe Word64
forall a. Maybe a
Nothing Maybe Mint
forall a. Maybe a
Nothing Maybe Hash32
forall a. Maybe a
Nothing Maybe [Credential Guard]
forall a. Maybe a
Nothing Maybe BodyNetwork
forall a. Maybe a
Nothing Maybe [Input]
forall a. Maybe a
Nothing Maybe VotingProcedures
forall a. Maybe a
Nothing Maybe Proposals
forall a. Maybe a
Nothing Maybe Word64
forall a. Maybe a
Nothing Maybe Word64
forall a. Maybe a
Nothing Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
forall a. Maybe a
Nothing Maybe (Entries RewardAddress Word64)
forall a. Maybe a
Nothing Maybe (Entries RewardAddress BalanceInterval)
forall a. Maybe a
Nothing
encodeFields :: Fields -> [(Word64, E.Encoding)]
encodeFields :: Fields -> [(Word64, Encoding)]
encodeFields Fields
value =
[(Word64
0, [Input] -> Encoding
inputSet (Fields -> [Input]
fieldInputs Fields
value)), (Word64
1, [Output] -> Encoding
outputList (Fields -> [Output]
fieldOutputs Fields
value))]
[(Word64, Encoding)]
-> [(Word64, Encoding)] -> [(Word64, Encoding)]
forall a. [a] -> [a] -> [a]
++ Word64
-> (Word64 -> Encoding) -> Maybe Word64 -> [(Word64, Encoding)]
forall {a} {t} {b}. a -> (t -> b) -> Maybe t -> [(a, b)]
optional Word64
3 Word64 -> Encoding
E.encodeWord64 (Fields -> Maybe Word64
fieldInvalidAfter Fields
value)
[(Word64, Encoding)]
-> [(Word64, Encoding)] -> [(Word64, Encoding)]
forall a. [a] -> [a] -> [a]
++ Word64
-> (Certificates -> Encoding)
-> Maybe Certificates
-> [(Word64, Encoding)]
forall {a} {t} {b}. a -> (t -> b) -> Maybe t -> [(a, b)]
optional Word64
4 (ByteString -> Encoding
Cbor.raw (ByteString -> Encoding)
-> (Certificates -> ByteString) -> Certificates -> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Certificates -> ByteString
Certificates.encodeCbor) (Fields -> Maybe Certificates
fieldCertificates Fields
value)
[(Word64, Encoding)]
-> [(Word64, Encoding)] -> [(Word64, Encoding)]
forall a. [a] -> [a] -> [a]
++ Word64
-> (Entries RewardAddress Word64 -> Encoding)
-> Maybe (Entries RewardAddress Word64)
-> [(Word64, Encoding)]
forall {a} {t} {b}. a -> (t -> b) -> Maybe t -> [(a, b)]
optional Word64
5 ((RewardAddress -> Encoding)
-> (Word64 -> Encoding) -> Entries RewardAddress Word64 -> Encoding
forall key value.
(key -> Encoding)
-> (value -> Encoding) -> Entries key value -> Encoding
association (ByteString -> Encoding
E.encodeBytes (ByteString -> Encoding)
-> (RewardAddress -> ByteString) -> RewardAddress -> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RewardAddress -> ByteString
Reward.toBytes) Word64 -> Encoding
E.encodeWord64) (Fields -> Maybe (Entries RewardAddress Word64)
fieldWithdrawals Fields
value)
[(Word64, Encoding)]
-> [(Word64, Encoding)] -> [(Word64, Encoding)]
forall a. [a] -> [a] -> [a]
++ Word64
-> (Hash32 -> Encoding) -> Maybe Hash32 -> [(Word64, Encoding)]
forall {a} {t} {b}. a -> (t -> b) -> Maybe t -> [(a, b)]
optional Word64
7 Hash32 -> Encoding
hashEncoding (Fields -> Maybe Hash32
fieldAuxiliaryDataHash Fields
value)
[(Word64, Encoding)]
-> [(Word64, Encoding)] -> [(Word64, Encoding)]
forall a. [a] -> [a] -> [a]
++ Word64
-> (Word64 -> Encoding) -> Maybe Word64 -> [(Word64, Encoding)]
forall {a} {t} {b}. a -> (t -> b) -> Maybe t -> [(a, b)]
optional Word64
8 Word64 -> Encoding
E.encodeWord64 (Fields -> Maybe Word64
fieldInvalidBefore Fields
value)
[(Word64, Encoding)]
-> [(Word64, Encoding)] -> [(Word64, Encoding)]
forall a. [a] -> [a] -> [a]
++ Word64 -> (Mint -> Encoding) -> Maybe Mint -> [(Word64, Encoding)]
forall {a} {t} {b}. a -> (t -> b) -> Maybe t -> [(a, b)]
optional Word64
9 (Value -> Encoding
V.encodeAssets (Value -> Encoding) -> (Mint -> Value) -> Mint -> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Mint -> Value
mintValue) (Fields -> Maybe Mint
fieldMint Fields
value)
[(Word64, Encoding)]
-> [(Word64, Encoding)] -> [(Word64, Encoding)]
forall a. [a] -> [a] -> [a]
++ Word64
-> (Hash32 -> Encoding) -> Maybe Hash32 -> [(Word64, Encoding)]
forall {a} {t} {b}. a -> (t -> b) -> Maybe t -> [(a, b)]
optional Word64
11 Hash32 -> Encoding
hashEncoding (Fields -> Maybe Hash32
fieldScriptDataHash Fields
value)
[(Word64, Encoding)]
-> [(Word64, Encoding)] -> [(Word64, Encoding)]
forall a. [a] -> [a] -> [a]
++ Word64
-> ([Credential Guard] -> Encoding)
-> Maybe [Credential Guard]
-> [(Word64, Encoding)]
forall {a} {t} {b}. a -> (t -> b) -> Maybe t -> [(a, b)]
optional Word64
14 [Credential Guard] -> Encoding
guardSet (Fields -> Maybe [Credential Guard]
fieldGuards Fields
value)
[(Word64, Encoding)]
-> [(Word64, Encoding)] -> [(Word64, Encoding)]
forall a. [a] -> [a] -> [a]
++ Word64
-> (BodyNetwork -> Encoding)
-> Maybe BodyNetwork
-> [(Word64, Encoding)]
forall {a} {t} {b}. a -> (t -> b) -> Maybe t -> [(a, b)]
optional Word64
15 (Word -> Encoding
E.encodeWord (Word -> Encoding)
-> (BodyNetwork -> Word) -> BodyNetwork -> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Int -> Word) -> (BodyNetwork -> Int) -> BodyNetwork -> Word
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BodyNetwork -> Int
forall a. Enum a => a -> Int
fromEnum) (Fields -> Maybe BodyNetwork
fieldNetworkId Fields
value)
[(Word64, Encoding)]
-> [(Word64, Encoding)] -> [(Word64, Encoding)]
forall a. [a] -> [a] -> [a]
++ Word64
-> ([Input] -> Encoding) -> Maybe [Input] -> [(Word64, Encoding)]
forall {a} {t} {b}. a -> (t -> b) -> Maybe t -> [(a, b)]
optional Word64
18 [Input] -> Encoding
inputSet (Fields -> Maybe [Input]
fieldReferenceInputs Fields
value)
[(Word64, Encoding)]
-> [(Word64, Encoding)] -> [(Word64, Encoding)]
forall a. [a] -> [a] -> [a]
++ Word64
-> (VotingProcedures -> Encoding)
-> Maybe VotingProcedures
-> [(Word64, Encoding)]
forall {a} {t} {b}. a -> (t -> b) -> Maybe t -> [(a, b)]
optional Word64
19 (ByteString -> Encoding
Cbor.raw (ByteString -> Encoding)
-> (VotingProcedures -> ByteString) -> VotingProcedures -> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. VotingProcedures -> ByteString
Voting.encodeCbor) (Fields -> Maybe VotingProcedures
fieldVotingProcedures Fields
value)
[(Word64, Encoding)]
-> [(Word64, Encoding)] -> [(Word64, Encoding)]
forall a. [a] -> [a] -> [a]
++ Word64
-> (Proposals -> Encoding)
-> Maybe Proposals
-> [(Word64, Encoding)]
forall {a} {t} {b}. a -> (t -> b) -> Maybe t -> [(a, b)]
optional Word64
20 (ByteString -> Encoding
Cbor.raw (ByteString -> Encoding)
-> (Proposals -> ByteString) -> Proposals -> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proposals -> ByteString
Proposal.encodeProposals) (Fields -> Maybe Proposals
fieldProposalProcedures Fields
value)
[(Word64, Encoding)]
-> [(Word64, Encoding)] -> [(Word64, Encoding)]
forall a. [a] -> [a] -> [a]
++ Word64
-> (Word64 -> Encoding) -> Maybe Word64 -> [(Word64, Encoding)]
forall {a} {t} {b}. a -> (t -> b) -> Maybe t -> [(a, b)]
optional Word64
21 Word64 -> Encoding
E.encodeWord64 (Fields -> Maybe Word64
fieldTreasuryValue Fields
value)
[(Word64, Encoding)]
-> [(Word64, Encoding)] -> [(Word64, Encoding)]
forall a. [a] -> [a] -> [a]
++ Word64
-> (Word64 -> Encoding) -> Maybe Word64 -> [(Word64, Encoding)]
forall {a} {t} {b}. a -> (t -> b) -> Maybe t -> [(a, b)]
optional Word64
22 Word64 -> Encoding
E.encodeWord64 (Fields -> Maybe Word64
fieldDonation Fields
value)
[(Word64, Encoding)]
-> [(Word64, Encoding)] -> [(Word64, Encoding)]
forall a. [a] -> [a] -> [a]
++ Word64
-> (Entries (Credential Guard) (Maybe EncodedPlutusData)
-> Encoding)
-> Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
-> [(Word64, Encoding)]
forall {a} {t} {b}. a -> (t -> b) -> Maybe t -> [(a, b)]
optional Word64
24 ((Credential Guard -> Encoding)
-> (Maybe EncodedPlutusData -> Encoding)
-> Entries (Credential Guard) (Maybe EncodedPlutusData)
-> Encoding
forall key value.
(key -> Encoding)
-> (value -> Encoding) -> Entries key value -> Encoding
association Credential Guard -> Encoding
forall purpose. Credential purpose -> Encoding
P.credentialEncoding (Encoding
-> (EncodedPlutusData -> Encoding)
-> Maybe EncodedPlutusData
-> Encoding
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Encoding
E.encodeNull (ByteString -> Encoding
Cbor.raw (ByteString -> Encoding)
-> (EncodedPlutusData -> ByteString)
-> EncodedPlutusData
-> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EncodedPlutusData -> ByteString
Data.toCbor))) (Fields
-> Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
fieldRequiredTopLevelGuards Fields
value)
[(Word64, Encoding)]
-> [(Word64, Encoding)] -> [(Word64, Encoding)]
forall a. [a] -> [a] -> [a]
++ Word64
-> (Entries RewardAddress Word64 -> Encoding)
-> Maybe (Entries RewardAddress Word64)
-> [(Word64, Encoding)]
forall {a} {t} {b}. a -> (t -> b) -> Maybe t -> [(a, b)]
optional Word64
25 ((RewardAddress -> Encoding)
-> (Word64 -> Encoding) -> Entries RewardAddress Word64 -> Encoding
forall key value.
(key -> Encoding)
-> (value -> Encoding) -> Entries key value -> Encoding
association (ByteString -> Encoding
E.encodeBytes (ByteString -> Encoding)
-> (RewardAddress -> ByteString) -> RewardAddress -> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RewardAddress -> ByteString
Reward.toBytes) Word64 -> Encoding
E.encodeWord64) (Fields -> Maybe (Entries RewardAddress Word64)
fieldDirectDeposits Fields
value)
[(Word64, Encoding)]
-> [(Word64, Encoding)] -> [(Word64, Encoding)]
forall a. [a] -> [a] -> [a]
++ Word64
-> (Entries RewardAddress BalanceInterval -> Encoding)
-> Maybe (Entries RewardAddress BalanceInterval)
-> [(Word64, Encoding)]
forall {a} {t} {b}. a -> (t -> b) -> Maybe t -> [(a, b)]
optional Word64
26 ((RewardAddress -> Encoding)
-> (BalanceInterval -> Encoding)
-> Entries RewardAddress BalanceInterval
-> Encoding
forall key value.
(key -> Encoding)
-> (value -> Encoding) -> Entries key value -> Encoding
association (ByteString -> Encoding
E.encodeBytes (ByteString -> Encoding)
-> (RewardAddress -> ByteString) -> RewardAddress -> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RewardAddress -> ByteString
Reward.toBytes) BalanceInterval -> Encoding
intervalEncoding) (Fields -> Maybe (Entries RewardAddress BalanceInterval)
fieldAccountBalanceIntervals Fields
value)
where
optional :: a -> (t -> b) -> Maybe t -> [(a, b)]
optional a
key t -> b
enc = [(a, b)] -> (t -> [(a, b)]) -> Maybe t -> [(a, b)]
forall b a. b -> (a -> b) -> Maybe a -> b
maybe [] (\t
payload -> [(a
key, t -> b
enc t
payload)])
hashEncoding :: Hash32 -> Encoding
hashEncoding = ByteString -> Encoding
E.encodeBytes (ByteString -> Encoding)
-> (Hash32 -> ByteString) -> Hash32 -> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Hash32 -> ByteString
Datum.hashBytes
inputSet :: [Input] -> E.Encoding
inputSet :: [Input] -> Encoding
inputSet [Input]
values = Word -> Encoding
E.encodeTag Word
258 Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word -> Encoding
E.encodeListLen (Int -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral ([Input] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Input]
values)) Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> (Input -> Encoding) -> [Input] -> Encoding
forall m a. Monoid m => (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (ByteString -> Encoding
Cbor.raw (ByteString -> Encoding)
-> (Input -> ByteString) -> Input -> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Input -> ByteString
Input.encodeCbor) ([Input] -> [Input]
forall a. Ord a => [a] -> [a]
sort [Input]
values)
outputList :: [Output] -> E.Encoding
outputList :: [Output] -> Encoding
outputList [Output]
values = Word -> Encoding
E.encodeListLen (Int -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral ([Output] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Output]
values)) Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> (Output -> Encoding) -> [Output] -> Encoding
forall m a. Monoid m => (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (ByteString -> Encoding
Cbor.raw (ByteString -> Encoding)
-> (Output -> ByteString) -> Output -> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Output -> ByteString
Output.encodeCbor) [Output]
values
association :: (key -> E.Encoding) -> (value -> E.Encoding) -> Entries key value -> E.Encoding
association :: forall key value.
(key -> Encoding)
-> (value -> Encoding) -> Entries key value -> Encoding
association key -> Encoding
encodeKey value -> Encoding
encodeValue Entries key value
values = Word -> Encoding
E.encodeMapLen (Int -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral ([(key, value)] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [(key, value)]
pairs)) Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> ((key, value) -> Encoding) -> [(key, value)] -> Encoding
forall m a. Monoid m => (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap (\(key
key, value
value) -> key -> Encoding
encodeKey key
key Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> value -> Encoding
encodeValue value
value) [(key, value)]
pairs
where
pairs :: [(key, value)]
pairs = ((key, value) -> ByteString) -> [(key, value)] -> [(key, value)]
forall b a. Ord b => (a -> b) -> [a] -> [a]
sortOn (Encoding -> ByteString
Cbor.encode (Encoding -> ByteString)
-> ((key, value) -> Encoding) -> (key, value) -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. key -> Encoding
encodeKey (key -> Encoding)
-> ((key, value) -> key) -> (key, value) -> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (key, value) -> key
forall a b. (a, b) -> a
fst) (Entries key value -> [(key, value)]
forall key value. Entries key value -> [(key, value)]
entries Entries key value
values)
guardSet :: [Credential Guard] -> E.Encoding
guardSet :: [Credential Guard] -> Encoding
guardSet [Credential Guard]
values = Word -> Encoding
E.encodeTag Word
258 Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word -> Encoding
E.encodeListLen (Int -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral ([Credential Guard] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Credential Guard]
values)) Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> (Credential Guard -> Encoding) -> [Credential Guard] -> Encoding
forall m a. Monoid m => (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap Credential Guard -> Encoding
forall purpose. Credential purpose -> Encoding
encodeGuard [Credential Guard]
values
where
credentialForm :: Bool
credentialForm = (Credential Guard -> Bool) -> [Credential Guard] -> Bool
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Bool
any Credential Guard -> Bool
forall {purpose}. Credential purpose -> Bool
isScript [Credential Guard]
values
isScript :: Credential purpose -> Bool
isScript (Credential.ScriptCredential ScriptHash
_) = Bool
True
isScript Credential purpose
_ = Bool
False
encodeGuard :: Credential purpose -> Encoding
encodeGuard Credential purpose
credential =
if Bool
credentialForm
then Credential purpose -> Encoding
forall purpose. Credential purpose -> Encoding
P.credentialEncoding Credential purpose
credential
else case Credential purpose
credential of
Credential.KeyCredential KeyHash purpose
hash -> ByteString -> Encoding
E.encodeBytes (KeyHash purpose -> ByteString
forall purpose. KeyHash purpose -> ByteString
Credential.keyHashBytes KeyHash purpose
hash)
Credential.ScriptCredential ScriptHash
hash -> ByteString -> Encoding
E.encodeBytes (ScriptHash -> ByteString
Credential.scriptHashBytes ScriptHash
hash)
intervalEncoding :: BalanceInterval -> E.Encoding
intervalEncoding :: BalanceInterval -> Encoding
intervalEncoding BalanceInterval
interval = case BalanceInterval
interval of
ExactBalance Word64
coin -> Word64 -> Encoding
E.encodeWord64 Word64
coin
BalanceRange Maybe Word64
lower Maybe Word64
upper -> Word -> Encoding
E.encodeListLen Word
2 Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Encoding -> (Word64 -> Encoding) -> Maybe Word64 -> Encoding
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Encoding
E.encodeNull Word64 -> Encoding
E.encodeWord64 Maybe Word64
lower Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Encoding -> (Word64 -> Encoding) -> Maybe Word64 -> Encoding
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Encoding
E.encodeNull Word64 -> Encoding
E.encodeWord64 Maybe Word64
upper
decodeFields :: Map Word64 ByteString -> Either Error Fields
decodeFields :: Map Word64 ByteString -> Either Error Fields
decodeFields Map Word64 ByteString
values =
[Input]
-> [Output]
-> Maybe Word64
-> Maybe Certificates
-> Maybe (Entries RewardAddress Word64)
-> Maybe Hash32
-> Maybe Word64
-> Maybe Mint
-> Maybe Hash32
-> Maybe [Credential Guard]
-> Maybe BodyNetwork
-> Maybe [Input]
-> Maybe VotingProcedures
-> Maybe Proposals
-> Maybe Word64
-> Maybe Word64
-> Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
-> Maybe (Entries RewardAddress Word64)
-> Maybe (Entries RewardAddress BalanceInterval)
-> Fields
Fields
([Input]
-> [Output]
-> Maybe Word64
-> Maybe Certificates
-> Maybe (Entries RewardAddress Word64)
-> Maybe Hash32
-> Maybe Word64
-> Maybe Mint
-> Maybe Hash32
-> Maybe [Credential Guard]
-> Maybe BodyNetwork
-> Maybe [Input]
-> Maybe VotingProcedures
-> Maybe Proposals
-> Maybe Word64
-> Maybe Word64
-> Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
-> Maybe (Entries RewardAddress Word64)
-> Maybe (Entries RewardAddress BalanceInterval)
-> Fields)
-> Either Error [Input]
-> Either
Error
([Output]
-> Maybe Word64
-> Maybe Certificates
-> Maybe (Entries RewardAddress Word64)
-> Maybe Hash32
-> Maybe Word64
-> Maybe Mint
-> Maybe Hash32
-> Maybe [Credential Guard]
-> Maybe BodyNetwork
-> Maybe [Input]
-> Maybe VotingProcedures
-> Maybe Proposals
-> Maybe Word64
-> Maybe Word64
-> Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
-> Maybe (Entries RewardAddress Word64)
-> Maybe (Entries RewardAddress BalanceInterval)
-> Fields)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Word64
-> (ByteString -> Either Error [Input]) -> Either Error [Input]
forall {b}.
Word64 -> (ByteString -> Either Error b) -> Either Error b
required Word64
0 ByteString -> Either Error [Input]
inputDecoder
Either
Error
([Output]
-> Maybe Word64
-> Maybe Certificates
-> Maybe (Entries RewardAddress Word64)
-> Maybe Hash32
-> Maybe Word64
-> Maybe Mint
-> Maybe Hash32
-> Maybe [Credential Guard]
-> Maybe BodyNetwork
-> Maybe [Input]
-> Maybe VotingProcedures
-> Maybe Proposals
-> Maybe Word64
-> Maybe Word64
-> Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
-> Maybe (Entries RewardAddress Word64)
-> Maybe (Entries RewardAddress BalanceInterval)
-> Fields)
-> Either Error [Output]
-> Either
Error
(Maybe Word64
-> Maybe Certificates
-> Maybe (Entries RewardAddress Word64)
-> Maybe Hash32
-> Maybe Word64
-> Maybe Mint
-> Maybe Hash32
-> Maybe [Credential Guard]
-> Maybe BodyNetwork
-> Maybe [Input]
-> Maybe VotingProcedures
-> Maybe Proposals
-> Maybe Word64
-> Maybe Word64
-> Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
-> Maybe (Entries RewardAddress Word64)
-> Maybe (Entries RewardAddress BalanceInterval)
-> Fields)
forall a b.
Either Error (a -> b) -> Either Error a -> Either Error b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Word64
-> (ByteString -> Either Error [Output]) -> Either Error [Output]
forall {b}.
Word64 -> (ByteString -> Either Error b) -> Either Error b
required Word64
1 ByteString -> Either Error [Output]
outputDecoder
Either
Error
(Maybe Word64
-> Maybe Certificates
-> Maybe (Entries RewardAddress Word64)
-> Maybe Hash32
-> Maybe Word64
-> Maybe Mint
-> Maybe Hash32
-> Maybe [Credential Guard]
-> Maybe BodyNetwork
-> Maybe [Input]
-> Maybe VotingProcedures
-> Maybe Proposals
-> Maybe Word64
-> Maybe Word64
-> Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
-> Maybe (Entries RewardAddress Word64)
-> Maybe (Entries RewardAddress BalanceInterval)
-> Fields)
-> Either Error (Maybe Word64)
-> Either
Error
(Maybe Certificates
-> Maybe (Entries RewardAddress Word64)
-> Maybe Hash32
-> Maybe Word64
-> Maybe Mint
-> Maybe Hash32
-> Maybe [Credential Guard]
-> Maybe BodyNetwork
-> Maybe [Input]
-> Maybe VotingProcedures
-> Maybe Proposals
-> Maybe Word64
-> Maybe Word64
-> Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
-> Maybe (Entries RewardAddress Word64)
-> Maybe (Entries RewardAddress BalanceInterval)
-> Fields)
forall a b.
Either Error (a -> b) -> Either Error a -> Either Error b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Word64
-> (ByteString -> Either Error Word64)
-> Either Error (Maybe Word64)
forall {f :: * -> *} {b}.
Applicative f =>
Word64 -> (ByteString -> f b) -> f (Maybe b)
optional Word64
3 ByteString -> Either Error Word64
word
Either
Error
(Maybe Certificates
-> Maybe (Entries RewardAddress Word64)
-> Maybe Hash32
-> Maybe Word64
-> Maybe Mint
-> Maybe Hash32
-> Maybe [Credential Guard]
-> Maybe BodyNetwork
-> Maybe [Input]
-> Maybe VotingProcedures
-> Maybe Proposals
-> Maybe Word64
-> Maybe Word64
-> Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
-> Maybe (Entries RewardAddress Word64)
-> Maybe (Entries RewardAddress BalanceInterval)
-> Fields)
-> Either Error (Maybe Certificates)
-> Either
Error
(Maybe (Entries RewardAddress Word64)
-> Maybe Hash32
-> Maybe Word64
-> Maybe Mint
-> Maybe Hash32
-> Maybe [Credential Guard]
-> Maybe BodyNetwork
-> Maybe [Input]
-> Maybe VotingProcedures
-> Maybe Proposals
-> Maybe Word64
-> Maybe Word64
-> Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
-> Maybe (Entries RewardAddress Word64)
-> Maybe (Entries RewardAddress BalanceInterval)
-> Fields)
forall a b.
Either Error (a -> b) -> Either Error a -> Either Error b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Word64
-> (ByteString -> Either Error Certificates)
-> Either Error (Maybe Certificates)
forall {f :: * -> *} {b}.
Applicative f =>
Word64 -> (ByteString -> f b) -> f (Maybe b)
optional Word64
4 ((EncodedCertificates -> Certificates)
-> Either Error EncodedCertificates -> Either Error Certificates
forall a b. (a -> b) -> Either Error a -> Either Error b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap EncodedCertificates -> Certificates
Certificates.toCertificates (Either Error EncodedCertificates -> Either Error Certificates)
-> (ByteString -> Either Error EncodedCertificates)
-> ByteString
-> Either Error Certificates
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Either Error EncodedCertificates
Certificates.decodeCbor)
Either
Error
(Maybe (Entries RewardAddress Word64)
-> Maybe Hash32
-> Maybe Word64
-> Maybe Mint
-> Maybe Hash32
-> Maybe [Credential Guard]
-> Maybe BodyNetwork
-> Maybe [Input]
-> Maybe VotingProcedures
-> Maybe Proposals
-> Maybe Word64
-> Maybe Word64
-> Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
-> Maybe (Entries RewardAddress Word64)
-> Maybe (Entries RewardAddress BalanceInterval)
-> Fields)
-> Either Error (Maybe (Entries RewardAddress Word64))
-> Either
Error
(Maybe Hash32
-> Maybe Word64
-> Maybe Mint
-> Maybe Hash32
-> Maybe [Credential Guard]
-> Maybe BodyNetwork
-> Maybe [Input]
-> Maybe VotingProcedures
-> Maybe Proposals
-> Maybe Word64
-> Maybe Word64
-> Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
-> Maybe (Entries RewardAddress Word64)
-> Maybe (Entries RewardAddress BalanceInterval)
-> Fields)
forall a b.
Either Error (a -> b) -> Either Error a -> Either Error b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Word64
-> (ByteString -> Either Error (Entries RewardAddress Word64))
-> Either Error (Maybe (Entries RewardAddress Word64))
forall {f :: * -> *} {b}.
Applicative f =>
Word64 -> (ByteString -> f b) -> f (Maybe b)
optional Word64
5 ((forall s. Decoder s RewardAddress)
-> (forall s. Decoder s Word64)
-> ByteString
-> Either Error (Entries RewardAddress Word64)
forall key value.
Ord key =>
(forall s. Decoder s key)
-> (forall s. Decoder s value)
-> ByteString
-> Either Error (Entries key value)
associationDecoder Decoder s RewardAddress
forall s. Decoder s RewardAddress
rewardDecoder Decoder s Word64
forall s. Decoder s Word64
D.decodeWord64)
Either
Error
(Maybe Hash32
-> Maybe Word64
-> Maybe Mint
-> Maybe Hash32
-> Maybe [Credential Guard]
-> Maybe BodyNetwork
-> Maybe [Input]
-> Maybe VotingProcedures
-> Maybe Proposals
-> Maybe Word64
-> Maybe Word64
-> Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
-> Maybe (Entries RewardAddress Word64)
-> Maybe (Entries RewardAddress BalanceInterval)
-> Fields)
-> Either Error (Maybe Hash32)
-> Either
Error
(Maybe Word64
-> Maybe Mint
-> Maybe Hash32
-> Maybe [Credential Guard]
-> Maybe BodyNetwork
-> Maybe [Input]
-> Maybe VotingProcedures
-> Maybe Proposals
-> Maybe Word64
-> Maybe Word64
-> Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
-> Maybe (Entries RewardAddress Word64)
-> Maybe (Entries RewardAddress BalanceInterval)
-> Fields)
forall a b.
Either Error (a -> b) -> Either Error a -> Either Error b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Word64
-> (ByteString -> Either Error Hash32)
-> Either Error (Maybe Hash32)
forall {f :: * -> *} {b}.
Applicative f =>
Word64 -> (ByteString -> f b) -> f (Maybe b)
optional Word64
7 ByteString -> Either Error Hash32
hashDecoder
Either
Error
(Maybe Word64
-> Maybe Mint
-> Maybe Hash32
-> Maybe [Credential Guard]
-> Maybe BodyNetwork
-> Maybe [Input]
-> Maybe VotingProcedures
-> Maybe Proposals
-> Maybe Word64
-> Maybe Word64
-> Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
-> Maybe (Entries RewardAddress Word64)
-> Maybe (Entries RewardAddress BalanceInterval)
-> Fields)
-> Either Error (Maybe Word64)
-> Either
Error
(Maybe Mint
-> Maybe Hash32
-> Maybe [Credential Guard]
-> Maybe BodyNetwork
-> Maybe [Input]
-> Maybe VotingProcedures
-> Maybe Proposals
-> Maybe Word64
-> Maybe Word64
-> Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
-> Maybe (Entries RewardAddress Word64)
-> Maybe (Entries RewardAddress BalanceInterval)
-> Fields)
forall a b.
Either Error (a -> b) -> Either Error a -> Either Error b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Word64
-> (ByteString -> Either Error Word64)
-> Either Error (Maybe Word64)
forall {f :: * -> *} {b}.
Applicative f =>
Word64 -> (ByteString -> f b) -> f (Maybe b)
optional Word64
8 ByteString -> Either Error Word64
word
Either
Error
(Maybe Mint
-> Maybe Hash32
-> Maybe [Credential Guard]
-> Maybe BodyNetwork
-> Maybe [Input]
-> Maybe VotingProcedures
-> Maybe Proposals
-> Maybe Word64
-> Maybe Word64
-> Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
-> Maybe (Entries RewardAddress Word64)
-> Maybe (Entries RewardAddress BalanceInterval)
-> Fields)
-> Either Error (Maybe Mint)
-> Either
Error
(Maybe Hash32
-> Maybe [Credential Guard]
-> Maybe BodyNetwork
-> Maybe [Input]
-> Maybe VotingProcedures
-> Maybe Proposals
-> Maybe Word64
-> Maybe Word64
-> Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
-> Maybe (Entries RewardAddress Word64)
-> Maybe (Entries RewardAddress BalanceInterval)
-> Fields)
forall a b.
Either Error (a -> b) -> Either Error a -> Either Error b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Word64
-> (ByteString -> Either Error Mint) -> Either Error (Maybe Mint)
forall {f :: * -> *} {b}.
Applicative f =>
Word64 -> (ByteString -> f b) -> f (Maybe b)
optional Word64
9 ByteString -> Either Error Mint
mintDecoder
Either
Error
(Maybe Hash32
-> Maybe [Credential Guard]
-> Maybe BodyNetwork
-> Maybe [Input]
-> Maybe VotingProcedures
-> Maybe Proposals
-> Maybe Word64
-> Maybe Word64
-> Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
-> Maybe (Entries RewardAddress Word64)
-> Maybe (Entries RewardAddress BalanceInterval)
-> Fields)
-> Either Error (Maybe Hash32)
-> Either
Error
(Maybe [Credential Guard]
-> Maybe BodyNetwork
-> Maybe [Input]
-> Maybe VotingProcedures
-> Maybe Proposals
-> Maybe Word64
-> Maybe Word64
-> Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
-> Maybe (Entries RewardAddress Word64)
-> Maybe (Entries RewardAddress BalanceInterval)
-> Fields)
forall a b.
Either Error (a -> b) -> Either Error a -> Either Error b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Word64
-> (ByteString -> Either Error Hash32)
-> Either Error (Maybe Hash32)
forall {f :: * -> *} {b}.
Applicative f =>
Word64 -> (ByteString -> f b) -> f (Maybe b)
optional Word64
11 ByteString -> Either Error Hash32
hashDecoder
Either
Error
(Maybe [Credential Guard]
-> Maybe BodyNetwork
-> Maybe [Input]
-> Maybe VotingProcedures
-> Maybe Proposals
-> Maybe Word64
-> Maybe Word64
-> Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
-> Maybe (Entries RewardAddress Word64)
-> Maybe (Entries RewardAddress BalanceInterval)
-> Fields)
-> Either Error (Maybe [Credential Guard])
-> Either
Error
(Maybe BodyNetwork
-> Maybe [Input]
-> Maybe VotingProcedures
-> Maybe Proposals
-> Maybe Word64
-> Maybe Word64
-> Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
-> Maybe (Entries RewardAddress Word64)
-> Maybe (Entries RewardAddress BalanceInterval)
-> Fields)
forall a b.
Either Error (a -> b) -> Either Error a -> Either Error b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Word64
-> (ByteString -> Either Error [Credential Guard])
-> Either Error (Maybe [Credential Guard])
forall {f :: * -> *} {b}.
Applicative f =>
Word64 -> (ByteString -> f b) -> f (Maybe b)
optional Word64
14 ByteString -> Either Error [Credential Guard]
forall {purpose}. ByteString -> Either Error [Credential purpose]
guardsDecoder
Either
Error
(Maybe BodyNetwork
-> Maybe [Input]
-> Maybe VotingProcedures
-> Maybe Proposals
-> Maybe Word64
-> Maybe Word64
-> Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
-> Maybe (Entries RewardAddress Word64)
-> Maybe (Entries RewardAddress BalanceInterval)
-> Fields)
-> Either Error (Maybe BodyNetwork)
-> Either
Error
(Maybe [Input]
-> Maybe VotingProcedures
-> Maybe Proposals
-> Maybe Word64
-> Maybe Word64
-> Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
-> Maybe (Entries RewardAddress Word64)
-> Maybe (Entries RewardAddress BalanceInterval)
-> Fields)
forall a b.
Either Error (a -> b) -> Either Error a -> Either Error b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Word64
-> (ByteString -> Either Error BodyNetwork)
-> Either Error (Maybe BodyNetwork)
forall {f :: * -> *} {b}.
Applicative f =>
Word64 -> (ByteString -> f b) -> f (Maybe b)
optional Word64
15 ByteString -> Either Error BodyNetwork
networkDecoder
Either
Error
(Maybe [Input]
-> Maybe VotingProcedures
-> Maybe Proposals
-> Maybe Word64
-> Maybe Word64
-> Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
-> Maybe (Entries RewardAddress Word64)
-> Maybe (Entries RewardAddress BalanceInterval)
-> Fields)
-> Either Error (Maybe [Input])
-> Either
Error
(Maybe VotingProcedures
-> Maybe Proposals
-> Maybe Word64
-> Maybe Word64
-> Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
-> Maybe (Entries RewardAddress Word64)
-> Maybe (Entries RewardAddress BalanceInterval)
-> Fields)
forall a b.
Either Error (a -> b) -> Either Error a -> Either Error b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Word64
-> (ByteString -> Either Error [Input])
-> Either Error (Maybe [Input])
forall {f :: * -> *} {b}.
Applicative f =>
Word64 -> (ByteString -> f b) -> f (Maybe b)
optional Word64
18 ByteString -> Either Error [Input]
inputDecoder
Either
Error
(Maybe VotingProcedures
-> Maybe Proposals
-> Maybe Word64
-> Maybe Word64
-> Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
-> Maybe (Entries RewardAddress Word64)
-> Maybe (Entries RewardAddress BalanceInterval)
-> Fields)
-> Either Error (Maybe VotingProcedures)
-> Either
Error
(Maybe Proposals
-> Maybe Word64
-> Maybe Word64
-> Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
-> Maybe (Entries RewardAddress Word64)
-> Maybe (Entries RewardAddress BalanceInterval)
-> Fields)
forall a b.
Either Error (a -> b) -> Either Error a -> Either Error b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Word64
-> (ByteString -> Either Error VotingProcedures)
-> Either Error (Maybe VotingProcedures)
forall {f :: * -> *} {b}.
Applicative f =>
Word64 -> (ByteString -> f b) -> f (Maybe b)
optional Word64
19 ((EncodedVotingProcedures -> VotingProcedures)
-> Either Error EncodedVotingProcedures
-> Either Error VotingProcedures
forall a b. (a -> b) -> Either Error a -> Either Error b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap EncodedVotingProcedures -> VotingProcedures
Voting.toVotingProcedures (Either Error EncodedVotingProcedures
-> Either Error VotingProcedures)
-> (ByteString -> Either Error EncodedVotingProcedures)
-> ByteString
-> Either Error VotingProcedures
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Either Error EncodedVotingProcedures
Voting.decodeCbor)
Either
Error
(Maybe Proposals
-> Maybe Word64
-> Maybe Word64
-> Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
-> Maybe (Entries RewardAddress Word64)
-> Maybe (Entries RewardAddress BalanceInterval)
-> Fields)
-> Either Error (Maybe Proposals)
-> Either
Error
(Maybe Word64
-> Maybe Word64
-> Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
-> Maybe (Entries RewardAddress Word64)
-> Maybe (Entries RewardAddress BalanceInterval)
-> Fields)
forall a b.
Either Error (a -> b) -> Either Error a -> Either Error b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Word64
-> (ByteString -> Either Error Proposals)
-> Either Error (Maybe Proposals)
forall {f :: * -> *} {b}.
Applicative f =>
Word64 -> (ByteString -> f b) -> f (Maybe b)
optional Word64
20 ((EncodedProposals -> Proposals)
-> Either Error EncodedProposals -> Either Error Proposals
forall a b. (a -> b) -> Either Error a -> Either Error b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap EncodedProposals -> Proposals
Proposal.toProposals (Either Error EncodedProposals -> Either Error Proposals)
-> (ByteString -> Either Error EncodedProposals)
-> ByteString
-> Either Error Proposals
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Either Error EncodedProposals
Proposal.decodeProposals)
Either
Error
(Maybe Word64
-> Maybe Word64
-> Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
-> Maybe (Entries RewardAddress Word64)
-> Maybe (Entries RewardAddress BalanceInterval)
-> Fields)
-> Either Error (Maybe Word64)
-> Either
Error
(Maybe Word64
-> Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
-> Maybe (Entries RewardAddress Word64)
-> Maybe (Entries RewardAddress BalanceInterval)
-> Fields)
forall a b.
Either Error (a -> b) -> Either Error a -> Either Error b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Word64
-> (ByteString -> Either Error Word64)
-> Either Error (Maybe Word64)
forall {f :: * -> *} {b}.
Applicative f =>
Word64 -> (ByteString -> f b) -> f (Maybe b)
optional Word64
21 ByteString -> Either Error Word64
word
Either
Error
(Maybe Word64
-> Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
-> Maybe (Entries RewardAddress Word64)
-> Maybe (Entries RewardAddress BalanceInterval)
-> Fields)
-> Either Error (Maybe Word64)
-> Either
Error
(Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
-> Maybe (Entries RewardAddress Word64)
-> Maybe (Entries RewardAddress BalanceInterval)
-> Fields)
forall a b.
Either Error (a -> b) -> Either Error a -> Either Error b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Word64
-> (ByteString -> Either Error Word64)
-> Either Error (Maybe Word64)
forall {f :: * -> *} {b}.
Applicative f =>
Word64 -> (ByteString -> f b) -> f (Maybe b)
optional Word64
22 ByteString -> Either Error Word64
word
Either
Error
(Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData))
-> Maybe (Entries RewardAddress Word64)
-> Maybe (Entries RewardAddress BalanceInterval)
-> Fields)
-> Either
Error
(Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData)))
-> Either
Error
(Maybe (Entries RewardAddress Word64)
-> Maybe (Entries RewardAddress BalanceInterval) -> Fields)
forall a b.
Either Error (a -> b) -> Either Error a -> Either Error b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Word64
-> (ByteString
-> Either
Error (Entries (Credential Guard) (Maybe EncodedPlutusData)))
-> Either
Error
(Maybe (Entries (Credential Guard) (Maybe EncodedPlutusData)))
forall {f :: * -> *} {b}.
Applicative f =>
Word64 -> (ByteString -> f b) -> f (Maybe b)
optional Word64
24 ByteString
-> Either
Error (Entries (Credential Guard) (Maybe EncodedPlutusData))
forall {purpose}.
ByteString
-> Either
Error (Entries (Credential purpose) (Maybe EncodedPlutusData))
requiredGuardsDecoder
Either
Error
(Maybe (Entries RewardAddress Word64)
-> Maybe (Entries RewardAddress BalanceInterval) -> Fields)
-> Either Error (Maybe (Entries RewardAddress Word64))
-> Either
Error (Maybe (Entries RewardAddress BalanceInterval) -> Fields)
forall a b.
Either Error (a -> b) -> Either Error a -> Either Error b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Word64
-> (ByteString -> Either Error (Entries RewardAddress Word64))
-> Either Error (Maybe (Entries RewardAddress Word64))
forall {f :: * -> *} {b}.
Applicative f =>
Word64 -> (ByteString -> f b) -> f (Maybe b)
optional Word64
25 ((forall s. Decoder s RewardAddress)
-> (forall s. Decoder s Word64)
-> ByteString
-> Either Error (Entries RewardAddress Word64)
forall key value.
Ord key =>
(forall s. Decoder s key)
-> (forall s. Decoder s value)
-> ByteString
-> Either Error (Entries key value)
associationDecoder Decoder s RewardAddress
forall s. Decoder s RewardAddress
rewardDecoder Decoder s Word64
forall s. Decoder s Word64
D.decodeWord64)
Either
Error (Maybe (Entries RewardAddress BalanceInterval) -> Fields)
-> Either Error (Maybe (Entries RewardAddress BalanceInterval))
-> Either Error Fields
forall a b.
Either Error (a -> b) -> Either Error a -> Either Error b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Word64
-> (ByteString
-> Either Error (Entries RewardAddress BalanceInterval))
-> Either Error (Maybe (Entries RewardAddress BalanceInterval))
forall {f :: * -> *} {b}.
Applicative f =>
Word64 -> (ByteString -> f b) -> f (Maybe b)
optional Word64
26 ((forall s. Decoder s RewardAddress)
-> (forall s. Decoder s BalanceInterval)
-> ByteString
-> Either Error (Entries RewardAddress BalanceInterval)
forall key value.
Ord key =>
(forall s. Decoder s key)
-> (forall s. Decoder s value)
-> ByteString
-> Either Error (Entries key value)
associationDecoder Decoder s RewardAddress
forall s. Decoder s RewardAddress
rewardDecoder Decoder s BalanceInterval
forall s. Decoder s BalanceInterval
intervalDecoder)
where
required :: Word64 -> (ByteString -> Either Error b) -> Either Error b
required Word64
key ByteString -> Either Error b
parser = Either Error b
-> (ByteString -> Either Error b)
-> Maybe ByteString
-> Either Error b
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Error -> Either Error b
forall a b. a -> Either a b
Left (Text -> Error
InvalidTransactionField Text
"Missing required transaction body field")) ByteString -> Either Error b
parser (Word64 -> Map Word64 ByteString -> Maybe ByteString
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Word64
key Map Word64 ByteString
values)
optional :: Word64 -> (ByteString -> f b) -> f (Maybe b)
optional Word64
key ByteString -> f b
parser = (ByteString -> f b) -> Maybe ByteString -> f (Maybe b)
forall (t :: * -> *) (f :: * -> *) a b.
(Traversable t, Applicative f) =>
(a -> f b) -> t a -> f (t b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Maybe a -> f (Maybe b)
traverse ByteString -> f b
parser (Word64 -> Map Word64 ByteString -> Maybe ByteString
forall k a. Ord k => k -> Map k a -> Maybe a
Map.lookup Word64
key Map Word64 ByteString
values)
word :: ByteString -> Either Error Word64
word = (forall s. Decoder s Word64) -> ByteString -> Either Error Word64
forall a. (forall s. Decoder s a) -> ByteString -> Either Error a
Cbor.decode Decoder s Word64
forall s. Decoder s Word64
D.decodeWord64
inputDecoder :: ByteString -> Either Error [Input]
inputDecoder ByteString
bytes = [Input] -> [Input]
forall a. Ord a => [a] -> [a]
sort ([Input] -> [Input])
-> Either Error [Input] -> Either Error [Input]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall s. Decoder s [Input]) -> ByteString -> Either Error [Input]
forall a. (forall s. Decoder s a) -> ByteString -> Either Error a
Cbor.decode (Decoder s Input -> Decoder s [Input]
forall s a. Decoder s a -> Decoder s [a]
Cbor.setList (ByteString -> (ByteString -> Either Error Input) -> Decoder s Input
forall a s.
ByteString -> (ByteString -> Either Error a) -> Decoder s a
Cbor.nested ByteString
bytes ByteString -> Either Error Input
Input.decodeCbor)) ByteString
bytes
outputDecoder :: ByteString -> Either Error [Output]
outputDecoder ByteString
bytes = (forall s. Decoder s [Output])
-> ByteString -> Either Error [Output]
forall a. (forall s. Decoder s a) -> ByteString -> Either Error a
Cbor.decode (Decoder s Output -> Decoder s [Output]
forall s a. Decoder s a -> Decoder s [a]
Cbor.list (EncodedOutput -> Output
Output.toOutput (EncodedOutput -> Output)
-> Decoder s EncodedOutput -> Decoder s Output
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> ByteString
-> (ByteString -> Either Error EncodedOutput)
-> Decoder s EncodedOutput
forall a s.
ByteString -> (ByteString -> Either Error a) -> Decoder s a
Cbor.nested ByteString
bytes ByteString -> Either Error EncodedOutput
Output.decodeCbor)) ByteString
bytes
hashDecoder :: ByteString -> Either Error Hash32
hashDecoder = (forall s. Decoder s Hash32) -> ByteString -> Either Error Hash32
forall a. (forall s. Decoder s a) -> ByteString -> Either Error a
Cbor.decode (Decoder s ByteString
forall s. Decoder s ByteString
D.decodeBytes Decoder s ByteString
-> (ByteString -> Decoder s Hash32) -> Decoder s Hash32
forall a b. Decoder s a -> (a -> Decoder s b) -> Decoder s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Error -> Decoder s Hash32)
-> (Hash32 -> Decoder s Hash32)
-> Either Error Hash32
-> Decoder s Hash32
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (String -> Decoder s Hash32
forall a. String -> Decoder s a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Decoder s Hash32)
-> (Error -> String) -> Error -> Decoder s Hash32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Error -> String
forall a. Show a => a -> String
show) Hash32 -> Decoder s Hash32
forall a. a -> Decoder s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either Error Hash32 -> Decoder s Hash32)
-> (ByteString -> Either Error Hash32)
-> ByteString
-> Decoder s Hash32
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Either Error Hash32
Datum.hashFromBytes)
mintDecoder :: ByteString -> Either Error Mint
mintDecoder ByteString
bytes = (forall s. Decoder s Value) -> ByteString -> Either Error Value
forall a. (forall s. Decoder s a) -> ByteString -> Either Error a
Cbor.decode Decoder s Value
forall s. Decoder s Value
V.decodeAssets ByteString
bytes Either Error Value
-> (Value -> Either Error Mint) -> Either Error Mint
forall a b.
Either Error a -> (a -> Either Error b) -> Either Error b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= Value -> Either Error Mint
mkMint
networkDecoder :: ByteString -> Either Error BodyNetwork
networkDecoder ByteString
bytes = do
Word
value <- (forall s. Decoder s Word) -> ByteString -> Either Error Word
forall a. (forall s. Decoder s a) -> ByteString -> Either Error a
Cbor.decode Decoder s Word
forall s. Decoder s Word
D.decodeWord ByteString
bytes
case Word
value of
Word
0 -> BodyNetwork -> Either Error BodyNetwork
forall a b. b -> Either a b
Right BodyNetwork
Testnet
Word
1 -> BodyNetwork -> Either Error BodyNetwork
forall a b. b -> Either a b
Right BodyNetwork
Mainnet
Word
_ -> Error -> Either Error BodyNetwork
forall a b. a -> Either a b
Left (Text -> Error
InvalidTransactionField Text
"Body network id must be 0 or 1")
guardsDecoder :: ByteString -> Either Error [Credential purpose]
guardsDecoder ByteString
bytes = do
[Credential purpose]
guards <- (forall s. Decoder s [Credential purpose])
-> ByteString -> Either Error [Credential purpose]
forall a. (forall s. Decoder s a) -> ByteString -> Either Error a
Cbor.decode (Decoder s (Credential purpose) -> Decoder s [Credential purpose]
forall s a. Decoder s a -> Decoder s [a]
Cbor.setList Decoder s (Credential purpose)
forall {s} {purpose}. Decoder s (Credential purpose)
guardDecoder) ByteString
bytes
Bool -> Either Error () -> Either Error ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Set (Credential purpose) -> Int
forall a. Set a -> Int
Set.size ([Credential purpose] -> Set (Credential purpose)
forall a. Ord a => [a] -> Set a
Set.fromList [Credential purpose]
guards) Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== [Credential purpose] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Credential purpose]
guards) (Error -> Either Error ()
forall a b. a -> Either a b
Left (Text -> Error
InvalidTransactionField Text
"Duplicate guard credential"))
[Credential purpose] -> Either Error [Credential purpose]
forall a. a -> Either Error a
forall (f :: * -> *) a. Applicative f => a -> f a
pure [Credential purpose]
guards
guardDecoder :: Decoder s (Credential purpose)
guardDecoder = do
TokenType
token <- Decoder s TokenType
forall s. Decoder s TokenType
D.peekTokenType
if TokenType
token TokenType -> TokenType -> Bool
forall a. Eq a => a -> a -> Bool
== TokenType
D.TypeBytes then KeyHash purpose -> Credential purpose
forall purpose. KeyHash purpose -> Credential purpose
Credential.KeyCredential (KeyHash purpose -> Credential purpose)
-> Decoder s (KeyHash purpose) -> Decoder s (Credential purpose)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Decoder s ByteString
forall s. Decoder s ByteString
D.decodeBytes Decoder s ByteString
-> (ByteString -> Decoder s (KeyHash purpose))
-> Decoder s (KeyHash purpose)
forall a b. Decoder s a -> (a -> Decoder s b) -> Decoder s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Error -> Decoder s (KeyHash purpose))
-> (KeyHash purpose -> Decoder s (KeyHash purpose))
-> Either Error (KeyHash purpose)
-> Decoder s (KeyHash purpose)
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (String -> Decoder s (KeyHash purpose)
forall a. String -> Decoder s a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Decoder s (KeyHash purpose))
-> (Error -> String) -> Error -> Decoder s (KeyHash purpose)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Error -> String
forall a. Show a => a -> String
show) KeyHash purpose -> Decoder s (KeyHash purpose)
forall a. a -> Decoder s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either Error (KeyHash purpose) -> Decoder s (KeyHash purpose))
-> (ByteString -> Either Error (KeyHash purpose))
-> ByteString
-> Decoder s (KeyHash purpose)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Either Error (KeyHash purpose)
forall purpose. ByteString -> Either Error (KeyHash purpose)
Credential.keyHashFromBytes) else Decoder s (Credential purpose)
forall {s} {purpose}. Decoder s (Credential purpose)
P.credentialDecoder
requiredGuardsDecoder :: ByteString
-> Either
Error (Entries (Credential purpose) (Maybe EncodedPlutusData))
requiredGuardsDecoder ByteString
bytes = (forall s. Decoder s (Credential purpose))
-> (forall s. Decoder s (Maybe EncodedPlutusData))
-> ByteString
-> Either
Error (Entries (Credential purpose) (Maybe EncodedPlutusData))
forall key value.
Ord key =>
(forall s. Decoder s key)
-> (forall s. Decoder s value)
-> ByteString
-> Either Error (Entries key value)
associationDecoder Decoder s (Credential purpose)
forall s. Decoder s (Credential purpose)
forall {s} {purpose}. Decoder s (Credential purpose)
P.credentialDecoder (Decoder s EncodedPlutusData -> Decoder s (Maybe EncodedPlutusData)
forall s a. Decoder s a -> Decoder s (Maybe a)
Cbor.optional (ByteString
-> (ByteString -> Either Error EncodedPlutusData)
-> Decoder s EncodedPlutusData
forall a s.
ByteString -> (ByteString -> Either Error a) -> Decoder s a
Cbor.nested ByteString
bytes ByteString -> Either Error EncodedPlutusData
Data.decodeCbor)) ByteString
bytes
rewardDecoder :: D.Decoder s RewardAddress
rewardDecoder :: forall s. Decoder s RewardAddress
rewardDecoder = Decoder s ByteString
forall s. Decoder s ByteString
D.decodeBytes Decoder s ByteString
-> (ByteString -> Decoder s RewardAddress)
-> Decoder s RewardAddress
forall a b. Decoder s a -> (a -> Decoder s b) -> Decoder s b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= (Error -> Decoder s RewardAddress)
-> (RewardAddress -> Decoder s RewardAddress)
-> Either Error RewardAddress
-> Decoder s RewardAddress
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (String -> Decoder s RewardAddress
forall a. String -> Decoder s a
forall (m :: * -> *) a. MonadFail m => String -> m a
fail (String -> Decoder s RewardAddress)
-> (Error -> String) -> Error -> Decoder s RewardAddress
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Error -> String
forall a. Show a => a -> String
show) RewardAddress -> Decoder s RewardAddress
forall a. a -> Decoder s a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either Error RewardAddress -> Decoder s RewardAddress)
-> (ByteString -> Either Error RewardAddress)
-> ByteString
-> Decoder s RewardAddress
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Either Error RewardAddress
Reward.fromBytes
associationDecoder :: (Ord key) => (forall s. D.Decoder s key) -> (forall s. D.Decoder s value) -> ByteString -> Either Error (Entries key value)
associationDecoder :: forall key value.
Ord key =>
(forall s. Decoder s key)
-> (forall s. Decoder s value)
-> ByteString
-> Either Error (Entries key value)
associationDecoder forall s. Decoder s key
keyParser forall s. Decoder s value
valueParser ByteString
bytes = (forall s. Decoder s [(key, value)])
-> ByteString -> Either Error [(key, value)]
forall a. (forall s. Decoder s a) -> ByteString -> Either Error a
Cbor.decode (Decoder s (key, value) -> Decoder s [(key, value)]
forall s a. Decoder s a -> Decoder s [a]
Cbor.entries ((,) (key -> value -> (key, value))
-> Decoder s key -> Decoder s (value -> (key, value))
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s key
forall s. Decoder s key
keyParser Decoder s (value -> (key, value))
-> Decoder s value -> Decoder s (key, value)
forall a b. Decoder s (a -> b) -> Decoder s a -> Decoder s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s value
forall s. Decoder s value
valueParser)) ByteString
bytes Either Error [(key, value)]
-> ([(key, value)] -> Either Error (Entries key value))
-> Either Error (Entries key value)
forall a b.
Either Error a -> (a -> Either Error b) -> Either Error b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= [(key, value)] -> Either Error (Entries key value)
forall key value.
Ord key =>
[(key, value)] -> Either Error (Entries key value)
mkEntries
intervalDecoder :: D.Decoder s BalanceInterval
intervalDecoder :: forall s. Decoder s BalanceInterval
intervalDecoder = do
TokenType
token <- Decoder s TokenType
forall s. Decoder s TokenType
D.peekTokenType
if TokenType
token TokenType -> TokenType -> Bool
forall a. Eq a => a -> a -> Bool
== TokenType
D.TypeUInt Bool -> Bool -> Bool
|| TokenType
token TokenType -> TokenType -> Bool
forall a. Eq a => a -> a -> Bool
== TokenType
D.TypeUInt64
then Word64 -> BalanceInterval
ExactBalance (Word64 -> BalanceInterval)
-> Decoder s Word64 -> Decoder s BalanceInterval
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word64
forall s. Decoder s Word64
D.decodeWord64
else Int -> Decoder s BalanceInterval -> Decoder s BalanceInterval
forall s a. Int -> Decoder s a -> Decoder s a
Cbor.array Int
2 (Maybe Word64 -> Maybe Word64 -> BalanceInterval
BalanceRange (Maybe Word64 -> Maybe Word64 -> BalanceInterval)
-> Decoder s (Maybe Word64)
-> Decoder s (Maybe Word64 -> BalanceInterval)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Decoder s Word64 -> Decoder s (Maybe Word64)
forall s a. Decoder s a -> Decoder s (Maybe a)
Cbor.optional Decoder s Word64
forall s. Decoder s Word64
D.decodeWord64 Decoder s (Maybe Word64 -> BalanceInterval)
-> Decoder s (Maybe Word64) -> Decoder s BalanceInterval
forall a b. Decoder s (a -> b) -> Decoder s a -> Decoder s b
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
<*> Decoder s Word64 -> Decoder s (Maybe Word64)
forall s a. Decoder s a -> Decoder s (Maybe a)
Cbor.optional Decoder s Word64
forall s. Decoder s Word64
D.decodeWord64)
validateFields :: Bool -> Fields -> Either Error ()
validateFields :: Bool -> Fields -> Either Error ()
validateFields Bool
isSub Fields
value = do
case Fields -> Maybe [Credential Guard]
fieldGuards Fields
value of
Maybe [Credential Guard]
Nothing -> () -> Either Error ()
forall a. a -> Either Error a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
Just [Credential Guard]
guards -> do
Bool -> Either Error () -> Either Error ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when ([Credential Guard] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [Credential Guard]
guards) (Error -> Either Error ()
forall a b. a -> Either a b
Left (Text -> Error
InvalidTransactionField Text
"Present guard set must be nonempty"))
Bool -> Either Error () -> Either Error ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Set (Credential Guard) -> Int
forall a. Set a -> Int
Set.size ([Credential Guard] -> Set (Credential Guard)
forall a. Ord a => [a] -> Set a
Set.fromList [Credential Guard]
guards) Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== [Credential Guard] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Credential Guard]
guards) (Error -> Either Error ()
forall a b. a -> Either a b
Left (Text -> Error
InvalidTransactionField Text
"Duplicate guard credential"))
Bool -> Either Error () -> Either Error ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when Bool
isSub (Either Error () -> Either Error ())
-> Either Error () -> Either Error ()
forall a b. (a -> b) -> a -> b
$ do
case Fields -> Maybe Certificates
fieldCertificates Fields
value of
Just Certificates
certs -> Bool -> Either Error () -> Either Error ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when ([Certificate] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null (Certificates -> [Certificate]
Certificates.toList Certificates
certs)) (Error -> Either Error ()
forall a b. a -> Either a b
Left (Text -> Error
InvalidTransactionField Text
"Present subtransaction certificates must be nonempty"))
Maybe Certificates
Nothing -> () -> Either Error ()
forall a. a -> Either Error a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
case Fields -> Maybe Mint
fieldMint Fields
value of
Just Mint
mint -> Bool -> Either Error () -> Either Error ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Value -> Bool
Value.isZero (Mint -> Value
mintValue Mint
mint)) (Error -> Either Error ()
forall a b. a -> Either a b
Left (Text -> Error
InvalidTransactionField Text
"Present subtransaction mint must be nonempty"))
Maybe Mint
Nothing -> () -> Either Error ()
forall a. a -> Either Error a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
encodeIntervals :: Entries RewardAddress BalanceInterval -> E.Encoding
encodeIntervals :: Entries RewardAddress BalanceInterval -> Encoding
encodeIntervals = (RewardAddress -> Encoding)
-> (BalanceInterval -> Encoding)
-> Entries RewardAddress BalanceInterval
-> Encoding
forall key value.
(key -> Encoding)
-> (value -> Encoding) -> Entries key value -> Encoding
association (ByteString -> Encoding
E.encodeBytes (ByteString -> Encoding)
-> (RewardAddress -> ByteString) -> RewardAddress -> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RewardAddress -> ByteString
Reward.toBytes) BalanceInterval -> Encoding
intervalEncoding
decodeIntervals :: ByteString -> Either Error (Entries RewardAddress BalanceInterval)
decodeIntervals :: ByteString -> Either Error (Entries RewardAddress BalanceInterval)
decodeIntervals = (forall s. Decoder s RewardAddress)
-> (forall s. Decoder s BalanceInterval)
-> ByteString
-> Either Error (Entries RewardAddress BalanceInterval)
forall key value.
Ord key =>
(forall s. Decoder s key)
-> (forall s. Decoder s value)
-> ByteString
-> Either Error (Entries key value)
associationDecoder Decoder s RewardAddress
forall s. Decoder s RewardAddress
rewardDecoder Decoder s BalanceInterval
forall s. Decoder s BalanceInterval
intervalDecoder