Skip to content

Commit

Permalink
Improved comments
Browse files Browse the repository at this point in the history
  • Loading branch information
hrajchert committed Sep 13, 2021
1 parent 100dbed commit f42986f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
11 changes: 11 additions & 0 deletions marlowe-dashboard-client/src/Capability/PlutusApps/MarloweApp.purs
Expand Up @@ -83,6 +83,9 @@ createEndpointMutex = do
redeem <- EAVar.empty
pure { create, applyInputs, redeem }

-- Plutus contracts have endpoints that can be available or not. We get notified by the
-- websocket message NewActiveEndpoints when the status change, and we use this function
-- to update some mutex we use to restrict access to unavailable methods.
onNewActiveEndpoints ::
forall env m.
MonadAff m =>
Expand All @@ -102,11 +105,19 @@ onNewActiveEndpoints endpoints = do
)
endpoints

-- For each endpoint:
updateEndpoint name getter = do
mutex <- asks $ view (_marloweAppEndpointMutex <<< getter)
-- We check if it's available or not
if (elem name endpointsName) then
-- If it's available we put a unit in the mutex, to allow
-- users to call the endpoint. If the mutex already has a unit,
-- `tryPut` will return false but wont block the thread.
void $ liftAff $ AVar.tryPut unit mutex
else
-- If it's not available we remove a unit from the mutex to make
-- callers to wait until we put a unit. If the mutex was already
-- empty, tryTake will return Nothing but wont block the thread.
void $ liftAff $ AVar.tryTake mutex
updateEndpoint "redeem" _redeem
updateEndpoint "create" _create
Expand Down
@@ -1,8 +1,7 @@
-- The types are defined separated from the MarloweApp to avoid this circular dependency
-- Capability.PlutusApps.MarloweApp -> AppM -> Env -> Capability.PlutusApps.MarloweApp
module Capability.PlutusApps.MarloweApp.Types
( MarloweAppEndpoint(..)
, LastResult(..)
( LastResult(..)
, EndpointName
, MarloweError
, MarloweAppState
Expand Down Expand Up @@ -90,10 +89,3 @@ type EndpointMutex

type MarloweAppEndpointMutexEnv env
= { marloweAppEndpointMutex :: EndpointMutex | env }

-- FIXME: Delete
-- These are the endpoints of the main marlowe (control) contract.
data MarloweAppEndpoint
= Create
| ApplyInputs
| Redeem

0 comments on commit f42986f

Please sign in to comment.