1

I'm trying to understand how Constraints.mustHashDatum works but I'm not able to figure out the purpose of this Constraint.

Any help would be great.

1 Answer 1

1

This is my beginner takeaway about Constraints.mustHashDatum after reading about TxContraints and TxConstraint and mustHashDatum at the Ledger.Constraints documentation link below. I will also be interested in the responses so that I can know the answer too.

Here are my thoughts. It seems like when we're creating a transaction, we can dictate that one of the constraints/requirements is just that there exist a Datum and a DatumHash, and that both must be supplied as part of transaction creation. If one or both is not supplied, then the transaction won't be generated because the particular mustHashDatum constraint wouldn't be met. I think maybe the mustHashDatum constraint does this for us, since just creating that constraint requires that we provide both. Presumably, we might set this as a constraint to make sure that later code involving the transaction can use/check the Datum and the DatumHash.

Below are the excerpts from the documentation that seemed applicable.

https://playground.plutus.iohkdev.io/doc/haddock/plutus-ledger-constraints/html/Ledger-Constraints.html

Ledger.Constraints

This module defines TxConstraints, a list of constraints on transactions. To construct a value of TxConstraints use the mustPayToTheScript, mustSpendAtLeast, etc functions. Once we have a TxConstraints value it can be used both to generate a transaction that satisfies the constraints (off-chain, using mkTx) and to check whether a given pending transaction meets the constraints (on-chain, using checkScriptContext).

~~~~~

Constructors

TxConstraints

txConstraints :: [TxConstraint]

~~~~~

data TxConstraint

Constraints on transactions that want to spend script outputs

Constructors

MustSpendAtLeast Value

MustHashDatum DatumHash Datum

~~~~~

Defining constraints

{-# INLINABLE mustHashDatum #-}

mustHashDatum :: DatumHash -> Datum -> TxConstraints i o

mustHashDatum dvh = singleton . MustHashDatum dvh

1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Jan 22, 2022 at 11:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.