Skip to content

Commit 2f4b4c5

Browse files
committed
more detailed logging during collateral setup
1 parent c31302f commit 2f4b4c5

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

src/BotPlutusInterface/Contract.hs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import BotPlutusInterface.Types (
4343
TxFile (Signed),
4444
collateralValue,
4545
pcCollateralSize,
46+
pcOwnPubKeyHash,
4647
)
4748
import Cardano.Api (
4849
AsType (..),
@@ -524,37 +525,53 @@ handleCollateral ::
524525
ContractEnvironment w ->
525526
Eff effs (Either WAPI.WalletAPIError ())
526527
handleCollateral cEnv = do
528+
let ownPkh = pcOwnPubKeyHash $ cePABConfig cEnv
527529
result <- (fmap swapEither . runEitherT) $
528530
do
529531
let helperLog :: PP.Doc () -> ExceptT CollateralUtxo (Eff effs) ()
530532
helperLog msg = newEitherT $ Right <$> printBpiLog @w (Debug [CollateralLog]) msg
531533

532534
collateralNotInMem <-
533535
newEitherT $
534-
maybeToLeft "Collateral UTxO not found in contract env."
536+
maybeToLeft ("PKH: " <> pretty ownPkh <> ". Collateral UTxO not found in contract env.")
535537
<$> getInMemCollateral @w
536538

537539
helperLog collateralNotInMem
538540

539541
collateralNotInWallet <- newEitherT $ swapEither <$> findCollateralAtOwnPKH cEnv
540542

541543
helperLog
542-
("Collateral UTxO not found or failed to be found in wallet: " <> pretty collateralNotInWallet)
544+
( "PKH: " <> pretty ownPkh <> ". Collateral UTxO not found or failed to be found in wallet: "
545+
<> pretty collateralNotInWallet
546+
)
543547

544-
helperLog "Creating collateral UTxO."
548+
helperLog ("PKH: " <> pretty ownPkh <> ". Creating collateral UTxO.")
545549

546550
notCreatedCollateral <- newEitherT $ swapEither <$> makeCollateral @w cEnv
547551

548552
helperLog
549-
("Failed to create collateral UTxO: " <> pretty notCreatedCollateral)
553+
( "PKH: " <> pretty ownPkh <> ". Failed to create collateral UTxO: "
554+
<> pretty notCreatedCollateral
555+
)
550556

551-
pure ("Failed to create collateral UTxO: " <> show notCreatedCollateral)
557+
pure
558+
( "PKH: " <> show ownPkh <> ". Failed to create collateral UTxO: "
559+
<> show notCreatedCollateral
560+
)
552561

553562
case result of
554563
Right collteralUtxo ->
555564
setInMemCollateral @w collteralUtxo
556-
>> Right <$> printBpiLog @w (Debug [CollateralLog]) "successfully set the collateral utxo in env."
557-
Left err -> pure $ Left $ WAPI.OtherError $ T.pack $ "Failed to make collateral: " <> show err
565+
>> Right
566+
<$> printBpiLog @w
567+
(Debug [CollateralLog])
568+
("PKH: " <> pretty ownPkh <> ". Successfully set the collateral utxo in env.")
569+
Left err ->
570+
pure $
571+
Left $
572+
WAPI.OtherError $
573+
T.pack $
574+
"PKH: " <> show ownPkh <> ". Failed to make collateral: " <> show err
558575

559576
{- | Create collateral UTxO by submitting Tx.
560577
Then try to find created UTxO at own PKH address.

0 commit comments

Comments
 (0)