Skip to content

Simplify by not using QueryStakeAddressInfoCmdArgs unnecessarily #1184

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

Merged

Conversation

newhoggy
Copy link
Contributor

@newhoggy newhoggy commented May 14, 2025

Changelog

- description: |
    Simplify code by not using `QueryStakeAddressInfoCmdArgs` unnecessarily.
    Also fixes `query spo-stake-distribution` command so that the output format flags are respected.
# 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

Don't build a value of a data type if it doesn't make sense to use all the fields. Just pass the values directly to the function instead.

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

{ Cmd.commons = commons
, addr
, outputFormat
, mOutFile -- unused anyway. TODO tighten this by removing the field.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Both outputFormat and mOutFile are unused by callQueryStakeAddressInfoCmd, so don't bother using QueryStakeAddressInfoCmdArgs and packing unnecessary fields.

spoToDelegatee <-
Map.fromList . concat
<$> traverse
( \stakeAddr -> do
info <- callQueryStakeAddressInfoCmd $ mkQueryStakeAddressInfoCmdArgs stakeAddr
info <- callQueryStakeAddressInfoCmd commons stakeAddr
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Instead call callQueryStakeAddressInfoCmd with the values it needs directly.

@@ -1801,7 +1799,6 @@ runQuerySPOStakeDistribution
, Cmd.target
}
, Cmd.spoHashSources = spoHashSources'
, Cmd.outputFormat
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The unnecessary use of QueryStakeAddressInfoCmdArgs hides problems. For example here outputFormat is actually unused, when it really should be. The use of QueryStakeAddressInfoCmdArgs hides this fact.

[ ( spo
, coin
, Map.lookup spo spoToDelegatee
)
| (spo, coin) <- Map.assocs spoStakeDistribution
]

writeOutput mOutFile toWrite
output =
outputFormat
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We now respect the output format of the query spo-stake-distribution command.

writeOutput mOutFile toWrite
output =
outputFormat
& ( id
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 id to get alignment from the formatter? I don't think it has any effect on the code

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it is purely for alignment purposes.

@newhoggy newhoggy requested a review from palas May 15, 2025 09:34
@newhoggy newhoggy added this pull request to the merge queue May 16, 2025
Merged via the queue into master with commit 9b851c5 May 16, 2025
26 checks passed
@newhoggy newhoggy deleted the newhoggy/simplify-by-not-using-QueryStakeAddressInfoCmdArgs branch May 16, 2025 12:51
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