From aa8169ea9d9cea247558581d16e13b815bc6b520 Mon Sep 17 00:00:00 2001 From: Dzmitry Shuysky Date: Tue, 16 Jul 2024 12:42:02 +0300 Subject: [PATCH] Do not query datums by hash in processConstraints --- src/Contract/UnbalancedTx.purs | 1 - src/Internal/ProcessConstraints.purs | 14 ++------------ src/Internal/ProcessConstraints/Error.purs | 5 ----- 3 files changed, 2 insertions(+), 18 deletions(-) diff --git a/src/Contract/UnbalancedTx.purs b/src/Contract/UnbalancedTx.purs index 4d13f7fb4..23b2f08f7 100644 --- a/src/Contract/UnbalancedTx.purs +++ b/src/Contract/UnbalancedTx.purs @@ -18,7 +18,6 @@ import Ctl.Internal.ProcessConstraints.Error import Ctl.Internal.ProcessConstraints.Error ( MkUnbalancedTxError ( CannotFindDatum - , CannotQueryDatum , CannotConvertPOSIXTimeRange , CannotSolveTimeConstraints , CannotGetMintingPolicyScriptIndex diff --git a/src/Internal/ProcessConstraints.purs b/src/Internal/ProcessConstraints.purs index 01b5cae7c..b07d4d0b7 100644 --- a/src/Internal/ProcessConstraints.purs +++ b/src/Internal/ProcessConstraints.purs @@ -81,7 +81,6 @@ import Ctl.Internal.ProcessConstraints.Error , CannotMintZero , ExpectedPlutusScriptGotNativeScript , CannotFindDatum - , CannotQueryDatum , CannotGetValidatorHashFromAddress , TxOutRefWrongType , CannotConvertPOSIXTimeRange @@ -173,7 +172,7 @@ import Ctl.Internal.Types.Val as Val import Data.Array (cons, partition, toUnfoldable, zip) import Data.Array (mapMaybe, singleton, (:)) as Array import Data.Bifunctor (lmap) -import Data.Either (Either(Left, Right), either, hush, isRight, note) +import Data.Either (Either(Left, Right), either, note) import Data.Foldable (foldM) import Data.Lens ((%=), (%~), (.=), (.~), (<>=)) import Data.Lens.Getter (to, use) @@ -192,7 +191,6 @@ import Effect.Aff.Class (liftAff) import Effect.Class (liftEffect) import Effect.Exception (throw) import Partial.Unsafe (unsafePartial) -import Prelude (join) as Bind -- The constraints don't precisely match those of Plutus: -- `forall v. (FromData (DatumType v), ToData (DatumType v), ToData (RedeemerType v))` @@ -548,15 +546,7 @@ processConstraint -- Use the datum hash inside the lookup case datum' of Just (OutputDatumHash dHash) -> do - dat <- ExceptT do - mDatumLookup <- lookupDatum dHash - if isRight mDatumLookup then - pure mDatumLookup - else - liftAff $ queryHandle.getDatumByHash dHash <#> hush - >>> Bind.join - >>> note - (CannotQueryDatum dHash) + dat <- ExceptT $ lookupDatum dHash lift $ addDatum dat Just (OutputDatum _) -> pure unit Nothing -> throwError CannotFindDatum diff --git a/src/Internal/ProcessConstraints/Error.purs b/src/Internal/ProcessConstraints/Error.purs index 519025660..1b2281e3c 100644 --- a/src/Internal/ProcessConstraints/Error.purs +++ b/src/Internal/ProcessConstraints/Error.purs @@ -37,7 +37,6 @@ import Data.UInt as UInt data MkUnbalancedTxError = CannotFindDatum - | CannotQueryDatum DataHash | CannotConvertPOSIXTimeRange POSIXTimeRange PosixTimeToSlotError | CannotSolveTimeConstraints POSIXTimeRange POSIXTimeRange | CannotGetMintingPolicyScriptIndex -- Should be impossible @@ -70,10 +69,6 @@ instance Show MkUnbalancedTxError where explainMkUnbalancedTxError :: MkUnbalancedTxError -> String explainMkUnbalancedTxError = case _ of CannotFindDatum -> "Cannot find datum" - CannotQueryDatum dh -> - "Querying for datum by datum hash (" - <> byteArrayToHex (unwrap $ encodeCbor dh) - <> ") failed: no datum found" CannotConvertPOSIXTimeRange tr ttsErr -> "Cannot convert POSIX time range to slot time range.\nRange: " <> show tr