44
55module BotPlutusInterface.Contract (runContract , handleContract ) where
66
7- import BotPlutusInterface.Balance qualified as PreBalance
7+ import BotPlutusInterface.Balance qualified as Balance
88import BotPlutusInterface.BodyBuilder qualified as BodyBuilder
99import BotPlutusInterface.CardanoCLI qualified as CardanoCLI
1010import BotPlutusInterface.Collateral qualified as Collateral
@@ -240,7 +240,7 @@ awaitTxStatusChange contractEnv txId = do
240240 txStatus <- getStatus
241241 case (txStatus, currBlock > cutOffBlock) of
242242 (status, True ) -> do
243- helperLog ( Debug [ PABLog ]) . mconcat . fmap mconcat $
243+ helperLog . mconcat . fmap mconcat $
244244 [ [" Timeout for waiting `TxId " , show txId, " ` status change reached" ]
245245 , [" - waited " , show pollTimeout, " blocks." ]
246246 , [" Current status: " , show status]
@@ -255,17 +255,17 @@ awaitTxStatusChange contractEnv txId = do
255255 mTx <- queryChainIndexForTxState
256256 case mTx of
257257 Nothing -> do
258- helperLog ( Debug [ PABLog ]) $ " TxId " ++ show txId ++ " not found in index"
258+ helperLog $ " TxId " ++ show txId ++ " not found in index"
259259 pure Unknown
260260 Just txState -> do
261- helperLog ( Debug [ PABLog ]) $ " TxId " ++ show txId ++ " found in index, checking status"
261+ helperLog $ " TxId " ++ show txId ++ " found in index, checking status"
262262 blk <- fromInteger <$> currentBlock contractEnv
263263 case transactionStatus blk txState txId of
264264 Left e -> do
265- helperLog ( Debug [ PABLog ]) $ " Status check for TxId " ++ show txId ++ " failed with " ++ show e
265+ helperLog $ " Status check for TxId " ++ show txId ++ " failed with " ++ show e
266266 pure Unknown
267267 Right st -> do
268- helperLog ( Debug [ PABLog ]) $ " Status for TxId " ++ show txId ++ " is " ++ show st
268+ helperLog $ " Status for TxId " ++ show txId ++ " is " ++ show st
269269 pure st
270270
271271 queryChainIndexForTxState :: Eff effs (Maybe TxIdState )
@@ -277,8 +277,7 @@ awaitTxStatusChange contractEnv txId = do
277277 pure . Just $ fromTx blk tx
278278 Nothing -> pure Nothing
279279
280- helperLog :: LogLevel -> String -> Eff effs ()
281- helperLog (Debug a) = printBpiLog @ w (Debug a) . pretty
280+ helperLog = printBpiLog @ w (Debug [CollateralLog ]) . pretty
282281
283282-- | This will FULLY balance a transaction
284283balanceTx ::
@@ -296,21 +295,16 @@ balanceTx contractEnv unbalancedTx = do
296295 Left e -> pure $ BalanceTxFailed (OtherError e)
297296 _ -> do
298297 uploadDir @ w pabConf. pcSigningKeyFileDir
299- eitherPreBalancedTx <-
300- if PreBalance. txUsesScripts (unBalancedTxTx unbalancedTx)
301- then
302- PreBalance. balanceTxIO' @ w
303- PreBalance. defaultBalanceConfig {PreBalance. bcHasScripts = True }
304- pabConf
305- pabConf. pcOwnPubKeyHash
306- unbalancedTx
307- else
308- PreBalance. balanceTxIO @ w
309- pabConf
310- pabConf. pcOwnPubKeyHash
311- unbalancedTx
312-
313- pure $ either (BalanceTxFailed . InsufficientFunds ) (BalanceTxSuccess . Right ) eitherPreBalancedTx
298+ eitherBalancedTx <-
299+ Balance. balanceTxIO' @ w
300+ Balance. defaultBalanceConfig
301+ { Balance. bcHasScripts = Balance. txUsesScripts (unBalancedTxTx unbalancedTx)
302+ }
303+ pabConf
304+ pabConf. pcOwnPubKeyHash
305+ unbalancedTx
306+
307+ pure $ either (BalanceTxFailed . InsufficientFunds ) (BalanceTxSuccess . Right ) eitherBalancedTx
314308
315309-- | This step would build tx files, write them to disk and submit them to the chain
316310writeBalancedTx ::
@@ -485,7 +479,7 @@ handleCollateral cEnv = do
485479 case result of
486480 Right collteralUtxo ->
487481 setInMemCollateral @ w collteralUtxo
488- >> Right <$> printBpiLog @ w (Debug [PABLog ]) " successfully set the collateral utxo in env."
482+ >> Right <$> printBpiLog @ w (Debug [CollateralLog ]) " successfully set the collateral utxo in env."
489483 Left err -> pure $ Left $ " Failed to make collateral: " <> err
490484 where
491485 --
@@ -510,8 +504,8 @@ makeCollateral cEnv = runEitherT $ do
510504
511505 balancedTx <-
512506 newEitherT $
513- PreBalance . balanceTxIO' @ w
514- PreBalance . defaultBalanceConfig {PreBalance . bcHasScripts = False , PreBalance . bcSeparateChange = True }
507+ Balance . balanceTxIO' @ w
508+ Balance . defaultBalanceConfig {Balance . bcHasScripts = False , Balance . bcSeparateChange = True }
515509 pabConf
516510 pabConf. pcOwnPubKeyHash unbalancedTx
517511
0 commit comments