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

Wallet module makeover #254

Merged
merged 12 commits into from
Feb 9, 2023
Merged

Wallet module makeover #254

merged 12 commits into from
Feb 9, 2023

Conversation

florentc
Copy link
Member

@florentc florentc commented Feb 6, 2023

This applies a cleanup pass to the Wallet module including the following changes (see individual commits), mostly listed here to keep track of them for V2 changelog:

  1. Qualifies imported modules in a saner way. This module used to be messy in that regard. This follows a convention we aim to unify throughout the cooked codebase: Cardano for Cardano.*** modules, Pl for everything Ledger-y, and Pl1/Pl2 for everything that is explicitly from Plutus.V1 or Plutus.V2 (and cannot be changed to generic Ledger.***).
  2. Overhaul comments (adds them where they were missing + a little introduction heading paragraph). This ticks a box in the TODO list of Clean up the comments #245
  3. Remove everything dealing with minAda since the real minAda amount per UTxO is not that trivial to determine. The information was therefore misleading. This also simplifies InitialDistribution. We do not issue a dedicated custom (unreliable) error anymore. We will stumble upon validation errors if we forget to provide enough lovelace per UTxO in our initial distributions.
  4. initialDistribution' loses its prime. There was no initialDistribution (no prime) anyway. Also the field accessor for InitialDistribution has a more conventional (and less misleading) name.
  5. Unused functions (both in the rest of the codebase and during actual usage of cooked during audits) have been removed: toPKHMap and valuesForWallet.
  6. There is a hack to retrieve private keys from Pl.MockPrivateKey because no constructor or field accessor is exposed to do so. Since we have decided not to rely on explicit export lists in cooked, part of that hack has been moved away from the top-level and the weird-to-export-everywhere please field accessor is gone. See issue Get rid of the hack to retrieve private keys in Cooked.Wallet.walletStakingSK #255: we need to make a PR to expose the info we need. We could also investigate using Solo from Data.Tuple in base instead of HACK if at some point we update our index state in cabal.project and require at least base 4.16

Copy link
Contributor

@0xd34df00d 0xd34df00d left a comment

Choose a reason for hiding this comment

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

Getting rid of minAda checks makes me feel a little cautious, but, rationally, looks like that's the right thing to do!

cooked-validators/src/Cooked/Wallet.hs Outdated Show resolved Hide resolved
cooked-validators/src/Cooked/Wallet.hs Outdated Show resolved Hide resolved
Comment on lines 110 to 111
-- having a dedicated function makes it easy to test that this works: check
-- the @Cooked.WalletSpec@ test module.
Copy link
Contributor

Choose a reason for hiding this comment

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

There are currently no tests for this...

ensureHasMinAda val = val <> Pl.toValue missingAda
where
missingAda = max 0 $ Pl.minAdaTxOut - Pl.fromValue val

instance Semigroup InitialDistribution where
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this instance (and the one for Monoid) used anywhere execept in initialDistribution?

Copy link
Member Author

Choose a reason for hiding this comment

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

Does not seem so. I guess it might come in handy when designing one's own distribution.

@florentc florentc merged commit 7873abf into main Feb 9, 2023
@florentc florentc deleted the fc/cleanup-wallet-module branch February 9, 2023 16:22
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.

None yet

3 participants