Implement ordering for TransactionDetails#812
Implement ordering for TransactionDetails#812danielabrozzoni merged 1 commit intobitcoindevkit:masterfrom
Conversation
c62fd73 to
e2800ad
Compare
| // if timestamps are equal, compare by txid | ||
| match (&self.confirmation_time, &other.confirmation_time) { | ||
| (Some(a), Some(b)) => { | ||
| let cmp = a.timestamp.cmp(&b.timestamp); |
There was a problem hiding this comment.
Maybe it would make sense to implement Ord also for BlockTime, which would first compare the height then the timestamp. Here we then can just to compare the entire confirmation_time?
There was a problem hiding this comment.
Good idea, done
e2800ad to
b1e5a40
Compare
| // if timestamps are equal, compare by txid | ||
| match (&self.confirmation_time, &other.confirmation_time) { | ||
| (Some(a), Some(b)) => { | ||
| let cmp = a.cmp(&b); |
There was a problem hiding this comment.
I think you can make this (and below) quite a bit more concise by chaining the cmps via then_with.
Btw., Ord is implemented for Option<T>, so you should be able to just do self.confirmation_time.cmp(&other.confirmation_time).then_with(...), no need for the match.
b1e5a40 to
5036f89
Compare
c8c5038 to
1b5efb0
Compare
|
Ah, this probably would also benefit from a really basic unit test checking that the ordering works as expected. |
|
Added a test |
e8cb6bf to
405e113
Compare
|
Looks like a good reasonable default ordering scheme to me. But you need to fix a clippy error, and rebase to fix a recent CI issue. |
405e113 to
7fe4d5d
Compare
fixed |
7fe4d5d to
d3d0756
Compare
danielabrozzoni
left a comment
There was a problem hiding this comment.
utACK d3d0756
Thanks for taking care of this! :)
Description
Pulled from MutinyWallet/mutiny-node#189
Wallets should be able to sort the transactions easily, this makes it so you can just all
sorton a list of tx details instead of needing to implement the sort_by yourselfChecklists
All Submissions:
cargo fmtandcargo clippybefore committing