@@ -24,15 +24,17 @@ import BotPlutusInterface.Effects (
2424 saveBudget ,
2525 slotToPOSIXTime ,
2626 threadDelay ,
27- uploadDir
27+ uploadDir ,
2828 )
2929import BotPlutusInterface.Files (DummyPrivKey (FromSKey , FromVKey ))
3030import BotPlutusInterface.Files qualified as Files
3131import BotPlutusInterface.Types (
3232 ContractEnvironment (.. ),
3333 LogLevel (Debug , Warn ),
3434 Tip (block , slot ),
35- TxFile (Signed ), spInterval , spBlocksTimeOut
35+ TxFile (Signed ),
36+ -- spBlocksTimeOut,
37+ -- spInterval,
3638 )
3739import Cardano.Api (AsType (.. ), EraInMode (.. ), Tx (Tx ))
3840import Control.Lens (preview , (^.) )
@@ -52,6 +54,7 @@ import Data.Row (Row)
5254import Data.Text (Text )
5355import Data.Text qualified as Text
5456import Data.Vector qualified as V
57+ import Debug.Trace (traceM )
5558import Ledger (POSIXTime )
5659import Ledger qualified
5760import Ledger.Address (PaymentPubKeyHash (PaymentPubKeyHash ))
@@ -209,35 +212,43 @@ awaitTxStatusChange ::
209212 Ledger. TxId ->
210213 Eff effs TxStatus
211214awaitTxStatusChange contractEnv txId = do
212- let txStatusPolling = contractEnv. cePABConfig. pcTxStausPolling
213- pollInterval = fromIntegral $ spInterval txStatusPolling
214- pollTimeOut = fromIntegral $ spBlocksTimeOut txStatusPolling
215- cutOffBlock <- (pollTimeOut + ) <$> currentBlock contractEnv
215+ traceM " @@ await stats change"
216+ checkStartedBlock <- currentBlock contractEnv
216217 printBpiLog @ w Debug $ pretty $ " Awaiting status change for " ++ show txId
217- txStausCheckLoop txId contractEnv pollInterval cutOffBlock
218+ txStausCheckLoop txId contractEnv checkStartedBlock
218219
219220txStausCheckLoop ::
220221 forall (w :: Type ) (effs :: [Type -> Type ]).
221222 Member (PABEffect w ) effs =>
222223 Ledger. TxId ->
223224 ContractEnvironment w ->
224- Int ->
225225 Integer ->
226226 Eff effs TxStatus
227- txStausCheckLoop txId contractEnv pollInterval cutOffBlock = do
227+ txStausCheckLoop txId contractEnv checkStartedBlock = do
228+ let txStatusPolling = contractEnv. cePABConfig. pcTxStatusPolling
229+ pollInterval = fromIntegral $ txStatusPolling. spInterval
230+ pollTimeout = txStatusPolling. spBlocksTimeOut
231+ cutOffBlock = checkStartedBlock + fromIntegral pollTimeout
228232 currBlock <- currentBlock contractEnv
229233 txStatus <- getStatus
230234 case (txStatus, currBlock > cutOffBlock) of
231235 (status, True ) -> do
232- logDebug $ " Awaiting preiod for TxId " ++ show txId
233- ++ " status change is over, current status: " ++ show status
236+ logDebug . mconcat $
237+ [ " Timeout period for waiting `TxId "
238+ , show txId
239+ , " ` status cahnge is over"
240+ , " - waited "
241+ , show pollTimeout
242+ , " blocks."
243+ , " Current status: "
244+ , show status
245+ ]
234246 return status
235247 (Unknown , _) -> do
236248 threadDelay @ w pollInterval
237- txStausCheckLoop txId contractEnv pollInterval cutOffBlock
249+ retry
238250 (status, _) -> return status
239251 where
240- -- | get Tx status with extensive debug logging
241252 getStatus = do
242253 mTx <- queryChainIndexForTxState
243254 case mTx of
@@ -251,16 +262,9 @@ txStausCheckLoop txId contractEnv pollInterval cutOffBlock = do
251262 Left e -> do
252263 logDebug $ " Staus check for TxId " ++ show txId ++ " failed with " ++ show e
253264 return Unknown
254- Right st -> case st of
255- Unknown -> do
256- logDebug $ " Staus for TxId " ++ show txId ++ " is Unknown"
257- return Unknown
258- other -> do
259- logDebug $
260- " Staus for TxId " ++ show txId ++ " is " ++ show other
261- pure other
262-
263- logDebug = printBpiLog @ w Debug . pretty
265+ Right st -> do
266+ logDebug $ " Status for TxId " ++ show txId ++ " is " ++ show st
267+ return st
264268
265269 queryChainIndexForTxState :: Eff effs (Maybe TxIdState )
266270 queryChainIndexForTxState = do
@@ -271,6 +275,11 @@ txStausCheckLoop txId contractEnv pollInterval cutOffBlock = do
271275 pure . Just $ fromTx blk tx
272276 Nothing -> pure Nothing
273277
278+ logDebug = printBpiLog @ w Debug . pretty
279+ -- logDebug = traceM . show . pretty
280+
281+ retry = txStausCheckLoop txId contractEnv checkStartedBlock
282+
274283-- | This will FULLY balance a transaction
275284balanceTx ::
276285 forall (w :: Type ) (effs :: [Type -> Type ]).
0 commit comments