Skip to content

Commit ea23586

Browse files
Merge pull request #87 from mlabs-haskell/sam/confirm-until-time
Change awaitConfirmedTxSlot to Time
2 parents c1918de + a9e1228 commit ea23586

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

src/BotPlutusInterface/Helpers.hs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
module BotPlutusInterface.Helpers (awaitTxConfirmedUntilSlot) where
1+
module BotPlutusInterface.Helpers (awaitTxConfirmedUntilTime) where
22

33
import Control.Lens (review)
4+
import Control.Monad (void)
5+
import Data.Kind (Type)
6+
import Data.Row (Row)
47
import Data.Text (pack)
5-
import Ledger (Slot, TxId)
8+
import Ledger (POSIXTime, TxId)
69
import Plutus.Contract.Error (AsContractError, _OtherContractError)
7-
import Plutus.Contract.Request (RollbackState (Unknown), awaitTxStatusChange, currentSlot, waitNSlots)
10+
import Plutus.Contract.Request (RollbackState (Unknown), awaitTxStatusChange, currentTime, waitNSlots)
811
import Plutus.Contract.Types (Contract, throwError)
912
import Prelude
1013

11-
awaitTxConfirmedUntilSlot :: forall w s e. (AsContractError e) => TxId -> Slot -> Contract w s e ()
12-
awaitTxConfirmedUntilSlot txId maxSlot = go 0
13-
where
14-
go :: Integer -> Contract w s e ()
15-
go n = do
16-
mTx <- awaitTxStatusChange txId
17-
case mTx of
18-
Unknown -> do
19-
curSlot <- currentSlot
20-
if curSlot > maxSlot
21-
then
22-
throwError @e $
23-
review _OtherContractError $
24-
pack $
25-
"Could not find transaction - " ++ show txId ++ " - before slot " ++ show maxSlot
26-
else do
27-
_ <- waitNSlots 20
28-
go (n + 1)
29-
_ -> pure ()
14+
awaitTxConfirmedUntilTime :: forall (w :: Type) (s :: Row Type) (e :: Type). (AsContractError e) => TxId -> POSIXTime -> Contract w s e ()
15+
awaitTxConfirmedUntilTime txId maxTime = do
16+
mTx <- awaitTxStatusChange txId
17+
case mTx of
18+
Unknown -> do
19+
curTime <- currentTime
20+
if curTime > maxTime
21+
then
22+
throwError $
23+
review _OtherContractError $
24+
pack $
25+
"Could not find transaction - " ++ show txId ++ " - before " ++ show maxTime
26+
else do
27+
void $ waitNSlots 20
28+
awaitTxConfirmedUntilTime txId maxTime
29+
_ -> pure ()

0 commit comments

Comments
 (0)