-
Notifications
You must be signed in to change notification settings - Fork 214
Refactored the tx constraints library to prepare for PlutusV2 #625
Conversation
Damn, I should have published my refactoring branch. Changes to |
@andreabedini No problem. I can adapt my code considering your changes to |
I'll book some time to discuss both our chages ASAP. I'm still doing minor fixes all through the code base 🤯 |
52043f4
to
5f6b8a8
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good but I have a comment about the naming.
I dislike the usage of plutusV
prefix as a namespace approach because there are modules for this task.
Actually, we already have started mixing them:
import Ledger.Constraints.OnChain.V1 as Constraints
...
Constraints.checkPlutusV1OwnOutputConstraint
I think it's tedious, as a user I would need to remember when a function starts with plutusV1
or there is plutusV1
somewhere in the name. Also, we might be inconsistent in the future or just not careful as with otherPlutusV1Script
and that might lead to many functions with different names.
I think that modules here is a better approach to deal with namespacing and scopes.
- We still can use one version in one module:
import Ledger.Constraints.OnChain.V1 as Constraints
...
Constraints.checkOwnOutputConstraint
and it will be easier to switch to a different version by changing the import.
- We can mix the versions in one module without polluting the scope:
import Ledger.Constraints.OnChain.V1 as Constraints.V1
import Ledger.Constraints.OnChain.V2 as Constraints.V2
...
Constraints.V1.checkOwnOutputConstraint
The names of functions will be the same, we don't need to change them, only the name of the module.
Constraints.otherScript usScript <> | ||
Constraints.mintingPolicy (liquidityPolicy us) <> | ||
lookups = Constraints.plutusV1TypedValidatorLookups usInst <> | ||
Constraints.otherPlutusV1Script usScript <> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe should be plutusV1OtherScript
? To be consistent in naming.
@ak3n Very good point. One of the reason I decided to go with |
@koslambrou Yeah, should we split like in #628? |
b28ed75
to
0d0327d
Compare
@ak3n For now, I went back to the old naming for |
0d0327d
to
7cb2c16
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At some point I guess it will be useful to have a TypedValidator
that can contain a script in any plutus version, and then maybe this can use that? We'll learn by experience when it's useful to split code into one for each plutus version and when a sum type will do.
@sjoerdvisscher Yep, I agree |
* Changed functions names in plutus-ledger-constraints to reflect the Plutus version * `typedValidatorLookups` -> `plutusV1TypedValidatorLookups` * `mintingPolicy` -> `plutusV1MintingPolicy` * `otherScript` -> `plutusV1OtherScript` * Removed reexport of `Ledger.Constraints.OnChain.V1.checkScriptContext` from module `Ledger.Constraints` * Moved functions in `Plutus.Contract.Typed.Tx` and `Plutus.Contract.Tx` to plutus-ledger-constraints. * Changed 'Ledger.Tx.ChainIndexTxOut' from Either to Tuple for the datum and validator. This prevents from having to recompute the hash from the value when we have `Right ...` since the hashing function of PlutusV1 is not the same as the one in PlutusV2 (for scripts, not for datums, but for consistency we apply the same refactoring for datums). * Backported some refactoring changes from `next-node` such as the function 'Plutus.ChainIndex.Handlers.makeChainIndexTxOut' and the refactoring surrounding `Ledger.Tx.ChainIndexTxOut`.
7cb2c16
to
691ceba
Compare
Changed functions names in plutus-ledger-constraints to reflect the Plutus version
typedValidatorLookups
->plutusV1TypedValidatorLookups
mintingPolicy
->plutusV1MintingPolicy
otherScript
->plutusV1OtherScript
Removed reexport of
Ledger.Constraints.OnChain.V1.checkScriptContext
from moduleLedger.Constraints
.Moved functions in
Plutus.Contract.Typed.Tx
andPlutus.Contract.Tx
to plutus-ledger-constraints.
Changed 'Ledger.Tx.ChainIndexTxOut' from Either to Tuple for the datum
and validator. This prevents from having to recompute the hash from
the value when we have
Right ...
since the hashing function ofPlutusV1 is not the same as the one in PlutusV2 (for scripts, not for
datums, but for consistency we apply the same refactoring for datums).
Backported some refactoring changes from
next-node
such as thefunction 'Plutus.ChainIndex.Handlers.makeChainIndexTxOut' and the
refactoring surrounding
Ledger.Tx.ChainIndexTxOut
.Pre-submit checklist: