-- Copyright 2026 Biglup Labs
-- SPDX-License-Identifier: Apache-2.0
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
--     https://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.
{-# LANGUAGE OverloadedStrings #-}

-- | Inspect Cardano domain values using the CIP-116 JSON representation.
-- Large ledger integers become decimal strings and binary fields use explicit
-- text encodings. Object key order is insignificant. Inspection does not change
-- input encodings, validate ledger acceptance, sign or submit transactions.
-- Results are descriptive JSON, not exact-CBOR interchange. Render with
-- 'Data.Aeson.encode'. Expected validation/native failures remain explicit.
--
-- @
-- inspected <- Inspection.output output
-- -- fmap Data.Aeson.encode inspected
-- @
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

-- IMPORTS --------------------------------------------------------------------

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)

-- DEFINITIONS ----------------------------------------------------------------

-- | Inspect a standalone value, including signed native-asset quantities.
-- Ada must be nonnegative and all quantities must fit the native signed
-- 64-bit range. Invalid quantities return the errors from 'Value.encodeCbor'.
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

-- | Inspect a script with a @native_script@ or @plutus_script@ tag and payload.
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

-- | Inspect only the native-script payload, including recursive signature,
-- threshold, time and guard conditions. Omits the outer 'script' tag wrapper;
-- this is the CIP-116 schema, distinct from native-script construction JSON.
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

-- | Inspect the language name and compiled bytes of a Plutus script, without
-- the outer 'script' tag wrapper. Does not check program executability.
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")

-- | Inspect a role-indexed key or script credential as its tagged hash.
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

-- | Inspect one staking, pool, committee or DRep certificate. Deposits, refunds
-- and epochs describe the supplied certificate without checking chain state.
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

-- | Inspect a governance action, including its concrete action tag and fields.
-- Does not establish eligibility or interpret protocol activation rules.
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

-- | Inspect the deposit, return account, governance action and proposal anchor.
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

-- | Inspect the complete supplied pool registration parameters, including BLS,
-- relay, owner and metadata fields when present.
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

-- | Inspect supplied sparse protocol changes. Absent fields stay absent;
-- no current protocol snapshot or ledger-state query is performed.
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

-- | Inspect exact encoded script data. Arbitrary integers use decimal strings;
-- map entry order and duplicate keys remain represented in the JSON arrays.
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

-- | Inspect one output's address, value, datum and optional reference script.
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

-- | Inspect exact witness fields, including key witnesses, scripts, data and
-- redeemers. Does not verify signatures, budgets or script execution.
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

-- | Inspect an input reference paired with its resolved output. Does not check
-- whether the output exists or is currently unspent on a network.
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

-- | Inspect a credential DRep or either predefined delegation target.
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

-- | Inspect a transaction identifier and governance-action index.
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

-- | Inspect the metadata URL and content hash without fetching the URL.
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

-- | Inspect voter/action choices and optional explanation anchors. Collection
-- order follows the supplied validated representation; no vote is submitted.
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

-- | Inspect one validated metadata value using the tagged CIP-116 schema.
-- Nested map order and duplicate keys remain represented in the result. This
-- differs from the detailed and plain JSON codecs in "Cometa.Metadata".
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

-- | Inspect transaction metadata as an ordered array of label/value entries.
-- Labels use decimal strings; each value uses the tagged CIP-116 schema.
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

-- | Inspect exact auxiliary data, including metadata and native/Plutus scripts.
-- Retains source encodings and auxiliary-data hashes without recalculation.
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

-- | Inspect the transaction identifier and output index of an input reference.
-- Does not resolve the referenced output or establish its availability.
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

-- | Inspect a datum hash or inline datum. 'Datum.NoDatum' returns 'Nothing'
-- without allocating a native datum;
-- the other alternatives return the tagged native CIP-116 datum object.
-- Inline data retains its arbitrary integers, map order and duplicate keys.
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

-- | Inspect a redeemer's purpose, index, script data and declared execution
-- units. Does not execute the script or check its budget against a transaction.
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

-- | Inspect declared memory and CPU steps as decimal strings; no evaluation is performed.
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

-- | Inspect protocol major and minor versions as JSON numbers.
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

-- | Inspect the exact rational numerator and denominator as decimal strings.
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

-- | Inspect a pool relay, preserving absent ports and IP addresses as null.
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

-- | Inspect a pool metadata URL and hash without fetching the URL.
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

-- | Inspect a constitution anchor and optional guardrails hash; absence omits the hash.
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

-- | Inspect a committee, DRep or stake-pool voting identity with its role tag.
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

-- | Inspect a vote choice and optional explanation anchor; absence omits the anchor.
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

-- | Inspect a verification key and signature without verifying the signature.
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

-- | Inspect a Byron witness key, signature, chain code and attributes as hexadecimal.
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

-- | Inspect ordered signed costs as decimal strings. The language belongs to the
-- enclosing map and is absent from this array.
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

-- | Inspect known Plutus V1–V4 cost arrays. Unknown language identifiers are
-- omitted by this schema; input values and encodings remain unchanged.
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

-- | Inspect exact lovelace prices for memory and steps. Original
-- numerator/denominator components are retained, including prices greater than
-- one.
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

-- | Inspect all five stake-pool approval thresholds as exact rational components.
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

-- | Inspect all ten DRep approval thresholds as exact rational components.
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

-- | Inspect legacy genesis-authorized sparse changes as an object keyed by
-- hexadecimal genesis hashes. No authorization or era eligibility is
-- established.
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

-- | Inspect a legacy update proposal and activation epoch. Epoch is a JSON
-- number, unlike decimal-string ledger quantities.
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

-- | Inspect an exact lovelace balance or inclusive-lower/exclusive-upper range.
-- Absent bounds are null; contradictory bounds are described without ledger-
-- state validation. A range with both bounds absent returns a native invalid-
-- argument error.
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

-- | Inspect account balance requirements as ordered key/value entries. Keys are
-- reward addresses; bounds use the balance-interval schema.
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

-- | Inspect reward-account deposits as ordered key/value entries, preserving
-- present zero amounts as decimal strings.
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

-- | Inspect required guard credentials and optional exact script data as ordered
-- key/value entries. Absent data is null; script-data map order and duplicate
-- keys are retained.
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

-- | Inspect an asset name as lowercase hexadecimal, including the empty name.
-- Text decoding is not attempted.
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

-- | Inspect a validated nonempty digest as lowercase hexadecimal. No hashing or
-- role inference is performed.
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

-- | Inspect a pool BLS public key (96 bytes) and possession proof (48 bytes) as
-- hexadecimal. No group-membership or proof verification is performed.
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

-- | Inspect cold committee credentials and expiry epochs as ordered key/value
-- entries. Credential kind and hash determine order; epochs are decimal
-- strings.
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

-- | Inspect reward accounts and withdrawn lovelace as ordered key/value entries.
-- Empty input, zero and duplicate accounts are retained. Accounts sort stably
-- by encoded address bytes, distinct from ledger redeemer-index ordering.
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

-- | Inspect digests as a JSON array, sorted stably by byte length then bytes.
-- Duplicate digests remain; empty input produces an empty array.
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

-- | Inspect guards in supplied order. Empty input returns an empty array.
-- Key and script credentials remain tagged;
-- repeated credentials return a native duplicate-key error.
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)

-- | Inspect subtransactions in supplied order. Empty input returns an empty
-- array. Repeated body identifiers return
-- a native duplicate-key error, even if witnesses or outer framing differ.
-- Signed body encodings are unchanged.
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)

-- | Inspect policy/name associations as a JSON object keyed by hexadecimal
-- policies and names. Empty policy groups and zero quantities remain present.
-- Quantities must fit signed 64 bits ('Cometa.Error.InvalidValueQuantity').
-- Repeated policies use their last supplied group. Repeated names in a retained
-- group return 'InvalidValueCbor': object keys cannot retain repeated entries.
-- Ordering of object properties is insignificant.
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

-- | Inspect policy groups as ordered @{script_hash, assets}@ entries. The inner
-- @assets@ value is a name-keyed object, not an asset-entry array. Groups sort
-- stably by policy bytes; empty groups and zero remain. Repeated policies use
-- the last supplied group, matching native map decoding.
-- Duplicate names return 'InvalidValueCbor'; signed overflow returns
-- 'Cometa.Error.InvalidValueQuantity'. Use 'policyAssetEntries' for repeated names.
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

-- | Inspect one policy's name/quantity associations as a hexadecimal-name-keyed
-- object. Empty input and explicit zero are retained. Repeated names return
-- 'InvalidValueCbor'; quantities outside signed 64 bits return
-- 'Cometa.Error.InvalidValueQuantity'. No policy identity is required.
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

-- | Inspect one policy's assets as ordered @{asset_name, amount}@ entries.
-- Names sort stably by byte length then bytes; repeated names keep their relative
-- order. Empty input and explicit zeros remain. Quantities outside signed 64 bits
-- return 'Cometa.Error.InvalidValueQuantity'. No policy identity is required.
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