Skip to content

Commit dc74df7

Browse files
Add contract exists endpoint
1 parent ea23586 commit dc74df7

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/BotPlutusInterface/Server.hs

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ initState :: IO AppState
8686
initState = AppState <$> newTVarIO Map.empty
8787

8888
-- | 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
9090

9191
-- Endpoints are split up so it is easier to test them. In particular servant-client
9292
-- can not generate a client for the WebSocketEndpoint; this allows us to still
@@ -101,6 +101,13 @@ type ActivateContractEndpoint a =
101101
:> ReqBody '[JSON] (ContractActivationArgs a)
102102
:> Post '[JSON] ContractInstanceId -- Start a new instance.
103103

104+
type ContractLookupEndpoint =
105+
"api"
106+
:> "contract"
107+
:> "exists"
108+
:> ReqBody '[JSON] ContractInstanceId
109+
:> Post '[JSON] Bool
110+
104111
type RawTxEndpoint =
105112
"raw-tx"
106113
:> Capture "tx-id" TxIdCapture
@@ -131,6 +138,7 @@ server :: HasDefinitions t => PABConfig -> AppState -> Server (API t)
131138
server pabConfig state =
132139
websocketHandler state
133140
:<|> activateContractHandler pabConfig state
141+
:<|> contractLookupHandler state
134142
:<|> rawTxHandler pabConfig
135143

136144
apiProxy :: forall (t :: Type). Proxy (API t)
@@ -239,6 +247,14 @@ activateContractHandler pabConf state (ContractActivationArgs cardMessage _) =
239247
case getContract cardMessage of
240248
SomeBuiltin contract -> handleContract pabConf state contract
241249

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+
242258
handleContract ::
243259
forall
244260
(w :: Type)

0 commit comments

Comments
 (0)