de/serde for Amount by way of as_string#730
Closed
tcharding wants to merge 3 commits intorust-bitcoin:masterfrom
Closed
de/serde for Amount by way of as_string#730tcharding wants to merge 3 commits intorust-bitcoin:masterfrom
as_string#730tcharding wants to merge 3 commits intorust-bitcoin:masterfrom
Conversation
Currently we use plural for denomination "bits" and singular for denomination "sat". This means our users must remember which to use which is annoying. There is no reason not to allow parsing plural and singular, at least for the satoshi abbreviation "sats" is a common colloquial term. Enable usage of "bits", "bit", "sat", and "sats" when parsing and displaying denomination.
We recently added a `parse` function to enable deserialization of
strings for `Amount` within a struct. For sats and BTC we have a module
for this so we can go both ways, unless I'm missing something there
doesn't seem to be a reason to not allow serialization of `Amount`
strings to include the denomination also.
With this applied one can do the following:
```
#[derive(Deserialize, Serialize, PartialEq, Debug)]
struct T {
#[serde(default, with = "::util::amount::serde::as_string")]
pub amt: Amount,
}
```
0df642d to
29860ac
Compare
Kixunil
reviewed
Dec 1, 2021
| self.fmt_value_in(f, Denomination::Bitcoin)?; | ||
| write!(f, " {}", Denomination::Bitcoin) | ||
| self.fmt_value_in(f, Denomination::Sats)?; | ||
| write!(f, " {}", Denomination::Sats) |
Collaborator
There was a problem hiding this comment.
I think this will conflict with my PR. Is there a preferred order of merging?
Member
Author
There was a problem hiding this comment.
Do yours first man, I'm the new guy I'll work around you.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is done on top of @stevenroose's PR (#509). Is draft because it is just experimentation / proof of concept.
This does not currently work with
no_stdfeature.This is on ice until #716 is done.