Skip to content

Commit

Permalink
Do not query datums by hash in processConstraints
Browse files Browse the repository at this point in the history
  • Loading branch information
errfrom committed Jul 16, 2024
1 parent 44fd4a0 commit aa8169e
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 18 deletions.
1 change: 0 additions & 1 deletion src/Contract/UnbalancedTx.purs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import Ctl.Internal.ProcessConstraints.Error
import Ctl.Internal.ProcessConstraints.Error
( MkUnbalancedTxError
( CannotFindDatum
, CannotQueryDatum
, CannotConvertPOSIXTimeRange
, CannotSolveTimeConstraints
, CannotGetMintingPolicyScriptIndex
Expand Down
14 changes: 2 additions & 12 deletions src/Internal/ProcessConstraints.purs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ import Ctl.Internal.ProcessConstraints.Error
, CannotMintZero
, ExpectedPlutusScriptGotNativeScript
, CannotFindDatum
, CannotQueryDatum
, CannotGetValidatorHashFromAddress
, TxOutRefWrongType
, CannotConvertPOSIXTimeRange
Expand Down Expand Up @@ -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)
Expand All @@ -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))`
Expand Down Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions src/Internal/ProcessConstraints/Error.purs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ import Data.UInt as UInt

data MkUnbalancedTxError
= CannotFindDatum
| CannotQueryDatum DataHash
| CannotConvertPOSIXTimeRange POSIXTimeRange PosixTimeToSlotError
| CannotSolveTimeConstraints POSIXTimeRange POSIXTimeRange
| CannotGetMintingPolicyScriptIndex -- Should be impossible
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit aa8169e

Please sign in to comment.