From f42986fc774b027e601b9a2361181a174000b15a Mon Sep 17 00:00:00 2001 From: Hernan Rajchert Date: Mon, 13 Sep 2021 19:15:03 -0300 Subject: [PATCH] Improved comments --- .../src/Capability/PlutusApps/MarloweApp.purs | 11 +++++++++++ .../src/Capability/PlutusApps/MarloweApp/Types.purs | 10 +--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/marlowe-dashboard-client/src/Capability/PlutusApps/MarloweApp.purs b/marlowe-dashboard-client/src/Capability/PlutusApps/MarloweApp.purs index 7c0e8c9b7c7..1bf459c23af 100644 --- a/marlowe-dashboard-client/src/Capability/PlutusApps/MarloweApp.purs +++ b/marlowe-dashboard-client/src/Capability/PlutusApps/MarloweApp.purs @@ -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 => @@ -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 diff --git a/marlowe-dashboard-client/src/Capability/PlutusApps/MarloweApp/Types.purs b/marlowe-dashboard-client/src/Capability/PlutusApps/MarloweApp/Types.purs index 2c9d28da300..ff9be9609e9 100644 --- a/marlowe-dashboard-client/src/Capability/PlutusApps/MarloweApp/Types.purs +++ b/marlowe-dashboard-client/src/Capability/PlutusApps/MarloweApp/Types.purs @@ -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 @@ -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