Add amount::Display - make formatting configurable#716
Add amount::Display - make formatting configurable#716sanket1729 merged 1 commit intorust-bitcoin:masterfrom
amount::Display - make formatting configurable#716Conversation
|
the way |
|
Because there's no way to pass more than two possible custom formats into |
|
Concept ACK |
|
concept ACK. It's not clear from skimming the PR what happens when you just try to |
|
@apoelstra I didn't change the original implementation which was displaying amount in BTC with BTC suffix. |
|
Ok, that's a reasonable default too. |
5267db1 to
a41c43f
Compare
DisplayAmount - make formatting configurableamount::Display - make formatting configurable
|
Rebased, added tests, refactored&implemented
|
src/util/amount.rs
Outdated
There was a problem hiding this comment.
Forgot to mention: I'm making them separate tests because in practice it was very hard to identify which failed.
thomaseizinger
left a comment
There was a problem hiding this comment.
concept ACK
Some doc nits.
2b8cc5d to
88bd771
Compare
|
The MSRV is soooo old 😭 |
tcharding
left a comment
There was a problem hiding this comment.
Wow, thorough testing, nice effort.
3a0eb09 to
c991b07
Compare
|
@tcharding not thorough enough. I forgot to test Further, I originally wanted sats to behave like integer (ignoring I just pushed both fixes. |
c991b07 to
31ae760
Compare
|
The latest push changes naive manual exponentiation to faster |
|
|
||
| /// SignedAmount | ||
| /// | ||
| /// The [SignedAmount] type can be used to express Bitcoin amounts that supports |
There was a problem hiding this comment.
Not introduced in this PR but 'supports' shouldn't be plural.
There was a problem hiding this comment.
There are two instances of this typo.
There was a problem hiding this comment.
How about having an issue where people can link typos and once there are many we do a larger batch of fixes?
There was a problem hiding this comment.
That's a good idea, should save time.
This significatnly refactors the amount formatting code to make formatting more configurable. The main addition is the `amount::Display` type which is a builder that can configure denomination or other things (possibly more in the future). Further, this makes all representations of numbers minimal by default, so should be documented as a possibly-breaking change. Because of the effort to support all other `fmt::Formatter` options this required practically complete rewrite of `fmt_satoshi_in`. As a byproduct I took the opportunity of removing one allocation from there. Closes rust-bitcoin#709
31ae760 to
4f1200d
Compare
|
Renamed. |
sanket1729
left a comment
There was a problem hiding this comment.
ACK 4f1200d
Thanks for being super careful with this and the elaborate test cases. I learned a lot about format options reviewing this. Hopefully, this settles the Amount Display issue for a long time.
We should add this in release notes as a breaking change
|
ACK 4f1200d |
…matting configurable 4f1200d Added `amount::Display` - configurable formatting (Martin Habovstiak) Pull request description: This significatnly refactors the formatting code to make formatting more configurable. The main addition is the `Display` type which is a builder that can configure denomination or other things (possibly more in the future). Further, this makes all representations of numbers minimal by default, so should be documented as a possibly-breaking change. Because of the effort to support all other `fmt::Formatter` options this required practically complete rewrite of `fmt_satoshi_in`. As a byproduct I took the opportunity of removing one allocation from there. Closes #709 ACKs for top commit: tcharding: ACK 4f1200d dr-orlovsky: ACK 4f1200d sanket1729: ACK 4f1200d Tree-SHA512: 3fafdf63fd720fd4514e026e9d323ac45dfcd3d3a53a4943178b1e84e4cf7603cb6235ecd3989d46c4ae29453c4b0bb2f2a5996fbddf341cd3f68dc286062144
Displaying with minimal number of zeros is the default in Rust and we want to follow it. This was originally implemented in rust-bitcoin#716 but rust-bitcoin#2604 reversed it claiming this is common, however it broke people who rely on minimal display (e.g. BIP21) without fixing the root cause of rust-bitcoin#2136. This reverts commit d887423 adds a test to prevent this change and also fixes the problem with `{:0.8}` not working. Closes rust-bitcoin#2136 Closes rust-bitcoin#2948
3196c27 Deprecate `Amount::fmt_value_in` (Martin Habovstiak) 467546f Round `Amount` when requested precision is too low (Martin Habovstiak) 7c95a77 Fix `Amount` decimals handling (Martin Habovstiak) Pull request description: Displaying with minimal number of zeros is the default in Rust and we want to follow it. This was originally implemented in #716 but #2604 reversed it claiming this is common, however it broke people who rely on minimal display (e.g. BIP21) without fixing the root cause of #2136. This reverts commit d887423 adds a test to prevent this change and also fixes the problem with `{:0.8}` not working. Closes #2136 Closes #2948 Can we backport this one too? ACKs for top commit: tcharding: ACK 3196c27 apoelstra: ACK 3196c27 I also really like how this reduces the complexity of the module, basically passing everything through to `display_in` Tree-SHA512: 3221f83086ac55af3d4caad03fe2b619be303533bba12096040419d119600c8597938809e171662f11b515d469156b083b2072b901d445e4fdfc7b1062cf7b6a
This significatnly refactors the formatting code to make formatting more
configurable. The main addition is the
Displaytype which is abuilder that can configure denomination or other things (possibly more
in the future).
Further, this makes all representations of numbers minimal by default,
so should be documented as a possibly-breaking change.
Because of the effort to support all other
fmt::Formatteroptions thisrequired practically complete rewrite of
fmt_satoshi_in. As abyproduct I took the opportunity of removing one allocation from there.
Closes #709