{-# LANGUAGE AllowAmbiguousTypes  #-}
{-# LANGUAGE DataKinds            #-}
{-# LANGUAGE DeriveAnyClass       #-}
{-# LANGUAGE DerivingStrategies   #-}
{-# LANGUAGE FlexibleContexts     #-}
{-# LANGUAGE LambdaCase           #-}
{-# LANGUAGE MonoLocalBinds       #-}
{-# LANGUAGE OverloadedStrings    #-}
{-# LANGUAGE TypeApplications     #-}
{-# LANGUAGE UndecidableInstances #-}
-- | Request handlers for contract instance runners.
module Plutus.PAB.Core.ContractInstance.RequestHandlers(
    ContractInstanceMsg(..)
    ) where

import Cardano.BM.Data.Tracer (ToObject (..), TracingVerbosity (..))
import Cardano.BM.Data.Tracer.Extras (Tagged (Tagged), mkObjectStr)
import Data.Aeson (FromJSON, ToJSON)
import Data.Aeson qualified as JSON
import Data.Aeson.Encode.Pretty qualified as JSON
import Data.ByteString.Lazy.Char8 qualified as BSL8
import GHC.Generics (Generic)
import Ledger.Tx (CardanoTx, getCardanoTxId)
import Plutus.Contract.Effects (PABReq (..), PABResp (..))
import Plutus.Contract.Resumable (IterationID, Request (..), Response (..))
import Plutus.Contract.Trace.RequestHandler (RequestHandlerLogMsg)
import Plutus.PAB.Effects.Contract qualified as Contract
import Plutus.PAB.Events.Contract (ContractInstanceId (..))
import Plutus.PAB.Events.ContractInstanceState (PartiallyDecodedResponse)
import Prettyprinter (Pretty, colon, hang, parens, pretty, viaShow, vsep, (<+>))
import Wallet.Emulator.LogMessages (TxBalanceMsg)
import Wallet.Emulator.Types (Wallet)
import Wallet.Types (NotificationError)

-- | Log messages about the contract instance
data ContractInstanceMsg t =
    ProcessFirstInboxMessage ContractInstanceId (Response PABResp)
    | SendingContractStateMessages ContractInstanceId IterationID [Request PABReq]
    | LookingUpStateOfContractInstance
    | CurrentIteration IterationID
    | InboxMessageDoesntMatchIteration IterationID IterationID
    | InboxMessageMatchesIteration
    | InvokingContractUpdate
    | ObtainedNewState
    | ContractLog ContractInstanceId JSON.Value
    | UpdatedContract ContractInstanceId IterationID
    | LookingUpContract (Contract.ContractDef t)
    | InitialisingContract (Contract.ContractDef t) ContractInstanceId
    | InitialPABResp (PartiallyDecodedResponse PABReq)
    | ActivatedContractInstance (Contract.ContractDef t) Wallet ContractInstanceId
    | RunRequestHandler ContractInstanceId Int -- number of requests
    | RunRequestHandlerDidNotHandleAnyEvents
    | StoringSignedTx CardanoTx
    | CallingEndpoint String ContractInstanceId JSON.Value
    | ProcessContractInbox ContractInstanceId
    | HandlingRequest RequestHandlerLogMsg
    | HandlingRequests ContractInstanceId [Request PABReq]
    | BalancingTx TxBalanceMsg
    | NotificationFailed NotificationError
    deriving stock ((forall x. ContractInstanceMsg t -> Rep (ContractInstanceMsg t) x)
-> (forall x.
    Rep (ContractInstanceMsg t) x -> ContractInstanceMsg t)
-> Generic (ContractInstanceMsg t)
forall x. Rep (ContractInstanceMsg t) x -> ContractInstanceMsg t
forall x. ContractInstanceMsg t -> Rep (ContractInstanceMsg t) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall t x. Rep (ContractInstanceMsg t) x -> ContractInstanceMsg t
forall t x. ContractInstanceMsg t -> Rep (ContractInstanceMsg t) x
$cto :: forall t x. Rep (ContractInstanceMsg t) x -> ContractInstanceMsg t
$cfrom :: forall t x. ContractInstanceMsg t -> Rep (ContractInstanceMsg t) x
Generic)

deriving stock instance Eq (Contract.ContractDef t) => Eq (ContractInstanceMsg t)
deriving stock instance Show (Contract.ContractDef t) => Show (ContractInstanceMsg t)
deriving anyclass instance ToJSON (Contract.ContractDef t) => ToJSON (ContractInstanceMsg t)
deriving anyclass instance FromJSON (Contract.ContractDef t) => FromJSON (ContractInstanceMsg t)

instance (ToJSON (Contract.ContractDef t)) => ToObject (ContractInstanceMsg t) where
    toObject :: TracingVerbosity -> ContractInstanceMsg t -> Object
toObject TracingVerbosity
v = \case
        ProcessFirstInboxMessage ContractInstanceId
instanceID Response PABResp
response ->
            Text
-> Either
     (ContractInstanceId, Tagged "response" (Response PABResp))
     ContractInstanceId
-> Object
forall k. StructuredLog k => Text -> k -> Object
mkObjectStr Text
"Processing first contract inbox message" (Either
   (ContractInstanceId, Tagged "response" (Response PABResp))
   ContractInstanceId
 -> Object)
-> Either
     (ContractInstanceId, Tagged "response" (Response PABResp))
     ContractInstanceId
-> Object
forall a b. (a -> b) -> a -> b
$
                case TracingVerbosity
v of
                    TracingVerbosity
MaximalVerbosity -> (ContractInstanceId, Tagged "response" (Response PABResp))
-> Either
     (ContractInstanceId, Tagged "response" (Response PABResp))
     ContractInstanceId
forall a b. a -> Either a b
Left (ContractInstanceId
instanceID, Response PABResp -> Tagged "response" (Response PABResp)
forall k (s :: k) b. b -> Tagged s b
Tagged @"response" Response PABResp
response)
                    TracingVerbosity
_                -> ContractInstanceId
-> Either
     (ContractInstanceId, Tagged "response" (Response PABResp))
     ContractInstanceId
forall a b. b -> Either a b
Right ContractInstanceId
instanceID
        SendingContractStateMessages ContractInstanceId
instanceID IterationID
iterationID [Request PABReq]
requests ->
            Text
-> Either
     (ContractInstanceId, IterationID,
      Tagged "requests" [Request PABReq])
     ContractInstanceId
-> Object
forall k. StructuredLog k => Text -> k -> Object
mkObjectStr Text
"Sending contact state messages" (Either
   (ContractInstanceId, IterationID,
    Tagged "requests" [Request PABReq])
   ContractInstanceId
 -> Object)
-> Either
     (ContractInstanceId, IterationID,
      Tagged "requests" [Request PABReq])
     ContractInstanceId
-> Object
forall a b. (a -> b) -> a -> b
$
                case TracingVerbosity
v of
                    TracingVerbosity
MaximalVerbosity ->
                        (ContractInstanceId, IterationID,
 Tagged "requests" [Request PABReq])
-> Either
     (ContractInstanceId, IterationID,
      Tagged "requests" [Request PABReq])
     ContractInstanceId
forall a b. a -> Either a b
Left (ContractInstanceId
instanceID, IterationID
iterationID, [Request PABReq] -> Tagged "requests" [Request PABReq]
forall k (s :: k) b. b -> Tagged s b
Tagged @"requests" [Request PABReq]
requests)
                    TracingVerbosity
_ -> ContractInstanceId
-> Either
     (ContractInstanceId, IterationID,
      Tagged "requests" [Request PABReq])
     ContractInstanceId
forall a b. b -> Either a b
Right ContractInstanceId
instanceID
        ContractInstanceMsg t
LookingUpStateOfContractInstance -> Text -> () -> Object
forall k. StructuredLog k => Text -> k -> Object
mkObjectStr Text
"looking up state of contract instance" ()
        CurrentIteration IterationID
i -> Text -> IterationID -> Object
forall k. StructuredLog k => Text -> k -> Object
mkObjectStr Text
"current iteration" IterationID
i
        InboxMessageDoesntMatchIteration IterationID
i1 IterationID
i2 ->
            Text
-> (IterationID, Tagged "inbox_message_iteration" IterationID)
-> Object
forall k. StructuredLog k => Text -> k -> Object
mkObjectStr
                Text
"inbox message doesn't match iteration"
                (IterationID
i1, IterationID -> Tagged "inbox_message_iteration" IterationID
forall k (s :: k) b. b -> Tagged s b
Tagged @"inbox_message_iteration" IterationID
i2)
        ContractInstanceMsg t
InboxMessageMatchesIteration -> Text -> () -> Object
forall k. StructuredLog k => Text -> k -> Object
mkObjectStr Text
"inbox message matches iteration" ()
        ContractInstanceMsg t
InvokingContractUpdate -> Text -> () -> Object
forall k. StructuredLog k => Text -> k -> Object
mkObjectStr Text
"invoking contract update" ()
        ContractInstanceMsg t
ObtainedNewState -> Text -> () -> Object
forall k. StructuredLog k => Text -> k -> Object
mkObjectStr Text
"obtained new state" ()
        UpdatedContract ContractInstanceId
instanceID IterationID
iterationID ->
            Text -> (ContractInstanceId, IterationID) -> Object
forall k. StructuredLog k => Text -> k -> Object
mkObjectStr Text
"updated contract" (ContractInstanceId
instanceID, IterationID
iterationID)
        LookingUpContract ContractDef t
t ->
            Text -> Tagged "contract" (ContractDef t) -> Object
forall k. StructuredLog k => Text -> k -> Object
mkObjectStr Text
"looking up contract" (ContractDef t -> Tagged "contract" (ContractDef t)
forall k (s :: k) b. b -> Tagged s b
Tagged @"contract" ContractDef t
t)
        InitialisingContract ContractDef t
t ContractInstanceId
instanceID ->
            Text
-> (Tagged "contract" (ContractDef t), ContractInstanceId)
-> Object
forall k. StructuredLog k => Text -> k -> Object
mkObjectStr Text
"initialising contract" (ContractDef t -> Tagged "contract" (ContractDef t)
forall k (s :: k) b. b -> Tagged s b
Tagged @"contract" ContractDef t
t, ContractInstanceId
instanceID)
        InitialPABResp PartiallyDecodedResponse PABReq
rsp ->
            Text
-> Either (Tagged "response" (PartiallyDecodedResponse PABReq)) ()
-> Object
forall k. StructuredLog k => Text -> k -> Object
mkObjectStr Text
"initial contract response" (Either (Tagged "response" (PartiallyDecodedResponse PABReq)) ()
 -> Object)
-> Either (Tagged "response" (PartiallyDecodedResponse PABReq)) ()
-> Object
forall a b. (a -> b) -> a -> b
$
                case TracingVerbosity
v of
                    TracingVerbosity
MaximalVerbosity -> Tagged "response" (PartiallyDecodedResponse PABReq)
-> Either (Tagged "response" (PartiallyDecodedResponse PABReq)) ()
forall a b. a -> Either a b
Left (PartiallyDecodedResponse PABReq
-> Tagged "response" (PartiallyDecodedResponse PABReq)
forall k (s :: k) b. b -> Tagged s b
Tagged @"response" PartiallyDecodedResponse PABReq
rsp)
                    TracingVerbosity
_                -> ()
-> Either (Tagged "response" (PartiallyDecodedResponse PABReq)) ()
forall a b. b -> Either a b
Right ()
        ActivatedContractInstance ContractDef t
_ Wallet
_ ContractInstanceId
instanceID ->
            Text -> ContractInstanceId -> Object
forall k. StructuredLog k => Text -> k -> Object
mkObjectStr Text
"activated contract instance" ContractInstanceId
instanceID
        RunRequestHandler ContractInstanceId
instanceID Int
n ->
            Text -> (ContractInstanceId, Tagged "num_requests" Int) -> Object
forall k. StructuredLog k => Text -> k -> Object
mkObjectStr Text
"running request handler" (ContractInstanceId
instanceID, Int -> Tagged "num_requests" Int
forall k (s :: k) b. b -> Tagged s b
Tagged @"num_requests" Int
n)
        ContractInstanceMsg t
RunRequestHandlerDidNotHandleAnyEvents ->
            Text -> () -> Object
forall k. StructuredLog k => Text -> k -> Object
mkObjectStr Text
"request handler did not handle any events" ()
        StoringSignedTx CardanoTx
t ->
            Text -> Either CardanoTx () -> Object
forall k. StructuredLog k => Text -> k -> Object
mkObjectStr Text
"storing signed tx" (Either CardanoTx () -> Object) -> Either CardanoTx () -> Object
forall a b. (a -> b) -> a -> b
$
                case TracingVerbosity
v of
                    TracingVerbosity
MaximalVerbosity -> CardanoTx -> Either CardanoTx ()
forall a b. a -> Either a b
Left CardanoTx
t
                    TracingVerbosity
_                -> () -> Either CardanoTx ()
forall a b. b -> Either a b
Right ()
        CallingEndpoint String
ep ContractInstanceId
instanceID Value
vl ->
            Text
-> Either
     (ContractInstanceId, Tagged "endpoint" String)
     (ContractInstanceId, Tagged "endpoint" String,
      Tagged "value" Value)
-> Object
forall k. StructuredLog k => Text -> k -> Object
mkObjectStr Text
"calling endpoint" (Either
   (ContractInstanceId, Tagged "endpoint" String)
   (ContractInstanceId, Tagged "endpoint" String,
    Tagged "value" Value)
 -> Object)
-> Either
     (ContractInstanceId, Tagged "endpoint" String)
     (ContractInstanceId, Tagged "endpoint" String,
      Tagged "value" Value)
-> Object
forall a b. (a -> b) -> a -> b
$
                case TracingVerbosity
v of
                    TracingVerbosity
MinimalVerbosity -> (ContractInstanceId, Tagged "endpoint" String)
-> Either
     (ContractInstanceId, Tagged "endpoint" String)
     (ContractInstanceId, Tagged "endpoint" String,
      Tagged "value" Value)
forall a b. a -> Either a b
Left (ContractInstanceId
instanceID, String -> Tagged "endpoint" String
forall k (s :: k) b. b -> Tagged s b
Tagged @"endpoint" String
ep)
                    TracingVerbosity
_                -> (ContractInstanceId, Tagged "endpoint" String,
 Tagged "value" Value)
-> Either
     (ContractInstanceId, Tagged "endpoint" String)
     (ContractInstanceId, Tagged "endpoint" String,
      Tagged "value" Value)
forall a b. b -> Either a b
Right (ContractInstanceId
instanceID, String -> Tagged "endpoint" String
forall k (s :: k) b. b -> Tagged s b
Tagged @"endpoint" String
ep, Value -> Tagged "value" Value
forall k (s :: k) b. b -> Tagged s b
Tagged @"value" Value
vl)
        ProcessContractInbox ContractInstanceId
instanceID ->
            Text -> ContractInstanceId -> Object
forall k. StructuredLog k => Text -> k -> Object
mkObjectStr Text
"processing contract inbox" ContractInstanceId
instanceID
        HandlingRequest RequestHandlerLogMsg
reqLog ->
            Text -> Tagged "request" RequestHandlerLogMsg -> Object
forall k. StructuredLog k => Text -> k -> Object
mkObjectStr Text
"handling request" (RequestHandlerLogMsg -> Tagged "request" RequestHandlerLogMsg
forall k (s :: k) b. b -> Tagged s b
Tagged @"request" RequestHandlerLogMsg
reqLog)
        HandlingRequests ContractInstanceId
instanceID [Request PABReq]
requests ->
            Text
-> Either
     (ContractInstanceId, Tagged "requests" [Request PABReq],
      Tagged "num_requests" Int)
     (ContractInstanceId, Tagged "num_requests" Int)
-> Object
forall k. StructuredLog k => Text -> k -> Object
mkObjectStr Text
"handling requests" (Either
   (ContractInstanceId, Tagged "requests" [Request PABReq],
    Tagged "num_requests" Int)
   (ContractInstanceId, Tagged "num_requests" Int)
 -> Object)
-> Either
     (ContractInstanceId, Tagged "requests" [Request PABReq],
      Tagged "num_requests" Int)
     (ContractInstanceId, Tagged "num_requests" Int)
-> Object
forall a b. (a -> b) -> a -> b
$
                let n :: Int
n = [Request PABReq] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Request PABReq]
requests in
                case TracingVerbosity
v of
                    TracingVerbosity
MaximalVerbosity -> (ContractInstanceId, Tagged "requests" [Request PABReq],
 Tagged "num_requests" Int)
-> Either
     (ContractInstanceId, Tagged "requests" [Request PABReq],
      Tagged "num_requests" Int)
     (ContractInstanceId, Tagged "num_requests" Int)
forall a b. a -> Either a b
Left (ContractInstanceId
instanceID, [Request PABReq] -> Tagged "requests" [Request PABReq]
forall k (s :: k) b. b -> Tagged s b
Tagged @"requests" [Request PABReq]
requests, Int -> Tagged "num_requests" Int
forall k (s :: k) b. b -> Tagged s b
Tagged @"num_requests" Int
n)
                    TracingVerbosity
_                -> (ContractInstanceId, Tagged "num_requests" Int)
-> Either
     (ContractInstanceId, Tagged "requests" [Request PABReq],
      Tagged "num_requests" Int)
     (ContractInstanceId, Tagged "num_requests" Int)
forall a b. b -> Either a b
Right (ContractInstanceId
instanceID, Int -> Tagged "num_requests" Int
forall k (s :: k) b. b -> Tagged s b
Tagged @"num_requests" Int
n)
        BalancingTx TxBalanceMsg
m ->
            Text -> Either TxBalanceMsg () -> Object
forall k. StructuredLog k => Text -> k -> Object
mkObjectStr Text
"balancing tx" (Either TxBalanceMsg () -> Object)
-> Either TxBalanceMsg () -> Object
forall a b. (a -> b) -> a -> b
$
                case TracingVerbosity
v of
                    TracingVerbosity
MaximalVerbosity -> TxBalanceMsg -> Either TxBalanceMsg ()
forall a b. a -> Either a b
Left TxBalanceMsg
m
                    TracingVerbosity
_                -> () -> Either TxBalanceMsg ()
forall a b. b -> Either a b
Right ()
        NotificationFailed NotificationError
_ ->
            Text -> () -> Object
forall k. StructuredLog k => Text -> k -> Object
mkObjectStr Text
"notification failed" ()
        ContractLog ContractInstanceId
i Value
lg ->
            Text -> (ContractInstanceId, Tagged "message" Value) -> Object
forall k. StructuredLog k => Text -> k -> Object
mkObjectStr Text
"contract log" (ContractInstanceId
i, Value -> Tagged "message" Value
forall k (s :: k) b. b -> Tagged s b
Tagged @"message" Value
lg)

instance Pretty (Contract.ContractDef t) => Pretty (ContractInstanceMsg t) where
    pretty :: ContractInstanceMsg t -> Doc ann
pretty = \case
        ProcessFirstInboxMessage ContractInstanceId
instanceID Response PABResp
response ->
            Doc ann
"processFirstInboxMessage for" 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
instanceID Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann
". The first message is:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Response PABResp -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Response PABResp
response
        SendingContractStateMessages ContractInstanceId
contract IterationID
iterationID [Request PABReq]
requests ->
            Doc ann
"Sending messages for contract" 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
contract Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Doc ann
"at iteration" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> IterationID -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty IterationID
iterationID Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Doc ann
". The contract has the following requests:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> [Request PABReq] -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty [Request PABReq]
requests
        ContractInstanceMsg t
LookingUpStateOfContractInstance -> Doc ann
"Looking up current state of the contract instance."
        CurrentIteration IterationID
i -> Doc ann
"CurrentIteration:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> IterationID -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty IterationID
i
        InboxMessageDoesntMatchIteration IterationID
imsg IterationID
iinstance -> Doc ann
"The iteration of the first inbox message" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann
parens (IterationID -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty IterationID
imsg) Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Doc ann
"does not match the contract instance's iteration" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann
parens (IterationID -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty IterationID
iinstance) Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann
"."
        ContractInstanceMsg t
InboxMessageMatchesIteration -> Doc ann
"The iteration of the first inbox message matches the contract instance's iteration."
        ContractInstanceMsg t
InvokingContractUpdate -> Doc ann
"Invoking contract update."
        ContractInstanceMsg t
ObtainedNewState -> Doc ann
"Obtained new state. Sending contract state messages."
        UpdatedContract ContractInstanceId
instanceID IterationID
iterationID -> Doc ann
"Updated contract" 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
instanceID Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Doc ann
"to new iteration" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> IterationID -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty IterationID
iterationID
        LookingUpContract ContractDef t
c -> Doc ann
"Looking up contract" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> ContractDef t -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty ContractDef t
c
        InitialisingContract ContractDef t
c ContractInstanceId
instanceID -> Doc ann
"Initialising contract" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> ContractDef t -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty ContractDef t
c Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Doc ann
"with 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
instanceID
        InitialPABResp PartiallyDecodedResponse PABReq
rsp -> Doc ann
"Initial contract response:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> PartiallyDecodedResponse PABReq -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty PartiallyDecodedResponse PABReq
rsp
        ActivatedContractInstance ContractDef t
_ Wallet
wallet ContractInstanceId
instanceID -> Doc ann
"Activated instance" 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
instanceID Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Doc ann
"on" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Wallet -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Wallet
wallet
        RunRequestHandler ContractInstanceId
instanceID Int
numRequests -> Doc ann
"Running request handler for" 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
instanceID 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
<+> Int -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty Int
numRequests Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Doc ann
"requests."
        ContractInstanceMsg t
RunRequestHandlerDidNotHandleAnyEvents -> Doc ann
"runRequestHandler: did not handle any requests"
        StoringSignedTx CardanoTx
tx -> Doc ann
"Storing signed tx" 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)
        CallingEndpoint String
endpoint ContractInstanceId
instanceID Value
value ->
            Doc ann
"Calling endpoint" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> String -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty String
endpoint Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Doc ann
"on instance" 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
instanceID 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
<+> Value -> Doc ann
forall a ann. Show a => a -> Doc ann
viaShow Value
value
        ProcessContractInbox ContractInstanceId
i -> Doc ann
"Processing contract inbox for" 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
        HandlingRequest RequestHandlerLogMsg
msg -> RequestHandlerLogMsg -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty RequestHandlerLogMsg
msg
        HandlingRequests ContractInstanceId
i [Request PABReq]
rqs ->
                Int -> Doc ann -> Doc ann
forall ann. Int -> Doc ann -> Doc ann
hang 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
"Handling" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Int -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty ([Request PABReq] -> Int
forall (t :: * -> *) a. Foldable t => t a -> Int
length [Request PABReq]
rqs) Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> Doc ann
"requests for" 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, [Doc ann] -> Doc ann
forall ann. [Doc ann] -> Doc ann
vsep (Request PABReq -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty (Request PABReq -> Doc ann) -> [Request PABReq] -> [Doc ann]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> [Request PABReq]
rqs)]
        BalancingTx TxBalanceMsg
msg -> TxBalanceMsg -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty TxBalanceMsg
msg
        NotificationFailed NotificationError
e -> Doc ann
"Notification failed:" Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> NotificationError -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty NotificationError
e
        ContractLog ContractInstanceId
i Value
m -> ContractInstanceId -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty ContractInstanceId
i Doc ann -> Doc ann -> Doc ann
forall a. Semigroup a => a -> a -> a
<> Doc ann
forall ann. Doc ann
colon Doc ann -> Doc ann -> Doc ann
forall ann. Doc ann -> Doc ann -> Doc ann
<+> String -> Doc ann
forall a ann. Pretty a => a -> Doc ann
pretty (ByteString -> String
BSL8.unpack (ByteString -> String) -> ByteString -> String
forall a b. (a -> b) -> a -> b
$ Value -> ByteString
forall a. ToJSON a => a -> ByteString
JSON.encodePretty Value
m)