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

Remove redundant ScriptHash in ReferenceScript datatypes #642

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Swordlash
Copy link
Contributor

@Swordlash Swordlash commented Sep 23, 2024

Changelog

- description: |
    Remove redundant ScriptHash in ReferenceScript datatypes
  type:
  - breaking       
  - refactoring

Context

Sometime ago I opened an issue #606 but I didn't get any response, so I've made a PR myself.
One of the members of my team asked why is the Maybe ScriptHash needed in the PReferenceScript and after some digging it seems it's completely redundant and not used anywhere (with the comment being obsolete). Therefore I removed it and everything "just compiled".

Fixes #606

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

@smelc
Copy link
Contributor

smelc commented Sep 24, 2024

@Swordlash> can you fix the formatting of Haskell files? You need to run:

# order matters: fourmolu first, then stylish-haskell
fourmolu -i <modified files>
stylish-haskell -i <modified files>

@smelc
Copy link
Contributor

smelc commented Sep 24, 2024

LGTM

@carbolymer> WDYT?

@Swordlash
Copy link
Contributor Author

Formatting should be good now. Redundant whitespace it seems.

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor Author

@Swordlash Swordlash Sep 24, 2024

Choose a reason for hiding this comment

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

This is some very unfortunate coupling, isn't it? Having a library keep redundant information (and confuse users) for the sake of one of downstream tools. Maybe we could refactor it down to cardano-cli?

Copy link
Contributor Author

@Swordlash Swordlash Sep 24, 2024

Choose a reason for hiding this comment

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

Of course we can argue that if the user wants to reference a script then he probably knows the hash. If the above is not possible I would at least not make it Maybe, for the sake of API cleanliness. I think a redundant field is better than Maybe redundant field as at least there is no ambiguity which option to use.

Copy link
Contributor Author

@Swordlash Swordlash Sep 24, 2024

Choose a reason for hiding this comment

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

@carbolymer I did the refactor, see the following: Swordlash/cardano-cli@b5c76a0

User provides the Maybe PolicyId himself anyway in the CLI, so cardano-cli code just temporarily stores this info in the PReferenceScript to be unpacked later. We can change the signature of the appropriate function to return a pair, so that we avoid storing the information in the datatype.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@carbolymer did you have a chance to take a look at the above? Tl;dr cardano-cli uses this field as a temporary container for user provided data and it can be safely refactored out.

Copy link
Contributor

@carbolymer carbolymer Sep 30, 2024

Choose a reason for hiding this comment

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

Dzięki. Looks sensible. Can you open a PR to cardano-cli with those changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure thing

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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.

It's used in cardano-cli in handling of minting scripts.

-- have direct access to the script
PReferenceScript
TxIn
(Maybe ScriptHash)
Copy link
Contributor

Choose a reason for hiding this comment

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

The purpose of this field should be documented better.

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.

Remove redundant Maybe ScriptHash from PReferenceScript
3 participants