Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minting script witness refactor #971

Merged
merged 17 commits into from
Nov 26, 2024
Merged

Conversation

Jimbo4350
Copy link
Contributor

@Jimbo4350 Jimbo4350 commented Nov 18, 2024

Changelog

- description: |
    Minting script witness refactor
    TODO: Add more details
# uncomment types applicable to the change:
  type:
  # - feature        # introduces a new feature
  - breaking       # the API has changed in a breaking way
  # - compatible     # the API has changed but is non-breaking
  # - optimisation   # measurable performance improvements
  - refactoring    # QoL changes
  # - bugfix         # fixes a defect
  # - test           # fixes/modifies tests
  # - maintenance    # not directly related to the code
  # - release        # related to a new release preparation
  # - documentation  # change in code docs, haddocks...

Context

Additional context for the PR goes here. If the PR fixes a particular issue please provide a link to the issue.

How to trust this PR

Highlight important bits of the PR that will make the review faster. If there are commands the reviewer can run to observe the new behavior, describe them.

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • New tests are added if needed and existing tests are updated. See Running tests for more details
  • Self-reviewed the diff

Copy link
Contributor

@carbolymer carbolymer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after first pass 👍🏻 Nice work.

Comment on lines 9 to 11
, createOnDiskSimpleOfPlutusScriptCliArgs
, createOnDiskSimpleReferenceScriptCliArgs
, createOnDiskPlutusReferenceScriptCliArgs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should switch to either using OnDiskXXXXThing or FileXXXXThing names convention for the consistency, eventually. It would make navigating codebase easier.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about:

   createSimpleOrPlutusScriptFromCliArgs
   createSimpleReferenceScriptFromCliArgs
   createPlutusReferenceScriptFromCliArgs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine I think. I had in mind the type names as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this module is in the right place. Can we split it into two:

  • cardano-cli/src/Cardano/CLI/Types/Plutus.hs with MintScriptWitWithPolId, CliMintScriptRequirements and createOnDiskXXX functions
  • cardano-cli/src/Cardano/CLI/Read/Plutus.hs with readMintScriptWitness and CliScriptWitnessError

?

I'm not a fan of the current module structure, but it never felt like a good moment to turn everything upside down.

For the moment I think we should follow it rather than introducing different changes.

I propose the following change:
https://gist.github.com/carbolymer/63b23d0df940c61d1501a6763d86134c

I'm not insisting on keeping EraBased if we have a better alternative here.

Thoughts?

Copy link
Contributor Author

@Jimbo4350 Jimbo4350 Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

100% agree with the new structure and the module split.

So then based on what you suggested we would have:

Cardano/CLI
├── Byron
├── Commands
├── EraBased
│   └── Plutus
│       └── Read.hs
│       └── Types.hs
│     
│           

Copy link
Contributor

@carbolymer carbolymer Nov 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

├── Commands could be organised by domains too I think.

cardano-cli/src/Cardano/CLI/Plutus/Minting.hs Outdated Show resolved Hide resolved
cardano-cli/src/Cardano/CLI/Plutus/Minting.hs Outdated Show resolved Hide resolved
cardano-cli/src/Cardano/CLI/Read.hs Outdated Show resolved Hide resolved
cardano-cli/src/Cardano/CLI/Read.hs Outdated Show resolved Hide resolved
cardano-cli/src/Cardano/CLI/Plutus/Minting.hs Outdated Show resolved Hide resolved
cardano-cli/src/Cardano/CLI/Plutus/Minting.hs Outdated Show resolved Hide resolved
@Jimbo4350 Jimbo4350 force-pushed the jordan/minting-script-witness-refactor branch from 708410b to 672b332 Compare November 20, 2024 19:29
smelc and others added 11 commits November 20, 2024 21:37
Define the data definition CliMintScriptRequirements
This type makes it clearer that we require the policy id for transaction
construction when using a minting script
AnyScriptLanguage
Replace ScriptWitnessFiles WitCtxMint with CliMintScriptRequirements
AnyPlutusScriptVersion instead of AnyScriptLanguage
Refactor readScriptWitness and eliminate invalid states

Factor out fromSomeTypeSimpleScript and fromSomeTypePlutusScripts

fromSomeTypePlutusScripts should automatically be updated as soon as the
Enum AnyPlutusScriptVersion instance is updated in cardano-api
Add ScriptDecodeUnknownPlutusScriptVersion to ScriptDecodeError
@Jimbo4350 Jimbo4350 force-pushed the jordan/minting-script-witness-refactor branch from 672b332 to 1d7728e Compare November 21, 2024 15:31
@Jimbo4350 Jimbo4350 requested review from a team as code owners November 21, 2024 15:31
@Jimbo4350 Jimbo4350 force-pushed the jordan/minting-script-witness-refactor branch from 1d7728e to d09f60b Compare November 21, 2024 15:52
@Jimbo4350 Jimbo4350 force-pushed the jordan/minting-script-witness-refactor branch from d09f60b to 4ff64a8 Compare November 21, 2024 15:53
@Jimbo4350 Jimbo4350 force-pushed the jordan/minting-script-witness-refactor branch from 4ff64a8 to 424ad7b Compare November 21, 2024 16:11
- Cardano.CLI.Types.Errors.PlutusScriptDecodeError
- Cardano.CLI.Types.Errors.ScriptDataError
@Jimbo4350 Jimbo4350 force-pushed the jordan/minting-script-witness-refactor branch 4 times, most recently from 7e08bf1 to c157954 Compare November 21, 2024 16:54
Jimbo4350 and others added 3 commits November 21, 2024 15:07
handle all minting scripts (simple and plutus) we no longer have to
accomodate for the PolicyId in the constructors
PlutusReferenceScriptWitnessFiles and SimpleReferenceScriptWitnessFiles

This is evidenced by the diff of this commit

The goal is to deprecate ScriptWitnessFiles and replace it with a
collection of types for the different script purposes. The first example
of this is MintScriptWitnessWithPolicyId era
from PReferenceScript and SReferenceScript constructors

Co-authored-by: Mateusz Gałażyn <[email protected]>
@Jimbo4350 Jimbo4350 force-pushed the jordan/minting-script-witness-refactor branch from c157954 to 5649c78 Compare November 21, 2024 19:10
Comment on lines +31 to +34
"Version mismatch in code: script version that was read"
<> pretty version
<> " but tried to decode script version: "
<> pshow v
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"Version mismatch in code: script version that was read"
<> pretty version
<> " but tried to decode script version: "
<> pshow v
"Version mismatch in code: script version that was read"
<+> pretty version
<+> "but tried to decode script version:"
<+> pshow v

-- which says nothing about the script type (simple vs plutus) or script version.
-- As a result need to separate the different script purposes into
-- their own separate data definitions where we can make changes specific to that script purpose
-- more easily without affecting the rest of the api.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Beautiful 🤩

@@ -1230,9 +1248,9 @@ getAllReferenceInputs
:: ScriptWitness witctx era -> Maybe TxIn
getReferenceInput sWit =
case sWit of
PlutusScriptWitness _ _ (PReferenceScript refIn _) _ _ _ -> Just refIn
PlutusScriptWitness _ _ (PReferenceScript refIn) _ _ _ -> Just refIn
Copy link
Contributor

@carbolymer carbolymer Nov 22, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function can be removed, as this functionality is provided by getScriptWitnessReferenceInput from cardano-api.

@Jimbo4350 Jimbo4350 added this pull request to the merge queue Nov 26, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 26, 2024
@smelc smelc added this pull request to the merge queue Nov 26, 2024
Merged via the queue into master with commit 308ce97 Nov 26, 2024
25 checks passed
@smelc smelc deleted the jordan/minting-script-witness-refactor branch November 26, 2024 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants