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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

Jimbo4350
Copy link
Contributor

Changelog

- description: |
    Minting script witness refactor
# 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

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
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

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?

Comment on lines +26 to +28
data MintScriptWitWithPolId era
= MintScriptWitWithPolId
{ mswPolId :: PolicyId
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
data MintScriptWitWithPolId era
= MintScriptWitWithPolId
{ mswPolId :: PolicyId
data MintScriptWitWithPolicyId era
= MintScriptWitWithPolicyId
{ mswPolicyId :: PolicyId

I don't think we're gaining much here by shortening the names here

Comment on lines +195 to +200
sbeToSimpleScriptLangInEra ShelleyBasedEraShelley = SimpleScriptInShelley
sbeToSimpleScriptLangInEra ShelleyBasedEraAllegra = SimpleScriptInAllegra
sbeToSimpleScriptLangInEra ShelleyBasedEraMary = SimpleScriptInMary
sbeToSimpleScriptLangInEra ShelleyBasedEraAlonzo = SimpleScriptInAlonzo
sbeToSimpleScriptLangInEra ShelleyBasedEraBabbage = SimpleScriptInBabbage
sbeToSimpleScriptLangInEra ShelleyBasedEraConway = SimpleScriptInConway
Copy link
Contributor

@carbolymer carbolymer Nov 19, 2024

Choose a reason for hiding this comment

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

  • I'll upstream this to Cardano.Api.Script.

Copy link
Contributor

Choose a reason for hiding this comment

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

Comment on lines +656 to +658
case deserialiseFromTextEnvelopeAnyOf [teTypes (AnyPlutusScriptVersion PlutusScriptV1)] te of
Left err -> Left (PlutusScriptDecodeTextEnvelopeError err)
Right script -> Right script
Copy link
Contributor

Choose a reason for hiding this comment

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

this can be simplified too

Comment on lines +651 to +653
case deserialiseFromJSON AsTextEnvelope bs of
Left err -> Left $ PlutusScriptJsonDecodeError err
Right te ->
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
case deserialiseFromJSON AsTextEnvelope bs of
Left err -> Left $ PlutusScriptJsonDecodeError err
Right te ->
te <- first PlutusScriptJsonDecodeError $ deserialiseFromJSON AsTextEnvelope bs of

Comment on lines +64 to +81
data PlutusRefScriptCliArgs
= PlutusRefScriptCliArgs
TxIn
AnyPlutusScriptVersion
ScriptDataOrFile
ExecutionUnits
PolicyId
deriving Show

createOnDiskPlutusReferenceScriptCliArgs
:: TxIn
-> AnyPlutusScriptVersion
-> ScriptDataOrFile
-> ExecutionUnits
-> PolicyId
-> CliMintScriptRequirements
createOnDiskPlutusReferenceScriptCliArgs txin scriptVersion scriptData execUnits polid =
OnDiskPlutusRefScript $ PlutusRefScriptCliArgs txin scriptVersion scriptData execUnits polid
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you put those definitions below the type CliMintScriptRequirements? It makes hard to read when you have to jump up and down from definition to definiton to follow the call/type hierarchy.

Comment on lines +83 to +88
data CliMintScriptRequirements
= OnDiskSimpleOrPlutusScript OnDiskSimpleOrPlutusScriptCliArgs
| OnDiskSimpleRefScript SimpleRefScriptCliArgs
| OnDiskPlutusRefScript PlutusRefScriptCliArgs
deriving Show

Copy link
Contributor

Choose a reason for hiding this comment

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

Same like my previous comment, can you put this definition near the top of the module, before any of its "dependencies"?

(also applies to other types here, I don't want to highlight the whole file for that purpose)

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.

2 participants