{-# LANGUAGE OverloadedStrings #-}
module Cometa.Inspection
( transaction,
subTransaction,
body,
subBody,
value,
script,
nativeScript,
plutusScript,
credential,
certificate,
governanceAction,
proposal,
poolParameters,
protocolUpdate,
plutusData,
output,
witnesses,
utxo,
drep,
actionId,
anchor,
votingProcedures,
metadatum,
metadata,
auxiliaryData,
input,
datum,
redeemer,
exUnits,
protocolVersion,
unitInterval,
relay,
poolMetadata,
constitution,
voter,
votingProcedure,
verificationWitness,
bootstrapWitness,
costModel,
costModels,
exUnitPrices,
poolVotingThresholds,
drepVotingThresholds,
proposedUpdates,
updateProposal,
balanceInterval,
balanceIntervals,
directDeposits,
requiredGuards,
assetName,
blake2bHash,
blsKey,
committeeMembers,
withdrawals,
hashes,
guards,
subTransactions,
assets,
assetEntries,
policyAssets,
policyAssetEntries,
)
where
import qualified Codec.CBOR.Encoding as Encoding
import qualified Codec.CBOR.Write as Write
import qualified Cometa.Address.Reward as Reward
import qualified Cometa.AssetName as Name
import qualified Cometa.Certificate as Certificate
import qualified Cometa.Credential as Credential
import qualified Cometa.Crypto.Blake2b as Hash
import qualified Cometa.Encoding.Collections as Collections
import Cometa.Error (Error (InvalidValueCbor, NativeContractViolation))
import qualified Cometa.Governance.Action as Action
import qualified Cometa.Governance.ActionId as ActionId
import qualified Cometa.Governance.Anchor as Anchor
import qualified Cometa.Governance.Committee as Committee
import qualified Cometa.Governance.Constitution as Constitution
import qualified Cometa.Governance.DRep as DRep
import qualified Cometa.Governance.Proposal as Proposal
import qualified Cometa.Governance.Voting as Voting
import qualified Cometa.Internal.Inspection as Internal
import qualified Cometa.Metadata as Metadata
import qualified Cometa.PlutusData as Data
import qualified Cometa.PolicyId as Policy
import qualified Cometa.Pool.BlsKey as Bls
import qualified Cometa.Pool.Metadata as PoolMetadata
import qualified Cometa.Pool.Parameters as Pool
import qualified Cometa.Pool.Relay as Relay
import qualified Cometa.Protocol.CostModels as Models
import qualified Cometa.Protocol.DRepVotingThresholds as DRepThresholds
import qualified Cometa.Protocol.ExUnitPrices as Prices
import qualified Cometa.Protocol.ExUnits as ExUnits
import qualified Cometa.Protocol.Parameters.Update as Update
import qualified Cometa.Protocol.PoolVotingThresholds as PoolThresholds
import qualified Cometa.Protocol.ProposedUpdates as Proposed
import qualified Cometa.Protocol.Version as Version
import qualified Cometa.Script as Script
import qualified Cometa.Script.Native as Native
import qualified Cometa.Script.Plutus as Plutus
import qualified Cometa.SubTransaction as Sub
import qualified Cometa.Transaction.AuxiliaryData as Auxiliary
import qualified Cometa.Transaction.Datum as Datum
import qualified Cometa.Transaction.Fields as Fields
import qualified Cometa.Transaction.Input as Input
import Cometa.Transaction.Inspection (body, subBody, subTransaction, transaction)
import qualified Cometa.Transaction.Output as Output
import qualified Cometa.Transaction.Redeemer as Redeemer
import qualified Cometa.Transaction.Utxo as Utxo
import qualified Cometa.Transaction.Witness as Witness
import qualified Cometa.Transaction.Witnesses as Witnesses
import qualified Cometa.UnitInterval as Unit
import qualified Cometa.Value as Value
import Control.Monad (unless)
import Data.Aeson (Value (Object), toJSON)
import qualified Data.Aeson.KeyMap as KeyMap
import Data.ByteString (ByteString)
import Data.List (sortOn)
import qualified Data.Map.Strict as Map
import qualified Data.Set as Set
import Data.Text (Text)
import Data.Word (Word64)
import Foreign.C.Types (CUInt)
value :: Value.Value -> IO (Either Error Value)
value :: Value -> IO (Either Error Value)
value Value
amount = case Value -> Either Error ByteString
Value.encodeCbor Value
amount of
Left Error
failure -> Either Error Value -> IO (Either Error Value)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Error -> Either Error Value
forall a b. a -> Either a b
Left Error
failure)
Right ByteString
bytes -> Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.value" CUInt
4 ByteString
bytes
script :: Script.Script -> IO (Either Error Value)
script :: Script -> IO (Either Error Value)
script = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.script" CUInt
5 (ByteString -> IO (Either Error Value))
-> (Script -> ByteString) -> Script -> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Script -> ByteString
Script.encodeCbor
nativeScript :: Native.NativeScript -> IO (Either Error Value)
nativeScript :: NativeScript -> IO (Either Error Value)
nativeScript = Script -> IO (Either Error Value)
scriptPayload (Script -> IO (Either Error Value))
-> (NativeScript -> Script)
-> NativeScript
-> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NativeScript -> Script
Script.Native
plutusScript :: Plutus.PlutusScript -> IO (Either Error Value)
plutusScript :: PlutusScript -> IO (Either Error Value)
plutusScript = Script -> IO (Either Error Value)
scriptPayload (Script -> IO (Either Error Value))
-> (PlutusScript -> Script)
-> PlutusScript
-> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PlutusScript -> Script
Script.Plutus
scriptPayload :: Script.Script -> IO (Either Error Value)
scriptPayload :: Script -> IO (Either Error Value)
scriptPayload Script
suppliedScript = do
Either Error Value
result <- Script -> IO (Either Error Value)
script Script
suppliedScript
Either Error Value -> IO (Either Error Value)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either Error Value -> IO (Either Error Value))
-> Either Error Value -> IO (Either Error Value)
forall a b. (a -> b) -> a -> b
$ do
Value
json <- Either Error Value
result
case Value
json of
Object Object
fields -> Either Error Value
-> (Value -> Either Error Value)
-> Maybe Value
-> Either Error Value
forall b a. b -> (a -> b) -> Maybe a -> b
maybe Either Error Value
forall {b}. Either Error b
failure Value -> Either Error Value
forall a b. b -> Either a b
Right (Key -> Object -> Maybe Value
forall v. Key -> KeyMap v -> Maybe v
KeyMap.lookup Key
"value" Object
fields)
Value
_ -> Either Error Value
forall {b}. Either Error b
failure
where
failure :: Either Error b
failure = Error -> Either Error b
forall a b. a -> Either a b
Left (Text -> Error
NativeContractViolation Text
"inspection.script.payload")
credential :: Credential.Credential purpose -> IO (Either Error Value)
credential :: forall purpose. Credential purpose -> IO (Either Error Value)
credential = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.credential" CUInt
6 (ByteString -> IO (Either Error Value))
-> (Credential purpose -> ByteString)
-> Credential purpose
-> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Credential purpose -> ByteString
forall purpose. Credential purpose -> ByteString
Credential.encodeCbor
certificate :: Certificate.Certificate -> IO (Either Error Value)
certificate :: Certificate -> IO (Either Error Value)
certificate = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.certificate" CUInt
7 (ByteString -> IO (Either Error Value))
-> (Certificate -> ByteString)
-> Certificate
-> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Certificate -> ByteString
Certificate.encodeCbor
governanceAction :: Action.Action -> IO (Either Error Value)
governanceAction :: Action -> IO (Either Error Value)
governanceAction = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.governanceAction" CUInt
19 (ByteString -> IO (Either Error Value))
-> (Action -> ByteString) -> Action -> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Action -> ByteString
Action.encodeCbor
proposal :: Proposal.Proposal -> IO (Either Error Value)
proposal :: Proposal -> IO (Either Error Value)
proposal = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.proposal" CUInt
8 (ByteString -> IO (Either Error Value))
-> (Proposal -> ByteString) -> Proposal -> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Proposal -> ByteString
Proposal.encodeCbor
poolParameters :: Pool.PoolParameters -> IO (Either Error Value)
poolParameters :: PoolParameters -> IO (Either Error Value)
poolParameters = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.poolParameters" CUInt
9 (ByteString -> IO (Either Error Value))
-> (PoolParameters -> ByteString)
-> PoolParameters
-> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PoolParameters -> ByteString
Pool.encodeCbor
protocolUpdate :: Update.Update -> IO (Either Error Value)
protocolUpdate :: Update -> IO (Either Error Value)
protocolUpdate = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.protocolUpdate" CUInt
10 (ByteString -> IO (Either Error Value))
-> (Update -> ByteString) -> Update -> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Update -> ByteString
Update.encodeCbor
plutusData :: Data.EncodedPlutusData -> IO (Either Error Value)
plutusData :: EncodedPlutusData -> IO (Either Error Value)
plutusData = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.plutusData" CUInt
11 (ByteString -> IO (Either Error Value))
-> (EncodedPlutusData -> ByteString)
-> EncodedPlutusData
-> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EncodedPlutusData -> ByteString
Data.toCbor
output :: Output.Output -> IO (Either Error Value)
output :: Output -> IO (Either Error Value)
output = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.output" CUInt
12 (ByteString -> IO (Either Error Value))
-> (Output -> ByteString) -> Output -> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Output -> ByteString
Output.encodeCbor
witnesses :: Witnesses.EncodedWitnesses -> IO (Either Error Value)
witnesses :: EncodedWitnesses -> IO (Either Error Value)
witnesses = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.witnesses" CUInt
13 (ByteString -> IO (Either Error Value))
-> (EncodedWitnesses -> ByteString)
-> EncodedWitnesses
-> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EncodedWitnesses -> ByteString
Witnesses.toCbor
utxo :: Utxo.Utxo -> IO (Either Error Value)
utxo :: Utxo -> IO (Either Error Value)
utxo = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.utxo" CUInt
14 (ByteString -> IO (Either Error Value))
-> (Utxo -> ByteString) -> Utxo -> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Utxo -> ByteString
Utxo.encodeCbor
drep :: DRep.DRep -> IO (Either Error Value)
drep :: DRep -> IO (Either Error Value)
drep = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.drep" CUInt
15 (ByteString -> IO (Either Error Value))
-> (DRep -> ByteString) -> DRep -> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DRep -> ByteString
DRep.encodeCbor
actionId :: ActionId.ActionId -> IO (Either Error Value)
actionId :: ActionId -> IO (Either Error Value)
actionId = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.actionId" CUInt
16 (ByteString -> IO (Either Error Value))
-> (ActionId -> ByteString) -> ActionId -> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ActionId -> ByteString
ActionId.encodeCbor
anchor :: Anchor.Anchor -> IO (Either Error Value)
anchor :: Anchor -> IO (Either Error Value)
anchor = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.anchor" CUInt
17 (ByteString -> IO (Either Error Value))
-> (Anchor -> ByteString) -> Anchor -> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Anchor -> ByteString
Anchor.encodeCbor
votingProcedures :: Voting.VotingProcedures -> IO (Either Error Value)
votingProcedures :: VotingProcedures -> IO (Either Error Value)
votingProcedures = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.votingProcedures" CUInt
18 (ByteString -> IO (Either Error Value))
-> (VotingProcedures -> ByteString)
-> VotingProcedures
-> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. VotingProcedures -> ByteString
Voting.encodeCbor
metadatum :: Metadata.Metadatum -> IO (Either Error Value)
metadatum :: Metadatum -> IO (Either Error Value)
metadatum = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.metadatum" CUInt
20 (ByteString -> IO (Either Error Value))
-> (Metadatum -> ByteString)
-> Metadatum
-> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Metadatum -> ByteString
Metadata.encodeMetadatumCbor
metadata :: Metadata.Metadata -> IO (Either Error Value)
metadata :: Metadata -> IO (Either Error Value)
metadata = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.metadata" CUInt
21 (ByteString -> IO (Either Error Value))
-> (Metadata -> ByteString) -> Metadata -> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Metadata -> ByteString
Metadata.encodeCbor
auxiliaryData :: Auxiliary.EncodedAuxiliaryData -> IO (Either Error Value)
auxiliaryData :: EncodedAuxiliaryData -> IO (Either Error Value)
auxiliaryData = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.auxiliaryData" CUInt
22 (ByteString -> IO (Either Error Value))
-> (EncodedAuxiliaryData -> ByteString)
-> EncodedAuxiliaryData
-> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. EncodedAuxiliaryData -> ByteString
Auxiliary.toCbor
input :: Input.Input -> IO (Either Error Value)
input :: Input -> IO (Either Error Value)
input = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.input" CUInt
23 (ByteString -> IO (Either Error Value))
-> (Input -> ByteString) -> Input -> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Input -> ByteString
Input.encodeCbor
datum :: Datum.Datum -> IO (Either Error (Maybe Value))
datum :: Datum -> IO (Either Error (Maybe Value))
datum Datum
Datum.NoDatum = Either Error (Maybe Value) -> IO (Either Error (Maybe Value))
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Maybe Value -> Either Error (Maybe Value)
forall a b. b -> Either a b
Right Maybe Value
forall a. Maybe a
Nothing)
datum (Datum.DatumHash Hash32
hash) = Encoding -> IO (Either Error (Maybe Value))
inspectDatum (Word -> Encoding
Encoding.encodeListLen Word
2 Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word -> Encoding
Encoding.encodeWord Word
0 Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> ByteString -> Encoding
Encoding.encodeBytes (Hash32 -> ByteString
Datum.hashBytes Hash32
hash))
datum (Datum.InlineDatum EncodedPlutusData
payload) = Encoding -> IO (Either Error (Maybe Value))
inspectDatum (Word -> Encoding
Encoding.encodeListLen Word
2 Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word -> Encoding
Encoding.encodeWord Word
1 Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word -> Encoding
Encoding.encodeTag Word
24 Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> ByteString -> Encoding
Encoding.encodeBytes (EncodedPlutusData -> ByteString
Data.toCbor EncodedPlutusData
payload))
inspectDatum :: Encoding.Encoding -> IO (Either Error (Maybe Value))
inspectDatum :: Encoding -> IO (Either Error (Maybe Value))
inspectDatum = (Either Error Value -> Either Error (Maybe Value))
-> IO (Either Error Value) -> IO (Either Error (Maybe Value))
forall a b. (a -> b) -> IO a -> IO b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((Value -> Maybe Value)
-> Either Error Value -> Either Error (Maybe Value)
forall a b. (a -> b) -> Either Error a -> Either Error b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Value -> Maybe Value
forall a. a -> Maybe a
Just) (IO (Either Error Value) -> IO (Either Error (Maybe Value)))
-> (Encoding -> IO (Either Error Value))
-> Encoding
-> IO (Either Error (Maybe Value))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.datum" CUInt
24 (ByteString -> IO (Either Error Value))
-> (Encoding -> ByteString) -> Encoding -> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Encoding -> ByteString
Write.toStrictByteString
redeemer :: Redeemer.Redeemer -> IO (Either Error Value)
redeemer :: Redeemer -> IO (Either Error Value)
redeemer = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.redeemer" CUInt
25 (ByteString -> IO (Either Error Value))
-> (Redeemer -> ByteString) -> Redeemer -> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Redeemer -> ByteString
Redeemer.encodeCbor
exUnits :: ExUnits.ExUnits -> IO (Either Error Value)
exUnits :: ExUnits -> IO (Either Error Value)
exUnits = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.exUnits" CUInt
26 (ByteString -> IO (Either Error Value))
-> (ExUnits -> ByteString) -> ExUnits -> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExUnits -> ByteString
ExUnits.encodeCbor
protocolVersion :: Version.ProtocolVersion -> IO (Either Error Value)
protocolVersion :: ProtocolVersion -> IO (Either Error Value)
protocolVersion = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.protocolVersion" CUInt
27 (ByteString -> IO (Either Error Value))
-> (ProtocolVersion -> ByteString)
-> ProtocolVersion
-> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ProtocolVersion -> ByteString
Version.encodeCbor
unitInterval :: Unit.UnitInterval -> IO (Either Error Value)
unitInterval :: UnitInterval -> IO (Either Error Value)
unitInterval = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.unitInterval" CUInt
28 (ByteString -> IO (Either Error Value))
-> (UnitInterval -> ByteString)
-> UnitInterval
-> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UnitInterval -> ByteString
Unit.encodeCbor
relay :: Relay.Relay -> IO (Either Error Value)
relay :: Relay -> IO (Either Error Value)
relay = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.relay" CUInt
29 (ByteString -> IO (Either Error Value))
-> (Relay -> ByteString) -> Relay -> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Relay -> ByteString
Relay.encodeCbor
poolMetadata :: PoolMetadata.Metadata -> IO (Either Error Value)
poolMetadata :: Metadata -> IO (Either Error Value)
poolMetadata = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.poolMetadata" CUInt
30 (ByteString -> IO (Either Error Value))
-> (Metadata -> ByteString) -> Metadata -> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Metadata -> ByteString
PoolMetadata.encodeCbor
constitution :: Constitution.Constitution -> IO (Either Error Value)
constitution :: Constitution -> IO (Either Error Value)
constitution = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.constitution" CUInt
31 (ByteString -> IO (Either Error Value))
-> (Constitution -> ByteString)
-> Constitution
-> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Constitution -> ByteString
Constitution.encodeCbor
voter :: Voting.Voter -> IO (Either Error Value)
voter :: Voter -> IO (Either Error Value)
voter = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.voter" CUInt
32 (ByteString -> IO (Either Error Value))
-> (Voter -> ByteString) -> Voter -> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Voter -> ByteString
Voting.encodeVoter
votingProcedure :: Voting.VotingProcedure -> IO (Either Error Value)
votingProcedure :: VotingProcedure -> IO (Either Error Value)
votingProcedure = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.votingProcedure" CUInt
33 (ByteString -> IO (Either Error Value))
-> (VotingProcedure -> ByteString)
-> VotingProcedure
-> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. VotingProcedure -> ByteString
Voting.encodeProcedure
verificationWitness :: Witness.VerificationWitness -> IO (Either Error Value)
verificationWitness :: VerificationWitness -> IO (Either Error Value)
verificationWitness = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.verificationWitness" CUInt
34 (ByteString -> IO (Either Error Value))
-> (VerificationWitness -> ByteString)
-> VerificationWitness
-> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. VerificationWitness -> ByteString
Witness.encodeCbor
bootstrapWitness :: Witness.BootstrapWitness -> IO (Either Error Value)
bootstrapWitness :: BootstrapWitness -> IO (Either Error Value)
bootstrapWitness = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.bootstrapWitness" CUInt
35 (ByteString -> IO (Either Error Value))
-> (BootstrapWitness -> ByteString)
-> BootstrapWitness
-> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BootstrapWitness -> ByteString
Witness.encodeBootstrapCbor
costModel :: Models.CostModel -> IO (Either Error Value)
costModel :: CostModel -> IO (Either Error Value)
costModel = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.costModel" CUInt
36 (ByteString -> IO (Either Error Value))
-> (CostModel -> ByteString)
-> CostModel
-> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CostModel -> ByteString
costModelBytes
costModels :: Models.CostModels -> IO (Either Error Value)
costModels :: CostModels -> IO (Either Error Value)
costModels = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.costModels" CUInt
37 (ByteString -> IO (Either Error Value))
-> (CostModels -> ByteString)
-> CostModels
-> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. CostModels -> ByteString
Models.encodeCbor
exUnitPrices :: Prices.ExUnitPrices -> IO (Either Error Value)
exUnitPrices :: ExUnitPrices -> IO (Either Error Value)
exUnitPrices = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.exUnitPrices" CUInt
38 (ByteString -> IO (Either Error Value))
-> (ExUnitPrices -> ByteString)
-> ExUnitPrices
-> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ExUnitPrices -> ByteString
Prices.encodeCbor
poolVotingThresholds :: PoolThresholds.PoolVotingThresholds -> IO (Either Error Value)
poolVotingThresholds :: PoolVotingThresholds -> IO (Either Error Value)
poolVotingThresholds = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.poolVotingThresholds" CUInt
39 (ByteString -> IO (Either Error Value))
-> (PoolVotingThresholds -> ByteString)
-> PoolVotingThresholds
-> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. PoolVotingThresholds -> ByteString
PoolThresholds.encodeCbor
drepVotingThresholds :: DRepThresholds.DRepVotingThresholds -> IO (Either Error Value)
drepVotingThresholds :: DRepVotingThresholds -> IO (Either Error Value)
drepVotingThresholds = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.drepVotingThresholds" CUInt
40 (ByteString -> IO (Either Error Value))
-> (DRepVotingThresholds -> ByteString)
-> DRepVotingThresholds
-> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DRepVotingThresholds -> ByteString
DRepThresholds.encodeCbor
proposedUpdates :: Proposed.ProposedUpdates -> IO (Either Error Value)
proposedUpdates :: ProposedUpdates -> IO (Either Error Value)
proposedUpdates = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.proposedUpdates" CUInt
41 (ByteString -> IO (Either Error Value))
-> (ProposedUpdates -> ByteString)
-> ProposedUpdates
-> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ProposedUpdates -> ByteString
Proposed.encodeCbor
updateProposal :: Proposed.UpdateProposal -> IO (Either Error Value)
updateProposal :: UpdateProposal -> IO (Either Error Value)
updateProposal = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.updateProposal" CUInt
42 (ByteString -> IO (Either Error Value))
-> (UpdateProposal -> ByteString)
-> UpdateProposal
-> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UpdateProposal -> ByteString
Proposed.encodeProposal
balanceInterval :: Fields.BalanceInterval -> IO (Either Error Value)
balanceInterval :: BalanceInterval -> IO (Either Error Value)
balanceInterval = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.balanceInterval" CUInt
43 (ByteString -> IO (Either Error Value))
-> (BalanceInterval -> ByteString)
-> BalanceInterval
-> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BalanceInterval -> ByteString
balanceIntervalBytes
balanceIntervals :: Fields.Entries Reward.RewardAddress Fields.BalanceInterval -> IO (Either Error Value)
balanceIntervals :: Entries RewardAddress BalanceInterval -> IO (Either Error Value)
balanceIntervals = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.balanceIntervals" CUInt
44 (ByteString -> IO (Either Error Value))
-> (Entries RewardAddress BalanceInterval -> ByteString)
-> Entries RewardAddress BalanceInterval
-> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Entries RewardAddress BalanceInterval -> ByteString
balanceIntervalsBytes
directDeposits :: Fields.Entries Reward.RewardAddress Word64 -> IO (Either Error Value)
directDeposits :: Entries RewardAddress Word64 -> IO (Either Error Value)
directDeposits = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.directDeposits" CUInt
45 (ByteString -> IO (Either Error Value))
-> (Entries RewardAddress Word64 -> ByteString)
-> Entries RewardAddress Word64
-> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Entries RewardAddress Word64 -> ByteString
directDepositsBytes
requiredGuards :: Fields.Entries (Credential.Credential Credential.Guard) (Maybe Data.EncodedPlutusData) -> IO (Either Error Value)
requiredGuards :: Entries (Credential Guard) (Maybe EncodedPlutusData)
-> IO (Either Error Value)
requiredGuards = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.requiredGuards" CUInt
46 (ByteString -> IO (Either Error Value))
-> (Entries (Credential Guard) (Maybe EncodedPlutusData)
-> ByteString)
-> Entries (Credential Guard) (Maybe EncodedPlutusData)
-> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Entries (Credential Guard) (Maybe EncodedPlutusData) -> ByteString
requiredGuardsBytes
costModelBytes :: Models.CostModel -> ByteString
costModelBytes :: CostModel -> ByteString
costModelBytes CostModel
model = Encoding -> ByteString
Write.toStrictByteString (Word -> Encoding
Encoding.encodeListLen Word
2 Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word8 -> Encoding
Encoding.encodeWord8 (CostModel -> Word8
Models.languageId CostModel
model)) ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> CostModel -> ByteString
Models.encodeCostModelCbor CostModel
model
balanceIntervalEncoding :: Fields.BalanceInterval -> Encoding.Encoding
balanceIntervalEncoding :: BalanceInterval -> Encoding
balanceIntervalEncoding BalanceInterval
interval = case BalanceInterval
interval of
Fields.ExactBalance Word64
amount -> Word64 -> Encoding
Encoding.encodeWord64 Word64
amount
Fields.BalanceRange Maybe Word64
lower Maybe Word64
upper -> Word -> Encoding
Encoding.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
Encoding.encodeNull Word64 -> Encoding
Encoding.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
Encoding.encodeNull Word64 -> Encoding
Encoding.encodeWord64 Maybe Word64
upper
balanceIntervalBytes :: Fields.BalanceInterval -> ByteString
balanceIntervalBytes :: BalanceInterval -> ByteString
balanceIntervalBytes = Encoding -> ByteString
Write.toStrictByteString (Encoding -> ByteString)
-> (BalanceInterval -> Encoding) -> BalanceInterval -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BalanceInterval -> Encoding
balanceIntervalEncoding
associationBytes :: (key -> Encoding.Encoding) -> (value -> Encoding.Encoding) -> Fields.Entries key value -> ByteString
associationBytes :: forall key value.
(key -> Encoding)
-> (value -> Encoding) -> Entries key value -> ByteString
associationBytes key -> Encoding
encodeKey value -> Encoding
encodeValue Entries key value
entries = Encoding -> ByteString
Write.toStrictByteString (Word -> Encoding
Encoding.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
payload) -> key -> Encoding
encodeKey key
key Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> value -> Encoding
encodeValue value
payload) [(key, value)]
pairs)
where
pairs :: [(key, value)]
pairs = Entries key value -> [(key, value)]
forall key value. Entries key value -> [(key, value)]
Fields.entries Entries key value
entries
balanceIntervalsBytes :: Fields.Entries Reward.RewardAddress Fields.BalanceInterval -> ByteString
balanceIntervalsBytes :: Entries RewardAddress BalanceInterval -> ByteString
balanceIntervalsBytes = (RewardAddress -> Encoding)
-> (BalanceInterval -> Encoding)
-> Entries RewardAddress BalanceInterval
-> ByteString
forall key value.
(key -> Encoding)
-> (value -> Encoding) -> Entries key value -> ByteString
associationBytes (ByteString -> Encoding
Encoding.encodeBytes (ByteString -> Encoding)
-> (RewardAddress -> ByteString) -> RewardAddress -> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RewardAddress -> ByteString
Reward.toBytes) BalanceInterval -> Encoding
balanceIntervalEncoding
directDepositsBytes :: Fields.Entries Reward.RewardAddress Word64 -> ByteString
directDepositsBytes :: Entries RewardAddress Word64 -> ByteString
directDepositsBytes = (RewardAddress -> Encoding)
-> (Word64 -> Encoding)
-> Entries RewardAddress Word64
-> ByteString
forall key value.
(key -> Encoding)
-> (value -> Encoding) -> Entries key value -> ByteString
associationBytes (ByteString -> Encoding
Encoding.encodeBytes (ByteString -> Encoding)
-> (RewardAddress -> ByteString) -> RewardAddress -> Encoding
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RewardAddress -> ByteString
Reward.toBytes) Word64 -> Encoding
Encoding.encodeWord64
requiredGuardsBytes :: Fields.Entries (Credential.Credential Credential.Guard) (Maybe Data.EncodedPlutusData) -> ByteString
requiredGuardsBytes :: Entries (Credential Guard) (Maybe EncodedPlutusData) -> ByteString
requiredGuardsBytes Entries (Credential Guard) (Maybe EncodedPlutusData)
entries = Encoding -> ByteString
Write.toStrictByteString (Word -> Encoding
Encoding.encodeMapLen (Int -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral ([(Credential Guard, Maybe EncodedPlutusData)] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [(Credential Guard, Maybe EncodedPlutusData)]
pairs))) ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ((Credential Guard, Maybe EncodedPlutusData) -> ByteString)
-> [(Credential Guard, Maybe EncodedPlutusData)] -> ByteString
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, Maybe EncodedPlutusData) -> ByteString
forall {purpose}.
(Credential purpose, Maybe EncodedPlutusData) -> ByteString
encodePair [(Credential Guard, Maybe EncodedPlutusData)]
pairs
where
pairs :: [(Credential Guard, Maybe EncodedPlutusData)]
pairs = Entries (Credential Guard) (Maybe EncodedPlutusData)
-> [(Credential Guard, Maybe EncodedPlutusData)]
forall key value. Entries key value -> [(key, value)]
Fields.entries Entries (Credential Guard) (Maybe EncodedPlutusData)
entries
encodePair :: (Credential purpose, Maybe EncodedPlutusData) -> ByteString
encodePair (Credential purpose
key, Maybe EncodedPlutusData
payload) = Credential purpose -> ByteString
forall purpose. Credential purpose -> ByteString
Credential.encodeCbor Credential purpose
key ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
-> (EncodedPlutusData -> ByteString)
-> Maybe EncodedPlutusData
-> ByteString
forall b a. b -> (a -> b) -> Maybe a -> b
maybe (Encoding -> ByteString
Write.toStrictByteString Encoding
Encoding.encodeNull) EncodedPlutusData -> ByteString
Data.toCbor Maybe EncodedPlutusData
payload
assetName :: Name.AssetName -> IO (Either Error Value)
assetName :: AssetName -> IO (Either Error Value)
assetName = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.assetName" CUInt
47 (ByteString -> IO (Either Error Value))
-> (AssetName -> ByteString)
-> AssetName
-> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. AssetName -> ByteString
Name.encodeCbor
blake2bHash :: Hash.Blake2bHash -> IO (Either Error Value)
blake2bHash :: Blake2bHash -> IO (Either Error Value)
blake2bHash = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.blake2bHash" CUInt
48 (ByteString -> IO (Either Error Value))
-> (Blake2bHash -> ByteString)
-> Blake2bHash
-> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Blake2bHash -> ByteString
Hash.encodeCbor
blsKey :: Bls.BlsKey -> IO (Either Error Value)
blsKey :: BlsKey -> IO (Either Error Value)
blsKey = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.blsKey" CUInt
49 (ByteString -> IO (Either Error Value))
-> (BlsKey -> ByteString) -> BlsKey -> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. BlsKey -> ByteString
Bls.encodeCbor
committeeMembers :: Committee.Members -> IO (Either Error Value)
committeeMembers :: Members -> IO (Either Error Value)
committeeMembers = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.committeeMembers" CUInt
50 (ByteString -> IO (Either Error Value))
-> (Members -> ByteString) -> Members -> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Members -> ByteString
Committee.encodeMembers
withdrawals :: [(Reward.RewardAddress, Word64)] -> IO (Either Error Value)
withdrawals :: [(RewardAddress, Word64)] -> IO (Either Error Value)
withdrawals = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.withdrawals" CUInt
51 (ByteString -> IO (Either Error Value))
-> ([(RewardAddress, Word64)] -> ByteString)
-> [(RewardAddress, Word64)]
-> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(RewardAddress, Word64)] -> ByteString
Collections.encodeWithdrawalsCbor
hashes :: [Hash.Blake2bHash] -> IO (Either Error Value)
hashes :: [Blake2bHash] -> IO (Either Error Value)
hashes = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.hashes" CUInt
52 (ByteString -> IO (Either Error Value))
-> ([Blake2bHash] -> ByteString)
-> [Blake2bHash]
-> IO (Either Error Value)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Blake2bHash] -> ByteString
Collections.encodeHashesCbor
guards :: [Credential.Credential Credential.Guard] -> IO (Either Error Value)
guards :: [Credential Guard] -> IO (Either Error Value)
guards [] = Either Error Value -> IO (Either Error Value)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Value -> Either Error Value
forall a b. b -> Either a b
Right ([Value] -> Value
forall a. ToJSON a => a -> Value
toJSON ([] :: [Value])))
guards [Credential Guard]
credentials = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.guards" CUInt
53 ([Credential Guard] -> ByteString
forall purpose. [Credential purpose] -> ByteString
credentialListBytes [Credential Guard]
credentials)
subTransactions :: [Sub.SubTransaction] -> IO (Either Error Value)
subTransactions :: [SubTransaction] -> IO (Either Error Value)
subTransactions [] = Either Error Value -> IO (Either Error Value)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Value -> Either Error Value
forall a b. b -> Either a b
Right ([Value] -> Value
forall a. ToJSON a => a -> Value
toJSON ([] :: [Value])))
subTransactions [SubTransaction]
transactions = Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.subTransactions" CUInt
54 ([SubTransaction] -> ByteString
subTransactionsBytes [SubTransaction]
transactions)
assets :: [(Policy.PolicyId, [(Name.AssetName, Integer)])] -> IO (Either Error Value)
assets :: [(PolicyId, [(AssetName, Integer)])] -> IO (Either Error Value)
assets = Text
-> CUInt
-> [(PolicyId, [(AssetName, Integer)])]
-> IO (Either Error Value)
inspectAssetAssociations Text
"inspection.assets" CUInt
55
assetEntries :: [(Policy.PolicyId, [(Name.AssetName, Integer)])] -> IO (Either Error Value)
assetEntries :: [(PolicyId, [(AssetName, Integer)])] -> IO (Either Error Value)
assetEntries = Text
-> CUInt
-> [(PolicyId, [(AssetName, Integer)])]
-> IO (Either Error Value)
inspectAssetAssociations Text
"inspection.assetEntries" CUInt
56
policyAssets :: [(Name.AssetName, Integer)] -> IO (Either Error Value)
policyAssets :: [(AssetName, Integer)] -> IO (Either Error Value)
policyAssets [(AssetName, Integer)]
pairs = case Either Error ByteString
encoded of
Left Error
failure -> Either Error Value -> IO (Either Error Value)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Error -> Either Error Value
forall a b. a -> Either a b
Left Error
failure)
Right ByteString
bytes -> Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.policyAssets" CUInt
57 ByteString
bytes
where
encoded :: Either Error ByteString
encoded = do
ByteString
bytes <- [(AssetName, Integer)] -> Either Error ByteString
Collections.encodeAssetNamesCbor [(AssetName, Integer)]
pairs
Text -> [AssetName] -> Either Error ()
forall key. Ord key => Text -> [key] -> Either Error ()
uniqueObjectKeys Text
"Repeated asset names cannot be represented as JSON object keys" (((AssetName, Integer) -> AssetName)
-> [(AssetName, Integer)] -> [AssetName]
forall a b. (a -> b) -> [a] -> [b]
map (AssetName, Integer) -> AssetName
forall a b. (a, b) -> a
fst [(AssetName, Integer)]
pairs)
ByteString -> Either Error ByteString
forall a. a -> Either Error a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ByteString
bytes
policyAssetEntries :: [(Name.AssetName, Integer)] -> IO (Either Error Value)
policyAssetEntries :: [(AssetName, Integer)] -> IO (Either Error Value)
policyAssetEntries [(AssetName, Integer)]
pairs = case [(AssetName, Integer)] -> Either Error ByteString
Collections.encodeAssetNamesCbor [(AssetName, Integer)]
pairs of
Left Error
failure -> Either Error Value -> IO (Either Error Value)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Error -> Either Error Value
forall a b. a -> Either a b
Left Error
failure)
Right ByteString
bytes -> Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
"inspection.policyAssetEntries" CUInt
58 ByteString
bytes
inspectAssetAssociations :: Text -> CUInt -> [(Policy.PolicyId, [(Name.AssetName, Integer)])] -> IO (Either Error Value)
inspectAssetAssociations :: Text
-> CUInt
-> [(PolicyId, [(AssetName, Integer)])]
-> IO (Either Error Value)
inspectAssetAssociations Text
operation CUInt
kind [(PolicyId, [(AssetName, Integer)])]
pairs = case Either Error ByteString
encoded of
Left Error
failure -> Either Error Value -> IO (Either Error Value)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Error -> Either Error Value
forall a b. a -> Either a b
Left Error
failure)
Right ByteString
bytes -> Text -> CUInt -> ByteString -> IO (Either Error Value)
Internal.inspect Text
operation CUInt
kind ByteString
bytes
where
encoded :: Either Error ByteString
encoded = do
[ByteString]
groups <- ((PolicyId, [(AssetName, Integer)]) -> Either Error ByteString)
-> [(PolicyId, [(AssetName, Integer)])]
-> Either Error [ByteString]
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) -> [a] -> f [b]
traverse (PolicyId, [(AssetName, Integer)]) -> Either Error ByteString
encodeGroup (((PolicyId, [(AssetName, Integer)]) -> ByteString)
-> [(PolicyId, [(AssetName, Integer)])]
-> [(PolicyId, [(AssetName, Integer)])]
forall b a. Ord b => (a -> b) -> [a] -> [a]
sortOn (PolicyId -> ByteString
Policy.toBytes (PolicyId -> ByteString)
-> ((PolicyId, [(AssetName, Integer)]) -> PolicyId)
-> (PolicyId, [(AssetName, Integer)])
-> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (PolicyId, [(AssetName, Integer)]) -> PolicyId
forall a b. (a, b) -> a
fst) [(PolicyId, [(AssetName, Integer)])]
pairs)
([(AssetName, Integer)] -> Either Error ())
-> [[(AssetName, Integer)]] -> Either Error ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (Text -> [AssetName] -> Either Error ()
forall key. Ord key => Text -> [key] -> Either Error ()
uniqueObjectKeys Text
"Repeated asset names cannot be represented as JSON object keys" ([AssetName] -> Either Error ())
-> ([(AssetName, Integer)] -> [AssetName])
-> [(AssetName, Integer)]
-> Either Error ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((AssetName, Integer) -> AssetName)
-> [(AssetName, Integer)] -> [AssetName]
forall a b. (a -> b) -> [a] -> [b]
map (AssetName, Integer) -> AssetName
forall a b. (a, b) -> a
fst) (Map PolicyId [(AssetName, Integer)] -> [[(AssetName, Integer)]]
forall k a. Map k a -> [a]
Map.elems ([(PolicyId, [(AssetName, Integer)])]
-> Map PolicyId [(AssetName, Integer)]
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [(PolicyId, [(AssetName, Integer)])]
pairs))
ByteString -> Either Error ByteString
forall a. a -> Either Error a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Encoding -> ByteString
Write.toStrictByteString (Word -> Encoding
Encoding.encodeMapLen (Int -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral ([ByteString] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [ByteString]
groups))) ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> [ByteString] -> ByteString
forall a. Monoid a => [a] -> a
mconcat [ByteString]
groups)
encodeGroup :: (PolicyId, [(AssetName, Integer)]) -> Either Error ByteString
encodeGroup (PolicyId
policy, [(AssetName, Integer)]
quantities) = do
ByteString
bytes <- [(AssetName, Integer)] -> Either Error ByteString
Collections.encodeAssetNamesCbor [(AssetName, Integer)]
quantities
ByteString -> Either Error ByteString
forall a. a -> Either Error a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Encoding -> ByteString
Write.toStrictByteString (ByteString -> Encoding
Encoding.encodeBytes (PolicyId -> ByteString
Policy.toBytes PolicyId
policy)) ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> ByteString
bytes)
uniqueObjectKeys :: (Ord key) => Text -> [key] -> Either Error ()
uniqueObjectKeys :: forall key. Ord key => Text -> [key] -> Either Error ()
uniqueObjectKeys Text
message [key]
keys = Bool -> Either Error () -> Either Error ()
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
unless (Set key -> Int
forall a. Set a -> Int
Set.size ([key] -> Set key
forall a. Ord a => [a] -> Set a
Set.fromList [key]
keys) Int -> Int -> Bool
forall a. Eq a => a -> a -> Bool
== [key] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [key]
keys) (Error -> Either Error ()
forall a b. a -> Either a b
Left (Text -> Error
InvalidValueCbor Text
message))
credentialListBytes :: [Credential.Credential purpose] -> ByteString
credentialListBytes :: forall purpose. [Credential purpose] -> ByteString
credentialListBytes [Credential purpose]
credentials = Encoding -> ByteString
Write.toStrictByteString (Word -> Encoding
Encoding.encodeTag Word
258 Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word -> Encoding
Encoding.encodeListLen (Int -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral ([Credential purpose] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Credential purpose]
credentials))) ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> (Credential purpose -> ByteString)
-> [Credential purpose] -> ByteString
forall m a. Monoid m => (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap Credential purpose -> ByteString
forall purpose. Credential purpose -> ByteString
Credential.encodeCbor [Credential purpose]
credentials
subTransactionsBytes :: [Sub.SubTransaction] -> ByteString
subTransactionsBytes :: [SubTransaction] -> ByteString
subTransactionsBytes [SubTransaction]
transactions = Encoding -> ByteString
Write.toStrictByteString (Word -> Encoding
Encoding.encodeTag Word
258 Encoding -> Encoding -> Encoding
forall a. Semigroup a => a -> a -> a
<> Word -> Encoding
Encoding.encodeListLen (Int -> Word
forall a b. (Integral a, Num b) => a -> b
fromIntegral ([SubTransaction] -> Int
forall a. [a] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [SubTransaction]
transactions))) ByteString -> ByteString -> ByteString
forall a. Semigroup a => a -> a -> a
<> (SubTransaction -> ByteString) -> [SubTransaction] -> ByteString
forall m a. Monoid m => (a -> m) -> [a] -> m
forall (t :: * -> *) m a.
(Foldable t, Monoid m) =>
(a -> m) -> t a -> m
foldMap SubTransaction -> ByteString
Sub.encodeCbor [SubTransaction]
transactions