Skip to content

de/serde for Amount by way of as_string#730

Closed
tcharding wants to merge 3 commits intorust-bitcoin:masterfrom
tcharding:amount-serde-as-str
Closed

de/serde for Amount by way of as_string#730
tcharding wants to merge 3 commits intorust-bitcoin:masterfrom
tcharding:amount-serde-as-str

Conversation

@tcharding
Copy link
Copy Markdown
Member

@tcharding tcharding commented Nov 30, 2021

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_std feature.

This is on ice until #716 is done.

stevenroose and others added 2 commits November 13, 2021 15:15
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,
        }
```
@tcharding tcharding force-pushed the amount-serde-as-str branch from 0df642d to 29860ac Compare December 1, 2021 01:49
self.fmt_value_in(f, Denomination::Bitcoin)?;
write!(f, " {}", Denomination::Bitcoin)
self.fmt_value_in(f, Denomination::Sats)?;
write!(f, " {}", Denomination::Sats)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think this will conflict with my PR. Is there a preferred order of merging?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Do yours first man, I'm the new guy I'll work around you.

@tcharding tcharding closed this May 26, 2022
@tcharding tcharding deleted the amount-serde-as-str branch May 26, 2022 05:56
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.

3 participants