Safe Haskell | None |
---|---|

Language | Haskell2010 |

## Synopsis

- type PABEffects t env = '[ContractStore t, ContractEffect t, ContractDefinition t, LogMsg (PABMultiAgentMsg t), TimeEffect, Reader (PABEnvironment t env), Error PABError, IO]
- type PABAction t env a = Eff (PABEffects t env) a
- data EffectHandlers t env = EffectHandlers {
- initialiseEnvironment :: forall effs. (Member (Error PABError) effs, LastMember IO effs) => Eff effs (InstancesState, BlockchainEnv, env)
- handleLogMessages :: forall effs. (Member (Reader (PABEnvironment t env)) effs, Member TimeEffect effs, Member (Error PABError) effs, LastMember IO effs) => Eff (LogMsg (PABMultiAgentMsg t) ': effs) ~> Eff effs
- handleContractStoreEffect :: forall effs. (Member (Reader (PABEnvironment t env)) effs, Member (Error PABError) effs, Member TimeEffect effs, Member (LogMsg (PABMultiAgentMsg t)) effs, LastMember IO effs) => Eff (ContractStore t ': effs) ~> Eff effs
- handleContractEffect :: forall effs. (Member (Reader (PABEnvironment t env)) effs, Member (Error PABError) effs, Member TimeEffect effs, Member (LogMsg (PABMultiAgentMsg t)) effs, LastMember IO effs) => Eff (ContractEffect t ': effs) ~> Eff effs
- handleContractDefinitionEffect :: forall effs. (Member (Reader (PABEnvironment t env)) effs, Member (Error PABError) effs, Member TimeEffect effs, Member (LogMsg (PABMultiAgentMsg t)) effs, LastMember IO effs) => Eff (ContractDefinition t ': effs) ~> Eff effs
- handleServicesEffects :: forall effs. (Member (Reader (PABEnvironment t env)) effs, Member (Error PABError) effs, Member TimeEffect effs, Member (LogMsg (PABMultiAgentMsg t)) effs, LastMember IO effs) => Wallet -> Maybe ContractInstanceId -> Eff (WalletEffect ': (ChainIndexQueryEffect ': (NodeClientEffect ': effs))) ~> Eff effs
- onStartup :: PABAction t env ()
- onShutdown :: PABAction t env ()

- runPAB :: forall t env a. Timeout -> EffectHandlers t env -> PABAction t env a -> IO (Either PABError a)
- runPAB' :: forall t env a. PABEnvironment t env -> PABAction t env a -> IO (Either PABError a)
- data PABEnvironment t env
- reportContractState :: forall t effs. (Member (ContractStore t) effs, PABContract t) => ContractInstanceId -> Eff effs (PartiallyDecodedResponse PABReq)
- activateContract :: forall t env. PABContract t => Wallet -> ContractDef t -> PABAction t env ContractInstanceId
- activateContract' :: forall t env. PABContract t => ContractInstanceState t -> ContractInstanceId -> Wallet -> ContractDef t -> PABAction t env ContractInstanceId
- callEndpointOnInstance :: forall t env a. ToJSON a => ContractInstanceId -> String -> a -> PABAction t env (Maybe NotificationError)
- callEndpointOnInstance' :: forall t env a. ToJSON a => ContractInstanceId -> String -> a -> PABAction t env (Maybe NotificationError)
- payToPaymentPublicKey :: ContractInstanceId -> Wallet -> PaymentPubKeyHash -> Value -> PABAction t env CardanoTx
- type ContractInstanceEffects t env effs = ContractEffect t ': (ContractStore t ': (WalletEffect ': (ChainIndexQueryEffect ': (NodeClientEffect ': (UUIDEffect ': (LogMsg TxBalanceMsg ': (LogMsg RequestHandlerLogMsg ': (LogMsg (ContractInstanceMsg t) ': (LogObserve (LogMessage Text) ': (LogMsg Text ': (Error PABError ': (TimeEffect ': (Reader BlockchainEnv ': (Reader InstancesState ': (Reader (PABEnvironment t env) ': (Reader Wallet ': effs))))))))))))))))
- handleAgentThread :: forall t env a. Wallet -> Maybe ContractInstanceId -> Eff (ContractInstanceEffects t env '[IO]) a -> PABAction t env a
- stopInstance :: forall t env. ContractInstanceId -> PABAction t env ()
- instanceActivity :: forall t env. ContractInstanceId -> PABAction t env Activity
- instanceState :: forall t env. Wallet -> ContractInstanceId -> PABAction t env (State t)
- observableState :: forall t env. ContractInstanceId -> PABAction t env (STM Value)
- waitForState :: forall t env a. (Value -> Maybe a) -> ContractInstanceId -> PABAction t env a
- waitForTxStatusChange :: forall t env. TxId -> PABAction t env TxStatus
- waitForTxOutStatusChange :: forall t env. TxOutRef -> PABAction t env TxOutStatus
- activeEndpoints :: forall t env. ContractInstanceId -> PABAction t env (STM [OpenEndpoint])
- waitForEndpoint :: forall t env. ContractInstanceId -> String -> PABAction t env ()
- yieldedExportTxs :: forall t env. ContractInstanceId -> PABAction t env [ExportTx]
- currentSlot :: forall t env. PABAction t env (STM Slot)
- waitUntilSlot :: forall t env. Slot -> PABAction t env ()
- waitNSlots :: forall t env. Int -> PABAction t env ()
- activeContracts :: forall t env. PABAction t env (Set ContractInstanceId)
- finalResult :: forall t env. ContractInstanceId -> PABAction t env (STM (Maybe Value))
- waitUntilFinished :: forall t env. ContractInstanceId -> PABAction t env (Maybe Value)
- blockchainEnv :: PABEnvironment t env -> BlockchainEnv
- valueAt :: Wallet -> PABAction t env Value
- askUserEnv :: forall t env effs. Member (Reader (PABEnvironment t env)) effs => Eff effs env
- askBlockchainEnv :: forall t env effs. Member (Reader (PABEnvironment t env)) effs => Eff effs BlockchainEnv
- askInstancesState :: forall t env effs. Member (Reader (PABEnvironment t env)) effs => Eff effs InstancesState
- instancesWithStatuses :: forall t env. PABAction t env (Map ContractInstanceId ContractActivityStatus)
- newtype PABRunner t env = PABRunner {
- runPABAction :: forall a. PABAction t env a -> IO (Either PABError a)

- pabRunner :: forall t env. PABAction t env (PABRunner t env)
- handleMappedReader :: forall f g effs. Member (Reader f) effs => (f -> g) -> Reader g ~> Eff effs
- handleUserEnvReader :: forall t env effs. Member (Reader (PABEnvironment t env)) effs => Reader env ~> Eff effs
- handleBlockchainEnvReader :: forall t env effs. Member (Reader (PABEnvironment t env)) effs => Reader BlockchainEnv ~> Eff effs
- handleInstancesStateReader :: forall t env effs. Member (Reader (PABEnvironment t env)) effs => Reader InstancesState ~> Eff effs
- timed :: forall e effs. (Member (LogMsg (EmulatorTimeEvent e)) effs, Member TimeEffect effs) => LogMsg e ~> Eff effs

# Documentation

type PABEffects t env = '[ContractStore t, ContractEffect t, ContractDefinition t, LogMsg (PABMultiAgentMsg t), TimeEffect, Reader (PABEnvironment t env), Error PABError, IO] Source #

Effects that are available in `PABAction`

s.

type PABAction t env a = Eff (PABEffects t env) a Source #

Actions that are run by the PAB.

data EffectHandlers t env Source #

Effect handlers for running the PAB.

runPAB :: forall t env a. Timeout -> EffectHandlers t env -> PABAction t env a -> IO (Either PABError a) Source #

Top-level entry point. Run a `PABAction`

, using the `EffectHandlers`

to
deal with logs, startup and shutdown, contract requests and communication
with external services.

runPAB' :: forall t env a. PABEnvironment t env -> PABAction t env a -> IO (Either PABError a) Source #

Run a PABAction in the context of the given environment. TODO: Clean it up so there is less duplication of the above.

data PABEnvironment t env Source #

Shared data that is needed by all PAB threads.

# Contracts and instances

reportContractState :: forall t effs. (Member (ContractStore t) effs, PABContract t) => ContractInstanceId -> Eff effs (PartiallyDecodedResponse PABReq) Source #

Report the state of a running contract.

activateContract :: forall t env. PABContract t => Wallet -> ContractDef t -> PABAction t env ContractInstanceId Source #

Start a new instance of a contract

activateContract' :: forall t env. PABContract t => ContractInstanceState t -> ContractInstanceId -> Wallet -> ContractDef t -> PABAction t env ContractInstanceId Source #

Start a new instance of a contract, with a given state. Note that we skip running the effects that push the state into the contract store, because we assume that if you're providing the state, it's already present in the store.

callEndpointOnInstance :: forall t env a. ToJSON a => ContractInstanceId -> String -> a -> PABAction t env (Maybe NotificationError) Source #

Call a named endpoint on a contract instance. Waits if the endpoint is not available.

callEndpointOnInstance' :: forall t env a. ToJSON a => ContractInstanceId -> String -> a -> PABAction t env (Maybe NotificationError) Source #

Call a named endpoint on a contract instance. Fails immediately if the endpoint is not available.

payToPaymentPublicKey :: ContractInstanceId -> Wallet -> PaymentPubKeyHash -> Value -> PABAction t env CardanoTx Source #

Make a payment to a payment public key.

# Agent threads

type ContractInstanceEffects t env effs = ContractEffect t ': (ContractStore t ': (WalletEffect ': (ChainIndexQueryEffect ': (NodeClientEffect ': (UUIDEffect ': (LogMsg TxBalanceMsg ': (LogMsg RequestHandlerLogMsg ': (LogMsg (ContractInstanceMsg t) ': (LogObserve (LogMessage Text) ': (LogMsg Text ': (Error PABError ': (TimeEffect ': (Reader BlockchainEnv ': (Reader InstancesState ': (Reader (PABEnvironment t env) ': (Reader Wallet ': effs)))))))))))))))) Source #

Effects available to contract instances with access to external services.

handleAgentThread :: forall t env a. Wallet -> Maybe ContractInstanceId -> Eff (ContractInstanceEffects t env '[IO]) a -> PABAction t env a Source #

Handle an action with `ContractInstanceEffects`

in the context of a wallet.

stopInstance :: forall t env. ContractInstanceId -> PABAction t env () Source #

Stop the instance.

instanceActivity :: forall t env. ContractInstanceId -> PABAction t env Activity Source #

The `Activity`

of the instance.

# Querying the state

instanceState :: forall t env. Wallet -> ContractInstanceId -> PABAction t env (State t) Source #

Get the current state of the contract instance.

observableState :: forall t env. ContractInstanceId -> PABAction t env (STM Value) Source #

An STM transaction that returns the observable state of the contract instance.

waitForState :: forall t env a. (Value -> Maybe a) -> ContractInstanceId -> PABAction t env a Source #

Wait until the observable state of the instance matches a predicate.

waitForTxStatusChange :: forall t env. TxId -> PABAction t env TxStatus Source #

Wait for the transaction to be confirmed on the blockchain.

waitForTxOutStatusChange :: forall t env. TxOutRef -> PABAction t env TxOutStatus Source #

Wait for the transaction output to be confirmed on the blockchain.

activeEndpoints :: forall t env. ContractInstanceId -> PABAction t env (STM [OpenEndpoint]) Source #

The list of endpoints that are currently open

waitForEndpoint :: forall t env. ContractInstanceId -> String -> PABAction t env () Source #

Wait until the endpoint becomes active.

yieldedExportTxs :: forall t env. ContractInstanceId -> PABAction t env [ExportTx] Source #

Get exported transactions waiting to be balanced, signed and submitted by an external client.

waitUntilSlot :: forall t env. Slot -> PABAction t env () Source #

Wait until the target slot number has been reached

waitNSlots :: forall t env. Int -> PABAction t env () Source #

activeContracts :: forall t env. PABAction t env (Set ContractInstanceId) Source #

The set of all active contracts.

finalResult :: forall t env. ContractInstanceId -> PABAction t env (STM (Maybe Value)) Source #

The final result of the instance (waits until it is available)

waitUntilFinished :: forall t env. ContractInstanceId -> PABAction t env (Maybe Value) Source #

Wait until the contract is done, then return the error (if any)

blockchainEnv :: PABEnvironment t env -> BlockchainEnv Source #

askUserEnv :: forall t env effs. Member (Reader (PABEnvironment t env)) effs => Eff effs env Source #

Read the `env`

from the environment

askBlockchainEnv :: forall t env effs. Member (Reader (PABEnvironment t env)) effs => Eff effs BlockchainEnv Source #

Read the `BlockchainEnv`

from the environment

askInstancesState :: forall t env effs. Member (Reader (PABEnvironment t env)) effs => Eff effs InstancesState Source #

Read the `InstancesState`

from the environment

instancesWithStatuses :: forall t env. PABAction t env (Map ContractInstanceId ContractActivityStatus) Source #

# Run PAB effects in separate threads

pabRunner :: forall t env. PABAction t env (PABRunner t env) Source #

Get a `PABRunner`

that uses the current environment.

# Effect handlers

handleMappedReader :: forall f g effs. Member (Reader f) effs => (f -> g) -> Reader g ~> Eff effs Source #

handleUserEnvReader :: forall t env effs. Member (Reader (PABEnvironment t env)) effs => Reader env ~> Eff effs Source #

handleBlockchainEnvReader :: forall t env effs. Member (Reader (PABEnvironment t env)) effs => Reader BlockchainEnv ~> Eff effs Source #

handleInstancesStateReader :: forall t env effs. Member (Reader (PABEnvironment t env)) effs => Reader InstancesState ~> Eff effs Source #