@@ -274,6 +274,9 @@ writeBalancedTx contractEnv (Right tx) = do
274274 , " Signatories (pkh): " <> Text. unwords (map pkhToText requiredSigners)
275275 ]
276276
277+ when (pabConf. pcCollectStats && signable) $
278+ collectBudgetStats (Tx. txId tx) pabConf
279+
277280 when (not pabConf. pcDryRun && signable) $ do
278281 newEitherT $ CardanoCLI. submitTx @ w pabConf tx
279282
@@ -284,9 +287,6 @@ writeBalancedTx contractEnv (Right tx) = do
284287 mvFiles (Files. txFilePath pabConf " raw" (Tx. txId tx)) (Files. txFilePath pabConf " raw" cardanoTxId)
285288 when signable $ mvFiles signedSrcPath signedDstPath
286289
287- when contractEnv. cePABConfig. pcCollectStats $
288- collectBudgetStats cardanoTxId signedDstPath
289-
290290 pure cardanoTx
291291 where
292292 mvFiles :: Text -> Text -> EitherT Text (Eff effs ) ()
@@ -299,10 +299,17 @@ writeBalancedTx contractEnv (Right tx) = do
299299 , cmdOutParser = const ()
300300 }
301301
302- collectBudgetStats txId txPath = do
303- let path = Text. unpack txPath
304- b <- firstEitherT (Text. pack . show ) $ newEitherT $ estimateBudget @ w (Signed path)
305- void $ newEitherT (Right <$> saveBudget @ w txId b)
302+ collectBudgetStats txId pabConf = do
303+ let path = Text. unpack (Files. txFilePath pabConf " signed" (Tx. txId tx))
304+ txBudget <-
305+ firstEitherT toBudgetSaveError $
306+ newEitherT $ estimateBudget @ w (Signed path)
307+ void $ newEitherT (Right <$> saveBudget @ w txId txBudget)
308+
309+ toBudgetSaveError =
310+ Text. pack
311+ . (" Failed to save Tx budgets statistics: " ++ )
312+ . show
306313
307314pkhToText :: Ledger. PubKey -> Text
308315pkhToText = encodeByteString . fromBuiltin . Ledger. getPubKeyHash . Ledger. pubKeyHash
0 commit comments