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

Add module for UTxO type and operations #710

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

locallycompact
Copy link
Contributor

@locallycompact locallycompact commented Dec 13, 2024

Changelog

- description: |
    Add `Cardano.Api.Tx.UTxO` module for common UTxO operations.
# 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, @Jimbo4350 thoughts?

cardano-api/internal/Cardano/Api/Query/UTxO.hs Outdated Show resolved Hide resolved
cardano-api/internal/Cardano/Api/Query/UTxO.hs Outdated Show resolved Hide resolved
cardano-api/internal/Cardano/Api/Query/UTxO.hs Outdated Show resolved Hide resolved
@carbolymer carbolymer linked an issue Dec 30, 2024 that may be closed by this pull request
@locallycompact locallycompact force-pushed the lc/utxo-module branch 9 times, most recently from 0ce0fcf to a2dbc0a Compare January 6, 2025 21:26
@locallycompact locallycompact force-pushed the lc/utxo-module branch 2 times, most recently from a07f563 to 1e931e1 Compare January 6, 2025 21:27
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. @Jimbo4350 thoughts?

cardano-api/internal/Cardano/Api/Query/UTxO.hs Outdated Show resolved Hide resolved
@@ -248,6 +250,7 @@ library
Cardano.Api.Ledger
Cardano.Api.Network
Cardano.Api.Shelley
Cardano.Api.UTxO
Copy link
Contributor

Choose a reason for hiding this comment

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

Keep this module hidden and expose the functionality from Cardano.Api. We need to do an audit on how we expose things.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No. This module by design is intended to be imported qualified, similar to container modules such as Data.Map, as it contains function names which commonly conflict.

Copy link
Contributor

@Jimbo4350 Jimbo4350 Jan 31, 2025

Choose a reason for hiding this comment

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

Yes. This PR will remain unmerged until this change is made. The decision as to how we expose our modules is not yours to make.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

OK. Didn't mean to sound presumptuous, I assumed we were misunderstanding each other. If I do understand you correctly, do you mean to expose functions such as empty and lookup directly through Cardano.Api? What I was trying to do here is provide a qualified import that deals with only this container type, because that is clear to the reader, eg import Cardano.Api.UTxO as UTxO, and called as UTxO.empty, UTxO.lookup. Doing import qualified Cardano.Api as UTxO is confusing, as it would contain functions that don't concern UTxOs, and import qualified Cardano.Api as Api would also be confusing, as Api.empty requires context for the reader when reading at the call site. Can you confirm if this is what you meant?

Copy link
Contributor

@carbolymer carbolymer Feb 7, 2025

Choose a reason for hiding this comment

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

I agree here with @locallycompact . Exposing commonly used function names like empty or singleton through Cardano.Api will be annoying. End users will be forced to qualify Cardano.Api imports. Moreover, if we decide to provide another similar container utility the same way in cardano-api, then the names will be in use already, and we'll be forced to use different names e.g. emptyTxSet, lookupTxSet ... which will be inconsistent.

Copy link
Contributor

@Jimbo4350 Jimbo4350 Feb 7, 2025

Choose a reason for hiding this comment

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

@locallycompact Fair point.

@carbolymer I'd like to task you with writing an ADR as to how we should expose cardano-api's functionality. It has been sub optimal for a long time and it would help contributors if we were clearer in this regard.

Copy link
Contributor

Choose a reason for hiding this comment

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

Or we could pick a middle ground here: export just the UTxO type and its instances through Cardano.Api, the utility functions should stay in the UTxO module exported from cardano-api.

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 I think that's the current behaviour

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 I think that's the current behaviour

cardano-api/src/Cardano/Api/UTxO.hs Outdated Show resolved Hide resolved
Copy link
Contributor

@Jimbo4350 Jimbo4350 left a comment

Choose a reason for hiding this comment

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

Two changes need to be made

@locallycompact locallycompact force-pushed the lc/utxo-module branch 4 times, most recently from f618f5e to 62330c6 Compare February 6, 2025 14:26
@carbolymer
Copy link
Contributor

carbolymer commented Feb 10, 2025

Can you place the new UTxO module in Cardano.Api.Tx.UTxO? The cabal library you chose is fine. We're shifting modules a bit in #748 so it'll better suit there I think.

@locallycompact
Copy link
Contributor Author

I will rebase after that work.

@locallycompact locallycompact force-pushed the lc/utxo-module branch 2 times, most recently from e36dbb9 to 764d987 Compare February 10, 2025 16:30
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.

[FR] - Data.Map style module for UTxO
3 participants