{-# LANGUAGE DeriveAnyClass    #-}
{-# LANGUAGE DerivingVia       #-}
{-# LANGUAGE LambdaCase        #-}
{-# LANGUAGE NamedFieldPuns    #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RankNTypes        #-}
{-# LANGUAGE TemplateHaskell   #-}
module Plutus.Contract.Effects( -- TODO: Move to Requests.Internal
    -- * Plutus application backend request effect types
    PABReq(..),
    _AdjustUnbalancedTxReq,
    _AwaitSlotReq,
    _AwaitTimeReq,
    _AwaitUtxoSpentReq,
    _AwaitUtxoProducedReq,
    _CurrentNodeClientSlotReq,
    _CurrentChainIndexSlotReq,
    _CurrentTimeReq,
    _CurrentNodeClientTimeRangeReq,
    _AwaitTxStatusChangeReq,
    _AwaitTxOutStatusChangeReq,
    _GetParamsReq,
    _OwnContractInstanceIdReq,
    _OwnAddressesReq,
    _ChainIndexQueryReq,
    _BalanceTxReq,
    _WriteBalancedTxReq,
    _ExposeEndpointReq,
    _PosixTimeRangeToContainedSlotRangeReq,
    _YieldUnbalancedTxReq,
    -- ** Chain index query effect types
    _DatumFromHash,
    _ValidatorFromHash,
    _MintingPolicyFromHash,
    _RedeemerFromHash,
    _TxOutFromRef,
    _TxFromTxId,
    _UnspentTxOutFromRef,
    _UtxoSetMembership,
    _UtxoSetAtAddress,
    _UtxoSetWithCurrency,
    _TxsFromTxIds,
    _TxoSetAtAddress,
    _GetTip,
    -- * Plutus application backend response effect types
    PABResp(..),
    _AdjustUnbalancedTxResp,
    _AwaitSlotResp,
    _AwaitTimeResp,
    _AwaitUtxoSpentResp,
    _AwaitUtxoProducedResp,
    _CurrentNodeClientSlotResp,
    _CurrentChainIndexSlotResp,
    _CurrentTimeResp,
    _CurrentNodeClientTimeRangeResp,
    _AwaitTxStatusChangeResp,
    _AwaitTxStatusChangeResp',
    _AwaitTxOutStatusChangeResp,
    _GetParamsResp,
    _OwnContractInstanceIdResp,
    _OwnAddressesResp,
    _ChainIndexQueryResp,
    _BalanceTxResp,
    _WriteBalancedTxResp,
    _ExposeEndpointResp,
    _PosixTimeRangeToContainedSlotRangeResp,
    _YieldUnbalancedTxResp,
    -- ** Chain index response effect types
    _DatumHashResponse,
    _ValidatorHashResponse,
    _MintingPolicyHashResponse,
    _RedeemerHashResponse,
    _TxOutRefResponse,
    _UnspentTxOutResponse,
    _TxIdResponse,
    _UtxoSetMembershipResponse,
    _UtxoSetAtResponse,
    _UtxoSetWithCurrencyResponse,
    _TxIdsResponse,
    _TxoSetAtResponse,
    _GetTipResponse,
    -- * Etc.
    matches,
    ChainIndexQuery(..),
    ChainIndexResponse(..),
    BalanceTxResponse(..),
    balanceTxResponse,
    WriteBalancedTxResponse(..),
    writeBalancedTxResponse,
    ActiveEndpoint(..),
    ) where

import Cardano.Api qualified as C
import Cardano.Node.Emulator.Internal.Node (Params, SlotConversionError)
import Control.Lens (Iso', Prism', iso, makePrisms, prism')
import Data.Aeson (FromJSON, ToJSON)
import Data.Aeson qualified as JSON
import Data.List.NonEmpty (NonEmpty)
import Data.String (fromString)
import GHC.Generics (Generic)
import Ledger.Address (CardanoAddress, toPlutusAddress)
import Ledger.Scripts (Validator)
import Ledger.Slot (Slot, SlotRange)
import Ledger.Time (POSIXTime, POSIXTimeRange)
import Ledger.Tx (CardanoTx, DecoratedTxOut, Versioned, getCardanoTxId)
import Ledger.Tx.Constraints.OffChain (UnbalancedTx)
import Plutus.ChainIndex (Page (pageItems), PageQuery)
import Plutus.ChainIndex.Api (IsUtxoResponse (IsUtxoResponse), QueryResponse (QueryResponse),
                              TxosResponse (TxosResponse), UtxosResponse (UtxosResponse))
import Plutus.ChainIndex.Tx (ChainIndexTx (_citxTxId))
import Plutus.ChainIndex.Types (Tip, TxOutStatus, TxStatus)
import Plutus.V1.Ledger.Api (Datum, DatumHash, MintingPolicy, MintingPolicyHash, Redeemer, RedeemerHash, StakeValidator,
                             StakeValidatorHash, TxId, TxOutRef, ValidatorHash)
import Plutus.V1.Ledger.Value (AssetClass)
import Prettyprinter (Pretty (pretty), hsep, indent, viaShow, vsep, (<+>))
import Wallet.Error (WalletAPIError)
import Wallet.Types (ContractInstanceId, EndpointDescription, EndpointValue)

-- | Requests that 'Contract's can make
data PABReq =
    AdjustUnbalancedTxReq UnbalancedTx
    | AwaitSlotReq Slot
    | AwaitTimeReq POSIXTime
    | AwaitUtxoSpentReq C.TxIn
    | AwaitUtxoProducedReq CardanoAddress
    | AwaitTxStatusChangeReq C.TxId
    | AwaitTxOutStatusChangeReq C.TxIn
    | CurrentNodeClientSlotReq
    | CurrentChainIndexSlotReq
    | CurrentTimeReq
    | CurrentNodeClientTimeRangeReq
    | GetParamsReq
    | OwnContractInstanceIdReq
    | OwnAddressesReq
    | ChainIndexQueryReq ChainIndexQuery
    | BalanceTxReq UnbalancedTx
    | WriteBalancedTxReq CardanoTx
    | ExposeEndpointReq ActiveEndpoint
    | PosixTimeRangeToContainedSlotRangeReq POSIXTimeRange
    | YieldUnbalancedTxReq UnbalancedTx
    deriving stock (PABReq -> PABReq -> Bool
(PABReq -> PABReq -> Bool)
-> (PABReq -> PABReq -> Bool) -> Eq PABReq
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PABReq -> PABReq -> Bool
$c/= :: PABReq -> PABReq -> Bool
== :: PABReq -> PABReq -> Bool
$c== :: PABReq -> PABReq -> Bool
Eq, Int -> PABReq -> ShowS
[PABReq] -> ShowS
PABReq -> String
(Int -> PABReq -> ShowS)
-> (PABReq -> String) -> ([PABReq] -> ShowS) -> Show PABReq
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PABReq] -> ShowS
$cshowList :: [PABReq] -> ShowS
show :: PABReq -> String
$cshow :: PABReq -> String
showsPrec :: Int -> PABReq -> ShowS
$cshowsPrec :: Int -> PABReq -> ShowS
Show, (forall x. PABReq -> Rep PABReq x)
-> (forall x. Rep PABReq x -> PABReq) -> Generic PABReq
forall x. Rep PABReq x -> PABReq
forall x. PABReq -> Rep PABReq x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PABReq x -> PABReq
$cfrom :: forall x. PABReq -> Rep PABReq x
Generic)
    deriving anyclass ([PABReq] -> Encoding
[PABReq] -> Value
PABReq -> Encoding
PABReq -> Value
(PABReq -> Value)
-> (PABReq -> Encoding)
-> ([PABReq] -> Value)
-> ([PABReq] -> Encoding)
-> ToJSON PABReq
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [PABReq] -> Encoding
$ctoEncodingList :: [PABReq] -> Encoding
toJSONList :: [PABReq] -> Value
$ctoJSONList :: [PABReq] -> Value
toEncoding :: PABReq -> Encoding
$ctoEncoding :: PABReq -> Encoding
toJSON :: PABReq -> Value
$ctoJSON :: PABReq -> Value
ToJSON, Value -> Parser [PABReq]
Value -> Parser PABReq
(Value -> Parser PABReq)
-> (Value -> Parser [PABReq]) -> FromJSON PABReq
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [PABReq]
$cparseJSONList :: Value -> Parser [PABReq]
parseJSON :: Value -> Parser PABReq
$cparseJSON :: Value -> Parser PABReq
FromJSON)

instance Pretty PABReq where
  pretty :: PABReq -> Doc ann
pretty = \case
    AdjustUnbalancedTxReq UnbalancedTx
utx               -> Doc ann
"Adjust unbalanced tx:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> UnbalancedTx -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty UnbalancedTx
utx
    AwaitSlotReq Slot
s                          -> Doc ann
"Await slot:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Slot -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Slot
s
    AwaitTimeReq POSIXTime
s                          -> Doc ann
"Await time:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> POSIXTime -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty POSIXTime
s
    AwaitUtxoSpentReq TxIn
utxo                  -> Doc ann
"Await utxo spent:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> TxIn -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty TxIn
utxo
    AwaitUtxoProducedReq CardanoAddress
a                  -> Doc ann
"Await utxo produced:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Address -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty (CardanoAddress -> Address
forall era. AddressInEra era -> Address
toPlutusAddress CardanoAddress
a)
    PABReq
CurrentNodeClientSlotReq                -> Doc ann
"Current node client slot"
    PABReq
CurrentChainIndexSlotReq                -> Doc ann
"Current chain index slot"
    PABReq
CurrentTimeReq                          -> Doc ann
"Current time"
    PABReq
CurrentNodeClientTimeRangeReq           -> Doc ann
"Current node client time range"
    AwaitTxStatusChangeReq TxId
txid             -> Doc ann
"Await tx status change:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> TxId -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty TxId
txid
    AwaitTxOutStatusChangeReq TxIn
ref           -> Doc ann
"Await txout status change:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> TxIn -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty TxIn
ref
    PABReq
GetParamsReq                            -> Doc ann
"Get the configured parameter set"
    PABReq
OwnContractInstanceIdReq                -> Doc ann
"Own contract instance ID"
    PABReq
OwnAddressesReq                         -> Doc ann
"Own addresses"
    ChainIndexQueryReq ChainIndexQuery
q                    -> Doc ann
"Chain index query:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> ChainIndexQuery -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty ChainIndexQuery
q
    BalanceTxReq UnbalancedTx
utx                        -> Doc ann
"Balance tx:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> UnbalancedTx -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty UnbalancedTx
utx
    WriteBalancedTxReq CardanoTx
tx                   -> Doc ann
"Write balanced tx:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> (String -> Doc ann
forall a. IsString a => String -> a
fromString (String -> Doc ann) -> String -> Doc ann
forall a b. (a -> b) -> a -> b
$ CardanoTx -> String
forall a. Show a => a -> String
show CardanoTx
tx)
    ExposeEndpointReq ActiveEndpoint
ep                    -> Doc ann
"Expose endpoint:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> ActiveEndpoint -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty ActiveEndpoint
ep
    PosixTimeRangeToContainedSlotRangeReq POSIXTimeRange
r -> Doc ann
"Posix time range to contained slot range:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> POSIXTimeRange -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty POSIXTimeRange
r
    YieldUnbalancedTxReq UnbalancedTx
utx                -> Doc ann
"Yield unbalanced tx:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> UnbalancedTx -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty UnbalancedTx
utx

-- | Responses that 'Contract's receive
data PABResp =
    AdjustUnbalancedTxResp UnbalancedTx
    | AwaitSlotResp Slot
    | AwaitTimeResp POSIXTime
    | AwaitUtxoSpentResp ChainIndexTx
    | AwaitUtxoProducedResp (NonEmpty ChainIndexTx)
    | AwaitTxStatusChangeResp C.TxId TxStatus
    | AwaitTxOutStatusChangeResp C.TxIn TxOutStatus
    | CurrentNodeClientSlotResp Slot
    | CurrentChainIndexSlotResp Slot
    | CurrentTimeResp POSIXTime
    | CurrentNodeClientTimeRangeResp (POSIXTime, POSIXTime)
    | GetParamsResp Params
    | OwnContractInstanceIdResp ContractInstanceId
    | OwnAddressesResp (NonEmpty CardanoAddress)
    | ChainIndexQueryResp ChainIndexResponse
    | BalanceTxResp BalanceTxResponse
    | WriteBalancedTxResp WriteBalancedTxResponse
    | ExposeEndpointResp EndpointDescription (EndpointValue JSON.Value)
    | PosixTimeRangeToContainedSlotRangeResp (Either SlotConversionError SlotRange)
    | YieldUnbalancedTxResp ()
    deriving stock (PABResp -> PABResp -> Bool
(PABResp -> PABResp -> Bool)
-> (PABResp -> PABResp -> Bool) -> Eq PABResp
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: PABResp -> PABResp -> Bool
$c/= :: PABResp -> PABResp -> Bool
== :: PABResp -> PABResp -> Bool
$c== :: PABResp -> PABResp -> Bool
Eq, Int -> PABResp -> ShowS
[PABResp] -> ShowS
PABResp -> String
(Int -> PABResp -> ShowS)
-> (PABResp -> String) -> ([PABResp] -> ShowS) -> Show PABResp
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [PABResp] -> ShowS
$cshowList :: [PABResp] -> ShowS
show :: PABResp -> String
$cshow :: PABResp -> String
showsPrec :: Int -> PABResp -> ShowS
$cshowsPrec :: Int -> PABResp -> ShowS
Show, (forall x. PABResp -> Rep PABResp x)
-> (forall x. Rep PABResp x -> PABResp) -> Generic PABResp
forall x. Rep PABResp x -> PABResp
forall x. PABResp -> Rep PABResp x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep PABResp x -> PABResp
$cfrom :: forall x. PABResp -> Rep PABResp x
Generic)
    deriving anyclass ([PABResp] -> Encoding
[PABResp] -> Value
PABResp -> Encoding
PABResp -> Value
(PABResp -> Value)
-> (PABResp -> Encoding)
-> ([PABResp] -> Value)
-> ([PABResp] -> Encoding)
-> ToJSON PABResp
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [PABResp] -> Encoding
$ctoEncodingList :: [PABResp] -> Encoding
toJSONList :: [PABResp] -> Value
$ctoJSONList :: [PABResp] -> Value
toEncoding :: PABResp -> Encoding
$ctoEncoding :: PABResp -> Encoding
toJSON :: PABResp -> Value
$ctoJSON :: PABResp -> Value
ToJSON, Value -> Parser [PABResp]
Value -> Parser PABResp
(Value -> Parser PABResp)
-> (Value -> Parser [PABResp]) -> FromJSON PABResp
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [PABResp]
$cparseJSONList :: Value -> Parser [PABResp]
parseJSON :: Value -> Parser PABResp
$cparseJSON :: Value -> Parser PABResp
FromJSON)

instance Pretty PABResp where
  pretty :: PABResp -> Doc ann
pretty = \case
    AdjustUnbalancedTxResp UnbalancedTx
utx               -> Doc ann
"Adjusted unbalanced tx: " Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> UnbalancedTx -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty UnbalancedTx
utx
    AwaitSlotResp Slot
s                          -> Doc ann
"Slot:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Slot -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Slot
s
    AwaitTimeResp POSIXTime
s                          -> Doc ann
"Time:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> POSIXTime -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty POSIXTime
s
    AwaitUtxoSpentResp ChainIndexTx
utxo                  -> Doc ann
"Utxo spent:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> ChainIndexTx -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty ChainIndexTx
utxo
    AwaitUtxoProducedResp NonEmpty ChainIndexTx
addr               -> Doc ann
"Utxo produced:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> NonEmpty ChainIndexTx -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty NonEmpty ChainIndexTx
addr
    CurrentNodeClientSlotResp Slot
s              -> Doc ann
"Current node client slot:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Slot -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Slot
s
    CurrentChainIndexSlotResp Slot
s              -> Doc ann
"Current chain index slot:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Slot -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Slot
s
    CurrentTimeResp POSIXTime
s                        -> Doc ann
"Current time:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> POSIXTime -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty POSIXTime
s
    CurrentNodeClientTimeRangeResp (POSIXTime, POSIXTime)
s         -> Doc ann
"Current node client time range:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> (POSIXTime, POSIXTime) -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty (POSIXTime, POSIXTime)
s
    AwaitTxStatusChangeResp TxId
txid TxStatus
status      -> Doc ann
"Status of" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> TxId -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty TxId
txid Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Doc ann
"changed to" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> TxStatus -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty TxStatus
status
    AwaitTxOutStatusChangeResp TxIn
ref TxOutStatus
status    -> Doc ann
"Status of" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> TxIn -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty TxIn
ref Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Doc ann
"changed to" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> TxOutStatus -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty TxOutStatus
status
    GetParamsResp Params
params                     -> Doc ann
"Configured parameters:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Params -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Params
params
    OwnContractInstanceIdResp ContractInstanceId
i              -> Doc ann
"Own contract instance ID:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> ContractInstanceId -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty ContractInstanceId
i
    OwnAddressesResp NonEmpty CardanoAddress
addrs                   -> Doc ann
"Own addresses:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> NonEmpty Address -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty (CardanoAddress -> Address
forall era. AddressInEra era -> Address
toPlutusAddress (CardanoAddress -> Address)
-> NonEmpty CardanoAddress -> NonEmpty Address
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> NonEmpty CardanoAddress
addrs)
    ChainIndexQueryResp ChainIndexResponse
rsp                  -> ChainIndexResponse -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty ChainIndexResponse
rsp
    BalanceTxResp BalanceTxResponse
r                          -> Doc ann
"Balance tx:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> BalanceTxResponse -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty BalanceTxResponse
r
    WriteBalancedTxResp WriteBalancedTxResponse
r                    -> Doc ann
"Write balanced tx:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> WriteBalancedTxResponse -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty WriteBalancedTxResponse
r
    ExposeEndpointResp EndpointDescription
desc EndpointValue Value
rsp              -> Doc ann
"Call endpoint" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> EndpointDescription -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty EndpointDescription
desc Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Doc ann
"with" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> EndpointValue Value -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty EndpointValue Value
rsp
    PosixTimeRangeToContainedSlotRangeResp Either SlotConversionError SlotRange
r -> Doc ann
"Slot range:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Either SlotConversionError SlotRange -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Either SlotConversionError SlotRange
r
    YieldUnbalancedTxResp ()                 -> Doc ann
"Yielded unbalanced tx"

matches :: PABReq -> PABResp -> Bool
matches :: PABReq -> PABResp -> Bool
matches PABReq
a PABResp
b = case (PABReq
a, PABResp
b) of
  (AdjustUnbalancedTxReq{}, AdjustUnbalancedTxResp{})      -> Bool
True
  (AwaitSlotReq{}, AwaitSlotResp{})                        -> Bool
True
  (AwaitTimeReq{}, AwaitTimeResp{})                        -> Bool
True
  (AwaitUtxoSpentReq{}, AwaitUtxoSpentResp{})              -> Bool
True
  (AwaitUtxoProducedReq{}, AwaitUtxoProducedResp{})        -> Bool
True
  (PABReq
CurrentNodeClientSlotReq, CurrentNodeClientSlotResp{})  -> Bool
True
  (PABReq
CurrentChainIndexSlotReq, CurrentChainIndexSlotResp{})  -> Bool
True
  (PABReq
CurrentTimeReq, CurrentTimeResp{})                      -> Bool
True
  (PABReq
CurrentNodeClientTimeRangeReq, CurrentNodeClientTimeRangeResp{}) -> Bool
True
  (AwaitTxStatusChangeReq TxId
i, AwaitTxStatusChangeResp TxId
i' TxStatus
_) -> TxId
i TxId -> TxId -> Bool
forall a. Eq a => a -> a -> Bool
== TxId
i'
  (AwaitTxOutStatusChangeReq TxIn
i, AwaitTxOutStatusChangeResp TxIn
i' TxOutStatus
_) -> TxIn
i TxIn -> TxIn -> Bool
forall a. Eq a => a -> a -> Bool
== TxIn
i'
  (PABReq
GetParamsReq, GetParamsResp Params
_)                          -> Bool
True
  (PABReq
OwnContractInstanceIdReq, OwnContractInstanceIdResp{})  -> Bool
True
  (PABReq
OwnAddressesReq, OwnAddressesResp {}) -> Bool
True
  (ChainIndexQueryReq ChainIndexQuery
r, ChainIndexQueryResp ChainIndexResponse
r')           -> ChainIndexQuery -> ChainIndexResponse -> Bool
chainIndexMatches ChainIndexQuery
r ChainIndexResponse
r'
  (BalanceTxReq{}, BalanceTxResp{})                        -> Bool
True
  (WriteBalancedTxReq{}, WriteBalancedTxResp{})            -> Bool
True
  (ExposeEndpointReq ActiveEndpoint{EndpointDescription
aeDescription :: ActiveEndpoint -> EndpointDescription
aeDescription :: EndpointDescription
aeDescription}, ExposeEndpointResp EndpointDescription
desc EndpointValue Value
_)
    | EndpointDescription
aeDescription EndpointDescription -> EndpointDescription -> Bool
forall a. Eq a => a -> a -> Bool
== EndpointDescription
desc -> Bool
True
  (PosixTimeRangeToContainedSlotRangeReq{}, PosixTimeRangeToContainedSlotRangeResp{}) -> Bool
True
  (YieldUnbalancedTxReq{}, YieldUnbalancedTxResp{})        -> Bool
True
  (PABReq, PABResp)
_                                                        -> Bool
False

chainIndexMatches :: ChainIndexQuery -> ChainIndexResponse -> Bool
chainIndexMatches :: ChainIndexQuery -> ChainIndexResponse -> Bool
chainIndexMatches ChainIndexQuery
q ChainIndexResponse
r = case (ChainIndexQuery
q, ChainIndexResponse
r) of
    (DatumFromHash{}, DatumHashResponse{})                   -> Bool
True
    (ValidatorFromHash{}, ValidatorHashResponse{})           -> Bool
True
    (MintingPolicyFromHash{}, MintingPolicyHashResponse{})   -> Bool
True
    (StakeValidatorFromHash{}, StakeValidatorHashResponse{}) -> Bool
True
    (RedeemerFromHash{}, RedeemerHashResponse{})             -> Bool
True
    (TxOutFromRef{}, TxOutRefResponse{})                     -> Bool
True
    (TxFromTxId{}, TxIdResponse{})                           -> Bool
True
    (UnspentTxOutFromRef{}, UnspentTxOutResponse{})          -> Bool
True
    (UtxoSetMembership{}, UtxoSetMembershipResponse{})       -> Bool
True
    (UtxoSetAtAddress{}, UtxoSetAtResponse{})                -> Bool
True
    (UnspentTxOutSetAtAddress{}, UnspentTxOutsAtResponse{})  -> Bool
True
    (DatumsAtAddress{}, DatumsAtResponse{})                  -> Bool
True
    (UtxoSetWithCurrency{}, UtxoSetWithCurrencyResponse{})   -> Bool
True
    (TxoSetAtAddress{}, TxoSetAtResponse{})                  -> Bool
True
    (TxsFromTxIds{}, TxIdsResponse{})                        -> Bool
True
    (GetTip{}, GetTipResponse{})                             -> Bool
True
    (ChainIndexQuery, ChainIndexResponse)
_                                                        -> Bool
False

-- | Represents all possible chain index queries. Each constructor contains the
-- input(s) needed for the query. These possible queries correspond to the
-- constructors of the data type 'Plutus.ChainIndex.Effects.ChainIndexQueryEffect'.
data ChainIndexQuery =
    DatumFromHash DatumHash
  | ValidatorFromHash ValidatorHash
  | MintingPolicyFromHash MintingPolicyHash
  | StakeValidatorFromHash StakeValidatorHash
  | RedeemerFromHash RedeemerHash
  | TxOutFromRef TxOutRef
  | UnspentTxOutFromRef TxOutRef
  | TxFromTxId TxId
  | UtxoSetMembership TxOutRef
  | UtxoSetAtAddress (PageQuery TxOutRef) CardanoAddress
  | UnspentTxOutSetAtAddress (PageQuery TxOutRef) CardanoAddress
  | DatumsAtAddress (PageQuery TxOutRef) CardanoAddress
  | UtxoSetWithCurrency (PageQuery TxOutRef) AssetClass
  | TxsFromTxIds [TxId]
  | TxoSetAtAddress (PageQuery TxOutRef) CardanoAddress
  | GetTip
    deriving stock (ChainIndexQuery -> ChainIndexQuery -> Bool
(ChainIndexQuery -> ChainIndexQuery -> Bool)
-> (ChainIndexQuery -> ChainIndexQuery -> Bool)
-> Eq ChainIndexQuery
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ChainIndexQuery -> ChainIndexQuery -> Bool
$c/= :: ChainIndexQuery -> ChainIndexQuery -> Bool
== :: ChainIndexQuery -> ChainIndexQuery -> Bool
$c== :: ChainIndexQuery -> ChainIndexQuery -> Bool
Eq, Int -> ChainIndexQuery -> ShowS
[ChainIndexQuery] -> ShowS
ChainIndexQuery -> String
(Int -> ChainIndexQuery -> ShowS)
-> (ChainIndexQuery -> String)
-> ([ChainIndexQuery] -> ShowS)
-> Show ChainIndexQuery
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ChainIndexQuery] -> ShowS
$cshowList :: [ChainIndexQuery] -> ShowS
show :: ChainIndexQuery -> String
$cshow :: ChainIndexQuery -> String
showsPrec :: Int -> ChainIndexQuery -> ShowS
$cshowsPrec :: Int -> ChainIndexQuery -> ShowS
Show, (forall x. ChainIndexQuery -> Rep ChainIndexQuery x)
-> (forall x. Rep ChainIndexQuery x -> ChainIndexQuery)
-> Generic ChainIndexQuery
forall x. Rep ChainIndexQuery x -> ChainIndexQuery
forall x. ChainIndexQuery -> Rep ChainIndexQuery x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ChainIndexQuery x -> ChainIndexQuery
$cfrom :: forall x. ChainIndexQuery -> Rep ChainIndexQuery x
Generic)
    deriving anyclass ([ChainIndexQuery] -> Encoding
[ChainIndexQuery] -> Value
ChainIndexQuery -> Encoding
ChainIndexQuery -> Value
(ChainIndexQuery -> Value)
-> (ChainIndexQuery -> Encoding)
-> ([ChainIndexQuery] -> Value)
-> ([ChainIndexQuery] -> Encoding)
-> ToJSON ChainIndexQuery
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [ChainIndexQuery] -> Encoding
$ctoEncodingList :: [ChainIndexQuery] -> Encoding
toJSONList :: [ChainIndexQuery] -> Value
$ctoJSONList :: [ChainIndexQuery] -> Value
toEncoding :: ChainIndexQuery -> Encoding
$ctoEncoding :: ChainIndexQuery -> Encoding
toJSON :: ChainIndexQuery -> Value
$ctoJSON :: ChainIndexQuery -> Value
ToJSON, Value -> Parser [ChainIndexQuery]
Value -> Parser ChainIndexQuery
(Value -> Parser ChainIndexQuery)
-> (Value -> Parser [ChainIndexQuery]) -> FromJSON ChainIndexQuery
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [ChainIndexQuery]
$cparseJSONList :: Value -> Parser [ChainIndexQuery]
parseJSON :: Value -> Parser ChainIndexQuery
$cparseJSON :: Value -> Parser ChainIndexQuery
FromJSON)

instance Pretty ChainIndexQuery where
    pretty :: ChainIndexQuery -> Doc ann
pretty = \case
        DatumFromHash DatumHash
h                 -> Doc ann
"requesting datum from hash" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> DatumHash -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty DatumHash
h
        ValidatorFromHash ValidatorHash
h             -> Doc ann
"requesting validator from hash" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> ValidatorHash -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty ValidatorHash
h
        MintingPolicyFromHash MintingPolicyHash
h         -> Doc ann
"requesting minting policy from hash" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> MintingPolicyHash -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty MintingPolicyHash
h
        StakeValidatorFromHash StakeValidatorHash
h        -> Doc ann
"requesting stake validator from hash" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> StakeValidatorHash -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty StakeValidatorHash
h
        RedeemerFromHash RedeemerHash
h              -> Doc ann
"requesting redeemer from hash" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> RedeemerHash -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty RedeemerHash
h
        TxOutFromRef TxOutRef
r                  -> Doc ann
"requesting utxo from utxo reference" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> TxOutRef -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty TxOutRef
r
        UnspentTxOutFromRef TxOutRef
r           -> Doc ann
"requesting unspent txos from utxo reference" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> TxOutRef -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty TxOutRef
r
        TxFromTxId TxId
i                    -> Doc ann
"requesting chain index tx from id" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> TxId -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty TxId
i
        UtxoSetMembership TxOutRef
txOutRef      -> Doc ann
"whether tx output is part of the utxo set" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> TxOutRef -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty TxOutRef
txOutRef
        UtxoSetAtAddress PageQuery TxOutRef
_ CardanoAddress
addr         -> Doc ann
"requesting utxos located at addresses with the credential" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Address -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty (CardanoAddress -> Address
forall era. AddressInEra era -> Address
toPlutusAddress CardanoAddress
addr)
        UnspentTxOutSetAtAddress PageQuery TxOutRef
_ CardanoAddress
addr -> Doc ann
"requesting unspent txos located at addresses with the credential" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Address -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty (CardanoAddress -> Address
forall era. AddressInEra era -> Address
toPlutusAddress CardanoAddress
addr)
        DatumsAtAddress PageQuery TxOutRef
_ CardanoAddress
addr          -> Doc ann
"requesting datums located at addresses with the credential" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Address -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty (CardanoAddress -> Address
forall era. AddressInEra era -> Address
toPlutusAddress CardanoAddress
addr)
        UtxoSetWithCurrency PageQuery TxOutRef
_ AssetClass
ac        -> Doc ann
"requesting utxos containing the asset class" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> AssetClass -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty AssetClass
ac
        TxsFromTxIds [TxId]
i                  -> Doc ann
"requesting chain index txs from ids" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> [TxId] -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty [TxId]
i
        TxoSetAtAddress PageQuery TxOutRef
_ CardanoAddress
addr          -> Doc ann
"requesting txos located at addresses with the credential" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Address -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty (CardanoAddress -> Address
forall era. AddressInEra era -> Address
toPlutusAddress CardanoAddress
addr)
        ChainIndexQuery
GetTip                          -> Doc ann
"requesting the tip of the chain index"

-- | Represents all possible responses to chain index queries. Each constructor
-- contain the output resulting for the chain index query. These possible
-- responses come from the data type 'Plutus.ChainIndex.Effects.ChainIndexQueryEffect'.
data ChainIndexResponse =
    DatumHashResponse (Maybe Datum)
  | ValidatorHashResponse (Maybe (Versioned Validator))
  | MintingPolicyHashResponse (Maybe (Versioned MintingPolicy))
  | StakeValidatorHashResponse (Maybe (Versioned StakeValidator))
  | TxOutRefResponse (Maybe DecoratedTxOut)
  | UnspentTxOutResponse (Maybe DecoratedTxOut)
  | RedeemerHashResponse (Maybe Redeemer)
  | TxIdResponse (Maybe ChainIndexTx)
  | UtxoSetMembershipResponse IsUtxoResponse
  | UtxoSetAtResponse UtxosResponse
  | UnspentTxOutsAtResponse (QueryResponse [(TxOutRef, DecoratedTxOut)])
  | DatumsAtResponse (QueryResponse [Datum])
  | UtxoSetWithCurrencyResponse UtxosResponse
  | TxIdsResponse [ChainIndexTx]
  | TxoSetAtResponse TxosResponse
  | GetTipResponse Tip
    deriving stock (ChainIndexResponse -> ChainIndexResponse -> Bool
(ChainIndexResponse -> ChainIndexResponse -> Bool)
-> (ChainIndexResponse -> ChainIndexResponse -> Bool)
-> Eq ChainIndexResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ChainIndexResponse -> ChainIndexResponse -> Bool
$c/= :: ChainIndexResponse -> ChainIndexResponse -> Bool
== :: ChainIndexResponse -> ChainIndexResponse -> Bool
$c== :: ChainIndexResponse -> ChainIndexResponse -> Bool
Eq, Int -> ChainIndexResponse -> ShowS
[ChainIndexResponse] -> ShowS
ChainIndexResponse -> String
(Int -> ChainIndexResponse -> ShowS)
-> (ChainIndexResponse -> String)
-> ([ChainIndexResponse] -> ShowS)
-> Show ChainIndexResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ChainIndexResponse] -> ShowS
$cshowList :: [ChainIndexResponse] -> ShowS
show :: ChainIndexResponse -> String
$cshow :: ChainIndexResponse -> String
showsPrec :: Int -> ChainIndexResponse -> ShowS
$cshowsPrec :: Int -> ChainIndexResponse -> ShowS
Show, (forall x. ChainIndexResponse -> Rep ChainIndexResponse x)
-> (forall x. Rep ChainIndexResponse x -> ChainIndexResponse)
-> Generic ChainIndexResponse
forall x. Rep ChainIndexResponse x -> ChainIndexResponse
forall x. ChainIndexResponse -> Rep ChainIndexResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ChainIndexResponse x -> ChainIndexResponse
$cfrom :: forall x. ChainIndexResponse -> Rep ChainIndexResponse x
Generic)
    deriving anyclass ([ChainIndexResponse] -> Encoding
[ChainIndexResponse] -> Value
ChainIndexResponse -> Encoding
ChainIndexResponse -> Value
(ChainIndexResponse -> Value)
-> (ChainIndexResponse -> Encoding)
-> ([ChainIndexResponse] -> Value)
-> ([ChainIndexResponse] -> Encoding)
-> ToJSON ChainIndexResponse
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [ChainIndexResponse] -> Encoding
$ctoEncodingList :: [ChainIndexResponse] -> Encoding
toJSONList :: [ChainIndexResponse] -> Value
$ctoJSONList :: [ChainIndexResponse] -> Value
toEncoding :: ChainIndexResponse -> Encoding
$ctoEncoding :: ChainIndexResponse -> Encoding
toJSON :: ChainIndexResponse -> Value
$ctoJSON :: ChainIndexResponse -> Value
ToJSON, Value -> Parser [ChainIndexResponse]
Value -> Parser ChainIndexResponse
(Value -> Parser ChainIndexResponse)
-> (Value -> Parser [ChainIndexResponse])
-> FromJSON ChainIndexResponse
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [ChainIndexResponse]
$cparseJSONList :: Value -> Parser [ChainIndexResponse]
parseJSON :: Value -> Parser ChainIndexResponse
$cparseJSON :: Value -> Parser ChainIndexResponse
FromJSON)

instance Pretty ChainIndexResponse where
    pretty :: ChainIndexResponse -> Doc ann
pretty = \case
        DatumHashResponse Maybe Datum
d -> Doc ann
"Chain index datum from hash response:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Maybe Datum -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Maybe Datum
d
        ValidatorHashResponse Maybe (Versioned Validator)
v -> Doc ann
"Chain index validator from hash response:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Maybe (Versioned Validator) -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Maybe (Versioned Validator)
v
        MintingPolicyHashResponse Maybe (Versioned MintingPolicy)
m -> Doc ann
"Chain index minting policy from hash response:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Maybe (Versioned MintingPolicy) -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Maybe (Versioned MintingPolicy)
m
        StakeValidatorHashResponse Maybe (Versioned StakeValidator)
m -> Doc ann
"Chain index stake validator from hash response:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Maybe (Versioned StakeValidator) -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Maybe (Versioned StakeValidator)
m
        RedeemerHashResponse Maybe Redeemer
r -> Doc ann
"Chain index redeemer from hash response:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Maybe Redeemer -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Maybe Redeemer
r
        TxOutRefResponse Maybe DecoratedTxOut
t -> Doc ann
"Chain index utxo from utxo ref response:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Maybe DecoratedTxOut -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Maybe DecoratedTxOut
t
        UnspentTxOutResponse Maybe DecoratedTxOut
t -> Doc ann
"Chain index unspent txo from utxo ref response:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Maybe DecoratedTxOut -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Maybe DecoratedTxOut
t
        TxIdResponse Maybe ChainIndexTx
t -> Doc ann
"Chain index tx from tx id response:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Maybe TxId -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty (ChainIndexTx -> TxId
_citxTxId (ChainIndexTx -> TxId) -> Maybe ChainIndexTx -> Maybe TxId
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Maybe ChainIndexTx
t)
        UtxoSetMembershipResponse (IsUtxoResponse Tip
tip Bool
b) ->
                Doc ann
"Chain index response whether tx output ref is part of the UTxO set:"
            Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Bool -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Bool
b
            Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Doc ann
"with tip"
            Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Tip -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Tip
tip
        UtxoSetAtResponse (UtxosResponse Tip
tip Page TxOutRef
txOutRefPage) ->
                Doc ann
"Chain index UTxO set from address response:"
            Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Doc ann
"Current tip is"
            Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Tip -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Tip
tip
            Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Doc ann
"and utxo refs are"
            Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> [Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
hsep ((TxOutRef -> Doc ann) -> [TxOutRef] -> [Doc ann]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap TxOutRef -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty ([TxOutRef] -> [Doc ann]) -> [TxOutRef] -> [Doc ann]
forall a b. (a -> b) -> a -> b
$ Page TxOutRef -> [TxOutRef]
forall a. Page a -> [a]
pageItems Page TxOutRef
txOutRefPage)
        UnspentTxOutsAtResponse (QueryResponse [(TxOutRef, DecoratedTxOut)]
txouts Maybe (PageQuery TxOutRef)
_) ->
          Doc ann
"Unspent txos from address response:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> [Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
hsep (((TxOutRef, DecoratedTxOut) -> Doc ann)
-> [(TxOutRef, DecoratedTxOut)] -> [Doc ann]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (TxOutRef, DecoratedTxOut) -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty [(TxOutRef, DecoratedTxOut)]
txouts)
        DatumsAtResponse (QueryResponse [Datum]
datums Maybe (PageQuery TxOutRef)
_) ->
          Doc ann
"Chain index datums from address response:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> [Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
hsep ((Datum -> Doc ann) -> [Datum] -> [Doc ann]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Datum -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty [Datum]
datums)
        UtxoSetWithCurrencyResponse (UtxosResponse Tip
tip Page TxOutRef
txOutRefPage) ->
                Doc ann
"Chain index UTxO with asset class response:"
            Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Doc ann
"Current tip is"
            Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Tip -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Tip
tip
            Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Doc ann
"and utxo refs are"
            Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> [Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
hsep ((TxOutRef -> Doc ann) -> [TxOutRef] -> [Doc ann]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap TxOutRef -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty ([TxOutRef] -> [Doc ann]) -> [TxOutRef] -> [Doc ann]
forall a b. (a -> b) -> a -> b
$ Page TxOutRef -> [TxOutRef]
forall a. Page a -> [a]
pageItems Page TxOutRef
txOutRefPage)
        TxIdsResponse [ChainIndexTx]
t -> Doc ann
"Chain index txs from tx ids response:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> [TxId] -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty (ChainIndexTx -> TxId
_citxTxId (ChainIndexTx -> TxId) -> [ChainIndexTx] -> [TxId]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [ChainIndexTx]
t)
        TxoSetAtResponse (TxosResponse Page TxOutRef
txOutRefPage) ->
                Doc ann
"Chain index TxO set from address response:"
            Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Doc ann
"The txo refs are"
            Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> [Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
hsep ((TxOutRef -> Doc ann) -> [TxOutRef] -> [Doc ann]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap TxOutRef -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty ([TxOutRef] -> [Doc ann]) -> [TxOutRef] -> [Doc ann]
forall a b. (a -> b) -> a -> b
$ Page TxOutRef -> [TxOutRef]
forall a. Page a -> [a]
pageItems Page TxOutRef
txOutRefPage)
        GetTipResponse Tip
tip -> Doc ann
"Chain index get tip response:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Tip -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Tip
tip

data BalanceTxResponse =
  BalanceTxFailed WalletAPIError
  | BalanceTxSuccess CardanoTx
  deriving stock (BalanceTxResponse -> BalanceTxResponse -> Bool
(BalanceTxResponse -> BalanceTxResponse -> Bool)
-> (BalanceTxResponse -> BalanceTxResponse -> Bool)
-> Eq BalanceTxResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: BalanceTxResponse -> BalanceTxResponse -> Bool
$c/= :: BalanceTxResponse -> BalanceTxResponse -> Bool
== :: BalanceTxResponse -> BalanceTxResponse -> Bool
$c== :: BalanceTxResponse -> BalanceTxResponse -> Bool
Eq, Int -> BalanceTxResponse -> ShowS
[BalanceTxResponse] -> ShowS
BalanceTxResponse -> String
(Int -> BalanceTxResponse -> ShowS)
-> (BalanceTxResponse -> String)
-> ([BalanceTxResponse] -> ShowS)
-> Show BalanceTxResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [BalanceTxResponse] -> ShowS
$cshowList :: [BalanceTxResponse] -> ShowS
show :: BalanceTxResponse -> String
$cshow :: BalanceTxResponse -> String
showsPrec :: Int -> BalanceTxResponse -> ShowS
$cshowsPrec :: Int -> BalanceTxResponse -> ShowS
Show, (forall x. BalanceTxResponse -> Rep BalanceTxResponse x)
-> (forall x. Rep BalanceTxResponse x -> BalanceTxResponse)
-> Generic BalanceTxResponse
forall x. Rep BalanceTxResponse x -> BalanceTxResponse
forall x. BalanceTxResponse -> Rep BalanceTxResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep BalanceTxResponse x -> BalanceTxResponse
$cfrom :: forall x. BalanceTxResponse -> Rep BalanceTxResponse x
Generic)
  deriving anyclass ([BalanceTxResponse] -> Encoding
[BalanceTxResponse] -> Value
BalanceTxResponse -> Encoding
BalanceTxResponse -> Value
(BalanceTxResponse -> Value)
-> (BalanceTxResponse -> Encoding)
-> ([BalanceTxResponse] -> Value)
-> ([BalanceTxResponse] -> Encoding)
-> ToJSON BalanceTxResponse
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [BalanceTxResponse] -> Encoding
$ctoEncodingList :: [BalanceTxResponse] -> Encoding
toJSONList :: [BalanceTxResponse] -> Value
$ctoJSONList :: [BalanceTxResponse] -> Value
toEncoding :: BalanceTxResponse -> Encoding
$ctoEncoding :: BalanceTxResponse -> Encoding
toJSON :: BalanceTxResponse -> Value
$ctoJSON :: BalanceTxResponse -> Value
ToJSON, Value -> Parser [BalanceTxResponse]
Value -> Parser BalanceTxResponse
(Value -> Parser BalanceTxResponse)
-> (Value -> Parser [BalanceTxResponse])
-> FromJSON BalanceTxResponse
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [BalanceTxResponse]
$cparseJSONList :: Value -> Parser [BalanceTxResponse]
parseJSON :: Value -> Parser BalanceTxResponse
$cparseJSON :: Value -> Parser BalanceTxResponse
FromJSON)

instance Pretty BalanceTxResponse where
  pretty :: BalanceTxResponse -> Doc ann
pretty = \case
    BalanceTxFailed WalletAPIError
e   -> Doc ann
"BalanceTxFailed:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> WalletAPIError -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty WalletAPIError
e
    BalanceTxSuccess CardanoTx
tx -> Doc ann
"BalanceTxSuccess:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> TxId -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty (CardanoTx -> TxId
getCardanoTxId CardanoTx
tx)

_AwaitTxStatusChangeResp' :: C.TxId -> Prism' PABResp TxStatus
_AwaitTxStatusChangeResp' :: TxId -> Prism' PABResp TxStatus
_AwaitTxStatusChangeResp' TxId
i =
  (TxStatus -> PABResp)
-> (PABResp -> Maybe TxStatus) -> Prism' PABResp TxStatus
forall b s a. (b -> s) -> (s -> Maybe a) -> Prism s s a b
prism'
    (TxId -> TxStatus -> PABResp
AwaitTxStatusChangeResp TxId
i)
    (\case { AwaitTxStatusChangeResp TxId
i' TxStatus
s | TxId
i TxId -> TxId -> Bool
forall a. Eq a => a -> a -> Bool
== TxId
i' -> TxStatus -> Maybe TxStatus
forall a. a -> Maybe a
Just TxStatus
s; PABResp
_ -> Maybe TxStatus
forall a. Maybe a
Nothing })

balanceTxResponse :: Iso' BalanceTxResponse (Either WalletAPIError CardanoTx)
balanceTxResponse :: p (Either WalletAPIError CardanoTx)
  (f (Either WalletAPIError CardanoTx))
-> p BalanceTxResponse (f BalanceTxResponse)
balanceTxResponse = (BalanceTxResponse -> Either WalletAPIError CardanoTx)
-> (Either WalletAPIError CardanoTx -> BalanceTxResponse)
-> Iso
     BalanceTxResponse
     BalanceTxResponse
     (Either WalletAPIError CardanoTx)
     (Either WalletAPIError CardanoTx)
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso BalanceTxResponse -> Either WalletAPIError CardanoTx
f Either WalletAPIError CardanoTx -> BalanceTxResponse
g where
  f :: BalanceTxResponse -> Either WalletAPIError CardanoTx
f = \case { BalanceTxFailed WalletAPIError
w -> WalletAPIError -> Either WalletAPIError CardanoTx
forall a b. a -> Either a b
Left WalletAPIError
w; BalanceTxSuccess CardanoTx
t -> CardanoTx -> Either WalletAPIError CardanoTx
forall a b. b -> Either a b
Right CardanoTx
t }
  g :: Either WalletAPIError CardanoTx -> BalanceTxResponse
g = (WalletAPIError -> BalanceTxResponse)
-> (CardanoTx -> BalanceTxResponse)
-> Either WalletAPIError CardanoTx
-> BalanceTxResponse
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either WalletAPIError -> BalanceTxResponse
BalanceTxFailed CardanoTx -> BalanceTxResponse
BalanceTxSuccess

data WriteBalancedTxResponse =
  WriteBalancedTxFailed WalletAPIError
  | WriteBalancedTxSuccess CardanoTx
  deriving stock (WriteBalancedTxResponse -> WriteBalancedTxResponse -> Bool
(WriteBalancedTxResponse -> WriteBalancedTxResponse -> Bool)
-> (WriteBalancedTxResponse -> WriteBalancedTxResponse -> Bool)
-> Eq WriteBalancedTxResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: WriteBalancedTxResponse -> WriteBalancedTxResponse -> Bool
$c/= :: WriteBalancedTxResponse -> WriteBalancedTxResponse -> Bool
== :: WriteBalancedTxResponse -> WriteBalancedTxResponse -> Bool
$c== :: WriteBalancedTxResponse -> WriteBalancedTxResponse -> Bool
Eq, Int -> WriteBalancedTxResponse -> ShowS
[WriteBalancedTxResponse] -> ShowS
WriteBalancedTxResponse -> String
(Int -> WriteBalancedTxResponse -> ShowS)
-> (WriteBalancedTxResponse -> String)
-> ([WriteBalancedTxResponse] -> ShowS)
-> Show WriteBalancedTxResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [WriteBalancedTxResponse] -> ShowS
$cshowList :: [WriteBalancedTxResponse] -> ShowS
show :: WriteBalancedTxResponse -> String
$cshow :: WriteBalancedTxResponse -> String
showsPrec :: Int -> WriteBalancedTxResponse -> ShowS
$cshowsPrec :: Int -> WriteBalancedTxResponse -> ShowS
Show, (forall x.
 WriteBalancedTxResponse -> Rep WriteBalancedTxResponse x)
-> (forall x.
    Rep WriteBalancedTxResponse x -> WriteBalancedTxResponse)
-> Generic WriteBalancedTxResponse
forall x. Rep WriteBalancedTxResponse x -> WriteBalancedTxResponse
forall x. WriteBalancedTxResponse -> Rep WriteBalancedTxResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep WriteBalancedTxResponse x -> WriteBalancedTxResponse
$cfrom :: forall x. WriteBalancedTxResponse -> Rep WriteBalancedTxResponse x
Generic)
  deriving anyclass ([WriteBalancedTxResponse] -> Encoding
[WriteBalancedTxResponse] -> Value
WriteBalancedTxResponse -> Encoding
WriteBalancedTxResponse -> Value
(WriteBalancedTxResponse -> Value)
-> (WriteBalancedTxResponse -> Encoding)
-> ([WriteBalancedTxResponse] -> Value)
-> ([WriteBalancedTxResponse] -> Encoding)
-> ToJSON WriteBalancedTxResponse
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [WriteBalancedTxResponse] -> Encoding
$ctoEncodingList :: [WriteBalancedTxResponse] -> Encoding
toJSONList :: [WriteBalancedTxResponse] -> Value
$ctoJSONList :: [WriteBalancedTxResponse] -> Value
toEncoding :: WriteBalancedTxResponse -> Encoding
$ctoEncoding :: WriteBalancedTxResponse -> Encoding
toJSON :: WriteBalancedTxResponse -> Value
$ctoJSON :: WriteBalancedTxResponse -> Value
ToJSON, Value -> Parser [WriteBalancedTxResponse]
Value -> Parser WriteBalancedTxResponse
(Value -> Parser WriteBalancedTxResponse)
-> (Value -> Parser [WriteBalancedTxResponse])
-> FromJSON WriteBalancedTxResponse
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [WriteBalancedTxResponse]
$cparseJSONList :: Value -> Parser [WriteBalancedTxResponse]
parseJSON :: Value -> Parser WriteBalancedTxResponse
$cparseJSON :: Value -> Parser WriteBalancedTxResponse
FromJSON)

instance Pretty WriteBalancedTxResponse where
  pretty :: WriteBalancedTxResponse -> Doc ann
pretty = \case
    WriteBalancedTxFailed WalletAPIError
e   -> Doc ann
"WriteBalancedTxFailed:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> WalletAPIError -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty WalletAPIError
e
    WriteBalancedTxSuccess CardanoTx
tx -> Doc ann
"WriteBalancedTxSuccess:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> TxId -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty (CardanoTx -> TxId
getCardanoTxId CardanoTx
tx)

writeBalancedTxResponse :: Iso' WriteBalancedTxResponse (Either WalletAPIError CardanoTx)
writeBalancedTxResponse :: p (Either WalletAPIError CardanoTx)
  (f (Either WalletAPIError CardanoTx))
-> p WriteBalancedTxResponse (f WriteBalancedTxResponse)
writeBalancedTxResponse = (WriteBalancedTxResponse -> Either WalletAPIError CardanoTx)
-> (Either WalletAPIError CardanoTx -> WriteBalancedTxResponse)
-> Iso
     WriteBalancedTxResponse
     WriteBalancedTxResponse
     (Either WalletAPIError CardanoTx)
     (Either WalletAPIError CardanoTx)
forall s a b t. (s -> a) -> (b -> t) -> Iso s t a b
iso WriteBalancedTxResponse -> Either WalletAPIError CardanoTx
f Either WalletAPIError CardanoTx -> WriteBalancedTxResponse
g where
  f :: WriteBalancedTxResponse -> Either WalletAPIError CardanoTx
f = \case { WriteBalancedTxFailed WalletAPIError
w -> WalletAPIError -> Either WalletAPIError CardanoTx
forall a b. a -> Either a b
Left WalletAPIError
w; WriteBalancedTxSuccess CardanoTx
t -> CardanoTx -> Either WalletAPIError CardanoTx
forall a b. b -> Either a b
Right CardanoTx
t }
  g :: Either WalletAPIError CardanoTx -> WriteBalancedTxResponse
g = (WalletAPIError -> WriteBalancedTxResponse)
-> (CardanoTx -> WriteBalancedTxResponse)
-> Either WalletAPIError CardanoTx
-> WriteBalancedTxResponse
forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either WalletAPIError -> WriteBalancedTxResponse
WriteBalancedTxFailed CardanoTx -> WriteBalancedTxResponse
WriteBalancedTxSuccess

data ActiveEndpoint = ActiveEndpoint
  { ActiveEndpoint -> EndpointDescription
aeDescription :: EndpointDescription -- ^ The name of the endpoint
  , ActiveEndpoint -> Maybe Value
aeMetadata    :: Maybe JSON.Value -- ^ Data that should be shown to the user
  }
  deriving (ActiveEndpoint -> ActiveEndpoint -> Bool
(ActiveEndpoint -> ActiveEndpoint -> Bool)
-> (ActiveEndpoint -> ActiveEndpoint -> Bool) -> Eq ActiveEndpoint
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ActiveEndpoint -> ActiveEndpoint -> Bool
$c/= :: ActiveEndpoint -> ActiveEndpoint -> Bool
== :: ActiveEndpoint -> ActiveEndpoint -> Bool
$c== :: ActiveEndpoint -> ActiveEndpoint -> Bool
Eq, Int -> ActiveEndpoint -> ShowS
[ActiveEndpoint] -> ShowS
ActiveEndpoint -> String
(Int -> ActiveEndpoint -> ShowS)
-> (ActiveEndpoint -> String)
-> ([ActiveEndpoint] -> ShowS)
-> Show ActiveEndpoint
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ActiveEndpoint] -> ShowS
$cshowList :: [ActiveEndpoint] -> ShowS
show :: ActiveEndpoint -> String
$cshow :: ActiveEndpoint -> String
showsPrec :: Int -> ActiveEndpoint -> ShowS
$cshowsPrec :: Int -> ActiveEndpoint -> ShowS
Show, (forall x. ActiveEndpoint -> Rep ActiveEndpoint x)
-> (forall x. Rep ActiveEndpoint x -> ActiveEndpoint)
-> Generic ActiveEndpoint
forall x. Rep ActiveEndpoint x -> ActiveEndpoint
forall x. ActiveEndpoint -> Rep ActiveEndpoint x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ActiveEndpoint x -> ActiveEndpoint
$cfrom :: forall x. ActiveEndpoint -> Rep ActiveEndpoint x
Generic)
  deriving anyclass ([ActiveEndpoint] -> Encoding
[ActiveEndpoint] -> Value
ActiveEndpoint -> Encoding
ActiveEndpoint -> Value
(ActiveEndpoint -> Value)
-> (ActiveEndpoint -> Encoding)
-> ([ActiveEndpoint] -> Value)
-> ([ActiveEndpoint] -> Encoding)
-> ToJSON ActiveEndpoint
forall a.
(a -> Value)
-> (a -> Encoding)
-> ([a] -> Value)
-> ([a] -> Encoding)
-> ToJSON a
toEncodingList :: [ActiveEndpoint] -> Encoding
$ctoEncodingList :: [ActiveEndpoint] -> Encoding
toJSONList :: [ActiveEndpoint] -> Value
$ctoJSONList :: [ActiveEndpoint] -> Value
toEncoding :: ActiveEndpoint -> Encoding
$ctoEncoding :: ActiveEndpoint -> Encoding
toJSON :: ActiveEndpoint -> Value
$ctoJSON :: ActiveEndpoint -> Value
ToJSON, Value -> Parser [ActiveEndpoint]
Value -> Parser ActiveEndpoint
(Value -> Parser ActiveEndpoint)
-> (Value -> Parser [ActiveEndpoint]) -> FromJSON ActiveEndpoint
forall a.
(Value -> Parser a) -> (Value -> Parser [a]) -> FromJSON a
parseJSONList :: Value -> Parser [ActiveEndpoint]
$cparseJSONList :: Value -> Parser [ActiveEndpoint]
parseJSON :: Value -> Parser ActiveEndpoint
$cparseJSON :: Value -> Parser ActiveEndpoint
FromJSON)

instance Pretty ActiveEndpoint where
  pretty :: ActiveEndpoint -> Doc ann
pretty ActiveEndpoint{EndpointDescription
aeDescription :: EndpointDescription
aeDescription :: ActiveEndpoint -> EndpointDescription
aeDescription, Maybe Value
aeMetadata :: Maybe Value
aeMetadata :: ActiveEndpoint -> Maybe Value
aeMetadata} =
    Int -> Doc ann -> Doc ann
forall ann. Int -> Doc ann -> Doc ann
indent Int
2 (Doc ann -> Doc ann) -> Doc ann -> Doc ann
forall a b. (a -> b) -> a -> b
$ [Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
vsep
      [ Doc ann
"Endpoint:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> EndpointDescription -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty EndpointDescription
aeDescription
      , Doc ann
"Metadata:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Maybe Value -> Doc ann
forall a ann. Show a => a -> Doc ann
viaShow Maybe Value
aeMetadata
      ]

makePrisms ''PABReq

makePrisms ''PABResp

makePrisms ''ChainIndexQuery

makePrisms ''ChainIndexResponse