Skip to content

Commit eaf7637

Browse files
Merge branch 'master' into trace-logs
2 parents bbf637f + 17072f2 commit eaf7637

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

src/BotPlutusInterface/Contract.hs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,9 @@ writeBalancedTx contractEnv (Right tx) = do
298298
, "Signatories (pkh):" <+> pretty (Text.unwords (map pkhToText requiredSigners))
299299
]
300300

301+
when (pabConf.pcCollectStats && signable) $
302+
collectBudgetStats (Tx.txId tx) pabConf
303+
301304
when (not pabConf.pcDryRun && signable) $ do
302305
newEitherT $ CardanoCLI.submitTx @w pabConf tx
303306

@@ -308,9 +311,6 @@ writeBalancedTx contractEnv (Right tx) = do
308311
mvFiles (Files.txFilePath pabConf "raw" (Tx.txId tx)) (Files.txFilePath pabConf "raw" cardanoTxId)
309312
when signable $ mvFiles signedSrcPath signedDstPath
310313

311-
when contractEnv.cePABConfig.pcCollectStats $
312-
collectBudgetStats cardanoTxId signedDstPath
313-
314314
pure cardanoTx
315315
where
316316
mvFiles :: Text -> Text -> EitherT Text (Eff effs) ()
@@ -323,10 +323,17 @@ writeBalancedTx contractEnv (Right tx) = do
323323
, cmdOutParser = const ()
324324
}
325325

326-
collectBudgetStats txId txPath = do
327-
let path = Text.unpack txPath
328-
b <- firstEitherT (Text.pack . show) $ newEitherT $ estimateBudget @w (Signed path)
329-
void $ newEitherT (Right <$> saveBudget @w txId b)
326+
collectBudgetStats txId pabConf = do
327+
let path = Text.unpack (Files.txFilePath pabConf "signed" (Tx.txId tx))
328+
txBudget <-
329+
firstEitherT toBudgetSaveError $
330+
newEitherT $ estimateBudget @w (Signed path)
331+
void $ newEitherT (Right <$> saveBudget @w txId txBudget)
332+
333+
toBudgetSaveError =
334+
Text.pack
335+
. ("Failed to save Tx budgets statistics: " ++)
336+
. show
330337

331338
pkhToText :: Ledger.PubKey -> Text
332339
pkhToText = encodeByteString . fromBuiltin . Ledger.getPubKeyHash . Ledger.pubKeyHash

0 commit comments

Comments
 (0)