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

Rename Balance::claimable_amount_satoshis to have a unique name #2460

Merged

Conversation

TheBlueMatt
Copy link
Collaborator

In Java/TypeScript, we map enums as a base class and each variant as a class which extends the base. In Java/TypeScript, functions and fields share the same namespace, which means we cannot have functions on an enum which have the same name as any fields in any enum variants.

Balance's claimable_amount_satoshis method aliases with fields in each variant, and thus ultimately doesn't compile in TypeScript.

Because Balance::claimable_amount_satoshis has the same name as the fields, it's also a bit confusing, as it doesn't return the field for each variant, but sometimes returns zero if we're not sure we can claim the balance.

Instead, we rename the method
definitely_claimable_amount_satoshis.

@codecov-commenter
Copy link

codecov-commenter commented Jul 28, 2023

Codecov Report

Patch coverage has no change and project coverage change: +0.13% 🎉

Comparison is base (685f266) 90.33% compared to head (b9a04c1) 90.47%.
Report is 2 commits behind head on main.

❗ Current head b9a04c1 differs from pull request most recent head 8302203. Consider uploading reports for the commit 8302203 to get more accurate results

❗ Your organization is not using the GitHub App Integration. As a result you may experience degraded service beginning May 15th. Please install the Github App Integration for your organization. Read more.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2460      +/-   ##
==========================================
+ Coverage   90.33%   90.47%   +0.13%     
==========================================
  Files         106      106              
  Lines       55732    56612     +880     
  Branches    55732    56612     +880     
==========================================
+ Hits        50347    51218     +871     
- Misses       5385     5394       +9     
Files Changed Coverage Δ
lightning/src/chain/channelmonitor.rs 94.82% <0.00%> (ø)

... and 2 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@tnull tnull left a comment

Choose a reason for hiding this comment

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

Makes sense, but if I'd be reading definitely_claimable_amount_satoshis I may be somewhat confused what it does, I guess due to the colloquial language?

Maybe we could make it more expressive, e.g., something like infallibly_claimable_amount_satoshis or ensured_claimable_amount_satoshis?

@TheBlueMatt
Copy link
Collaborator Author

Yea, I'm not super happy with definitely, either, tbh. That said, I'm not sure I like infallibly or ensured a hell of a lot more - all three imply a surety level that isn't really guaranteed - balances which are "ours" still actually have to be claimed, which could fail if we lose a broadcast race. Now, I'm not sure users need to concern themselves with that, its ultimately our responsibility, but infallible seems like a very strong word, ensured too. The other option is to rename the fields in the enum variants to something other than claimable_amount, maybe we could just drop the claimable there, leave them all as amount_satoshis, and then have claimable_amount_satoshis be as-is?

@valentinewallace
Copy link
Contributor

I vote removing the claimable_ prefixes from the Balance variant fields

In Java/TypeScript, we map enums as a base class and each variant
as a class which extends the base. In Java/TypeScript, functions
and fields share the same namespace, which means we cannot have
functions on an enum which have the same name as any fields in any
enum variants.

`Balance`'s `claimable_amount_satoshis` method aliases with fields
in each variant, and thus ultimately doesn't compile in TypeScript.

Because `Balance::claimable_amount_satoshis` has the same name as
the fields, it's also a bit confusing, as it doesn't return the
field for each variant, but sometimes returns zero if we're not
sure we can claim the balance.

Instead, we rename the fields in each enum variant to simply
`amount_satoshis`, to avoid implying that we can definitely claim
the balance.
@TheBlueMatt
Copy link
Collaborator Author

Done.

@TheBlueMatt TheBlueMatt merged commit 0607ed7 into lightningdevkit:main Jul 31, 2023
14 checks passed
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

5 participants