@@ -86,7 +86,7 @@ initState :: IO AppState
86
86
initState = AppState <$> newTVarIO Map. empty
87
87
88
88
-- | Mock API Schema, stripped endpoints that we don't use in this project
89
- type API a = WebSocketEndpoint :<|> ActivateContractEndpoint a :<|> RawTxEndpoint
89
+ type API a = WebSocketEndpoint :<|> ActivateContractEndpoint a :<|> ContractLookupEndpoint :<|> RawTxEndpoint
90
90
91
91
-- Endpoints are split up so it is easier to test them. In particular servant-client
92
92
-- can not generate a client for the WebSocketEndpoint; this allows us to still
@@ -101,6 +101,13 @@ type ActivateContractEndpoint a =
101
101
:> ReqBody '[JSON ] (ContractActivationArgs a )
102
102
:> Post '[JSON ] ContractInstanceId -- Start a new instance.
103
103
104
+ type ContractLookupEndpoint =
105
+ " api"
106
+ :> " contract"
107
+ :> " exists"
108
+ :> ReqBody '[JSON ] ContractInstanceId
109
+ :> Post '[JSON ] Bool
110
+
104
111
type RawTxEndpoint =
105
112
" raw-tx"
106
113
:> Capture " tx-id" TxIdCapture
@@ -131,6 +138,7 @@ server :: HasDefinitions t => PABConfig -> AppState -> Server (API t)
131
138
server pabConfig state =
132
139
websocketHandler state
133
140
:<|> activateContractHandler pabConfig state
141
+ :<|> contractLookupHandler state
134
142
:<|> rawTxHandler pabConfig
135
143
136
144
apiProxy :: forall (t :: Type ). Proxy (API t )
@@ -239,6 +247,14 @@ activateContractHandler pabConf state (ContractActivationArgs cardMessage _) =
239
247
case getContract cardMessage of
240
248
SomeBuiltin contract -> handleContract pabConf state contract
241
249
250
+ contractLookupHandler ::
251
+ AppState ->
252
+ ContractInstanceId ->
253
+ Handler Bool
254
+ contractLookupHandler (AppState s) contractInstanceId = liftIO . atomically $ do
255
+ instances <- readTVar s
256
+ return $ Map. member contractInstanceId instances
257
+
242
258
handleContract ::
243
259
forall
244
260
(w :: Type )
0 commit comments