@@ -31,7 +31,7 @@ import Ledger (POSIXTime)
3131import Ledger.Address (PaymentPubKeyHash (PaymentPubKeyHash ))
3232import Ledger.Constraints.OffChain (UnbalancedTx (.. ))
3333import Ledger.Slot (Slot (Slot ))
34- import Ledger.TimeSlot (posixTimeRangeToContainedSlotRange , slotToEndPOSIXTime )
34+ import Ledger.TimeSlot (posixTimeRangeToContainedSlotRange , posixTimeToEnclosingSlot , slotToEndPOSIXTime )
3535import Ledger.Tx (CardanoTx )
3636import Ledger.Tx qualified as Tx
3737import Plutus.ChainIndex.Types (RollbackState (Committed ), TxValidity (.. ))
@@ -121,7 +121,6 @@ handlePABReq contractEnv req = do
121121 -- Handled requests --
122122 ----------------------
123123 OwnPaymentPublicKeyHashReq ->
124- -- TODO: Should be able to get this from the wallet, hardcoded for now
125124 pure $ OwnPaymentPublicKeyHashResp $ PaymentPubKeyHash contractEnv. cePABConfig. pcOwnPubKeyHash
126125 OwnContractInstanceIdReq ->
127126 pure $ OwnContractInstanceIdResp (ceContractInstanceId contractEnv)
@@ -132,6 +131,7 @@ handlePABReq contractEnv req = do
132131 WriteBalancedTxReq tx ->
133132 WriteBalancedTxResp <$> writeBalancedTx @ w contractEnv tx
134133 AwaitSlotReq s -> AwaitSlotResp <$> awaitSlot @ w contractEnv s
134+ AwaitTimeReq t -> AwaitTimeResp <$> awaitTime @ w contractEnv t
135135 CurrentSlotReq -> CurrentSlotResp <$> currentSlot @ w contractEnv
136136 CurrentTimeReq -> CurrentTimeResp <$> currentTime @ w contractEnv
137137 PosixTimeRangeToContainedSlotRangeReq posixTimeRange ->
@@ -146,7 +146,9 @@ handlePABReq contractEnv req = do
146146 -- AwaitUtxoSpentReq txOutRef -> pure $ AwaitUtxoSpentResp ChainIndexTx
147147 -- AwaitUtxoProducedReq Address -> pure $ AwaitUtxoProducedResp (NonEmpty ChainIndexTx)
148148 AwaitTxStatusChangeReq txId -> pure $ AwaitTxStatusChangeResp txId (Committed TxValid () )
149+ -- AwaitTxOutStatusChangeReq TxOutRef
149150 -- ExposeEndpointReq ActiveEndpoint -> ExposeEndpointResp EndpointDescription (EndpointValue JSON.Value)
151+ -- YieldUnbalancedTxReq UnbalancedTx
150152 unsupported -> error (" Unsupported PAB effect: " ++ show unsupported)
151153
152154 printLog @ w Debug $ show resp
@@ -220,6 +222,20 @@ awaitSlot contractEnv s@(Slot n) = do
220222 then awaitSlot contractEnv s
221223 else pure $ Slot tip'. slot
222224
225+ {- | Wait at least until the given time. Uses the awaitSlot under the hood, so the same constraints
226+ are applying here as well.
227+ -}
228+ awaitTime ::
229+ forall (w :: Type ) (effs :: [Type -> Type ]).
230+ Member (PABEffect w ) effs =>
231+ ContractEnvironment w ->
232+ POSIXTime ->
233+ Eff effs POSIXTime
234+ awaitTime ce = fmap fromSlot . awaitSlot ce . toSlot
235+ where
236+ toSlot = posixTimeToEnclosingSlot ce. cePABConfig. pcSlotConfig
237+ fromSlot = slotToEndPOSIXTime ce. cePABConfig. pcSlotConfig
238+
223239currentSlot ::
224240 forall (w :: Type ) (effs :: [Type -> Type ]).
225241 Member (PABEffect w ) effs =>
0 commit comments