Module

Ctl.Internal.Contract.Monad

#Contract

newtype Contract (a :: Type)

The Contract monad is a newtype wrapper over ReaderT on ContractEnv over asynchronous effects, Aff. Throwing and catching errors can therefore be implemented with native JavaScript Effect.Exception.Errors and Effect.Class.Console.log replaces the Writer monad. Aff enables the user to make effectful calls inside this Contract monad.

Constructors

Instances

#ContractEnv

type ContractEnv = { backend :: QueryBackend, customLogger :: Maybe (LogLevel -> Message -> Aff Unit), handle :: QueryHandle, hooks :: Hooks, knownTxs :: { backend :: Ref (Set TransactionHash) }, ledgerConstants :: LedgerConstants, logLevel :: LogLevel, networkId :: NetworkId, suppressLogs :: Boolean, synchronizationParams :: ContractSynchronizationParams, timeParams :: ContractTimeParams, usedTxOuts :: UsedTxOuts, wallet :: Maybe Wallet }

A record containing Contract environment - everything a Contract needs to run. It is recommended to use one environment per application to save on websocket connections and to keep track of UsedTxOuts.

Instances

#ContractParams

type ContractParams = { backendParams :: QueryBackendParams, customLogger :: Maybe (LogLevel -> Message -> Aff Unit), hooks :: Hooks, logLevel :: LogLevel, networkId :: NetworkId, suppressLogs :: Boolean, synchronizationParams :: ContractSynchronizationParams, timeParams :: ContractTimeParams, walletSpec :: Maybe WalletSpec }

Options to construct an environment for a Contract to run.

See Contract.Config for pre-defined values for testnet and mainnet.

Use runContract to run a Contract within an implicity constructed ContractEnv environment, or use withContractEnv if your application contains multiple contracts that can reuse the same environment.

#ContractTimeParams

type ContractTimeParams = { awaitTxConfirmed :: { delay :: Milliseconds, timeout :: Seconds }, syncBackend :: { delay :: Milliseconds, timeout :: Seconds }, syncWallet :: { delay :: Milliseconds, timeout :: Seconds }, waitUntilSlot :: { delay :: Milliseconds } }

Delays and timeouts for internal query functions.

  • awaitTxConfirmed.delay - how frequently should we query for Tx in Contract.Transaction.awaitTxConfirmed

  • For info on syncBackend and syncWalletseedoc/query-layers.md`

#ContractSynchronizationParams

type ContractSynchronizationParams = { syncBackendWithWallet :: { beforeBalancing :: Boolean, beforeCip30Methods :: Boolean, errorOnTimeout :: Boolean }, syncWalletWithTransaction :: { beforeTxConfirmed :: Boolean, errorOnTimeout :: Boolean }, syncWalletWithTxInputs :: { beforeCip30Sign :: Boolean, errorOnTimeout :: Boolean } }

#LedgerConstants

type LedgerConstants = { pparams :: ProtocolParameters, systemStart :: SystemStart }

LedgerConstants contains values that technically may change, but we assume to be constant during Contract evaluation.

#mkContractEnv

mkContractEnv :: ContractParams -> Aff ContractEnv

Initializes a Contract environment. Does not ensure finalization. Consider using withContractEnv if possible - otherwise use stopContractEnv to properly finalize.

#runContract

runContract :: forall (a :: Type). ContractParams -> Contract a -> Aff a

Interprets a contract into an Aff context. Implicitly initializes and finalizes a new ContractEnv runtime.

Use withContractEnv if your application contains multiple contracts that can be run in parallel, reusing the same environment (see withContractEnv)

#runContractInEnv

runContractInEnv :: forall (a :: Type). ContractEnv -> Contract a -> Aff a

Runs a contract in existing environment. Does not destroy the environment when contract execution ends.

#runQueryM

runQueryM :: forall (a :: Type) (rest :: Row Type). LogParams rest -> CtlBackend -> QueryM a -> Aff a

#wrapQueryM

wrapQueryM :: forall (a :: Type). QueryM a -> Contract a

#stopContractEnv

stopContractEnv :: ContractEnv -> Aff Unit

Finalizes a Contract environment. Closes the connections in ContractEnv, effectively making it unusable.

#withContractEnv

withContractEnv :: forall (a :: Type). ContractParams -> (ContractEnv -> Aff a) -> Aff a

Constructs and finalizes a contract environment that is usable inside a bracket callback. One environment can be used by multiple Contracts in parallel (see runContractInEnv). Make sure that Aff action does not end before all contracts that use the runtime terminate. Otherwise WebSockets will be closed too early.

#getLedgerConstants

getLedgerConstants :: forall (r :: Row Type). { customLogger :: Maybe (LogLevel -> Message -> Aff Unit), logLevel :: LogLevel | r } -> QueryBackend -> Aff LedgerConstants

Query for the ledger constants using the main backend.

#filterLockedUtxos

#mkQueryHandle

mkQueryHandle :: forall (rest :: Row Type). LogParams rest -> QueryBackend -> QueryHandle

Modules