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 Comparable to Address remove from PrefixedChecksummedBytes #2018

Conversation

msgilligan
Copy link
Member

This is a draft implementation of my proposed solution discussed in PR #1854.

int result = this.params.getId().compareTo(o.params.getId());
if (result != 0) return result;

// Then compare Legacy vs Segwit
Copy link
Member

Choose a reason for hiding this comment

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

Couldn't the Legacy/Segwit comparison go to Address.compareTo()?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, we could put that there and then call an abstract method with a different signature that the two subclasses would implement. I'm going to take a break from work for the next week, so I'll look at doing this when I return.

Copy link
Member Author

Choose a reason for hiding this comment

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

How about this: 62ab82f ?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that's the general idea. But is there a reason for the additonal method? Couldn't it all be contained in three compareTo() impls? The leaves would call super.compareTo() for the comparison on Address level.

Copy link
Member Author

@msgilligan msgilligan Aug 20, 2020

Choose a reason for hiding this comment

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

Yes, that's the general idea. But is there a reason for the additonal method? Couldn't it all be contained in three compareTo() impls? The leaves would call super.compareTo() for the comparison on Address level.

I thought about doing it that way (1), but decided against it because (a) it seemed wrong to have an implementation of compareTo for Address that (as a standalone method, that would be inherited by subclasses) was incorrect. It also leaves no unimplemented abstract method that subclasses might implement.

Instead I implemented (2) a compareTo method that along with the abstract compareAddressTo method forces subclasses to implement comparison between two objects of the subclass type.

A third way of doing it (3) would be to have an abstract compareTo in Address and provide a protected method that the subclass implementation of compareTo can call that will provide the ordering by netParams and subclass.

(3) might be a better way to go. I want to get this fixed, so I'm happy with any of the methods, but after implementing (2), I would say that (3) is my first choice, (2) my second choice, and (1) my last choice.

So let me know what you want me to do. I can implement (3) or (1) or leave it as it is.

Copy link
Member

Choose a reason for hiding this comment

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

After your explanation I also think that (1) is clearly inferiour. As for picking (2) or (3), I think I have no preference so I'll leave it up to you.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks @schildbach , (3) is implemented (along with some JavaDoc cleanup), squashed, and is passing tests.

@msgilligan
Copy link
Member Author

@schildbach Can you review this one? If it looks good, I'll squash it, add a few more comments, and change it from "DRAFT" to "Ready to Merge".

Require address subclasses to implement compareToand provide the compareAddressPartial
method for comparing the first two fields.
@msgilligan msgilligan force-pushed the msgilligan-fix-address-compareto branch from a8ea460 to 7c6a37c Compare August 21, 2020 03:52
@msgilligan msgilligan marked this pull request as ready for review August 21, 2020 04:02
@msgilligan
Copy link
Member Author

@schildbach This is ready for final review.

@msgilligan msgilligan changed the title WIP: Add Comparable to Address remove from PrefixedChecksummedBytes Add Comparable to Address remove from PrefixedChecksummedBytes Aug 21, 2020
@schildbach
Copy link
Member

I removed a few unused imports from this PR and merged. Thanks for sticking to this!

@schildbach schildbach closed this Aug 25, 2020
@msgilligan msgilligan deleted the msgilligan-fix-address-compareto branch October 25, 2021 18:29
msgilligan added a commit to OmniLayer/OmniJ that referenced this pull request Oct 25, 2021
bitcoinj/bitcoinj#2018 is merged
in bitcoinj-0.16, so this workaround can be removed.
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

2 participants