Skip to content

Add bitcoin-units crate#1225

Merged
apoelstra merged 5 commits intorust-bitcoin:masterfrom
tcharding:09-01-bitcoin-units
Dec 11, 2023
Merged

Add bitcoin-units crate#1225
apoelstra merged 5 commits intorust-bitcoin:masterfrom
tcharding:09-01-bitcoin-units

Conversation

@tcharding
Copy link
Copy Markdown
Member

@tcharding tcharding commented Sep 1, 2022

Create a new bitcoin-units crate as described here.

Only the amount module is currently included.

I've resolved the Encodale/Decodable issue by keeping the amount module in bitcoin.

@tcharding tcharding force-pushed the 09-01-bitcoin-units branch 2 times, most recently from ad9dcfc to 5815d99 Compare September 1, 2022 01:09
Copy link
Copy Markdown
Member

@sanket1729 sanket1729 left a comment

Choose a reason for hiding this comment

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

strong concept ACK

@tcharding
Copy link
Copy Markdown
Member Author

tcharding commented Sep 1, 2022

Excuse all the force pushes, I'm wrestling with a few CI things but the core of this PR should be good to go!

@tcharding tcharding force-pushed the 09-01-bitcoin-units branch 4 times, most recently from 7c06523 to 29c733b Compare September 1, 2022 03:25
@tcharding
Copy link
Copy Markdown
Member Author

Finally, all green :)

Kixunil
Kixunil previously requested changes Sep 1, 2022
Copy link
Copy Markdown
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

Mostly nits, what I require is to fix (remove) the doc link and I strongly want to remove core2 dep.

Also maybe make adding the crate and depending on it a single commit so that git would show the file as moved.

@tcharding
Copy link
Copy Markdown
Member Author

Mostly nits,

nits implemented

what I require is to fix (remove) the doc link and I strongly want to remove core2 dep.

Still to resolve, commented above.

Also maybe make adding the crate and depending on it a single commit so that git would show the file as moved.

Done

@apoelstra
Copy link
Copy Markdown
Member

Done reviewing 79102d447ca9607ab60fa9b50acf2063ab43e111. This looks great! ACK except I'd really like to drop core2 if we can do it now. (If it requires a more-involved followup PR that's ok too.)

@tcharding tcharding marked this pull request as draft September 5, 2022 01:18
@tcharding tcharding mentioned this pull request Sep 5, 2022
apoelstra added a commit that referenced this pull request Sep 6, 2022
37cd650 ci: Remove TOOLCHAIN env var (Tobin C. Harding)
8eb6c23 ci: Remove inner quotes from shell variable (Tobin C. Harding)
58ede47 ci: Use set -ex instead of /bin/sh -ex (Tobin C. Harding)
4c4846f Remove double blank line at EOF (Tobin C. Harding)

Pull request description:

  Clean up the CI script. These patches are part of #1225, are beneficial to have before that PR resolves, and are trivial.

ACKs for top commit:
  sanket1729:
    utACK 37cd650
  apoelstra:
    ACK 37cd650

Tree-SHA512: f6b3379c8a1be7a3519461faeed35e35560e4228bddb59ef28ab3fb3ef2679afabfaccfeaffd78adbb66879aed02c092f3d9d1d1eb3193c811067ee75e876732
@Kixunil
Copy link
Copy Markdown
Collaborator

Kixunil commented Sep 7, 2022

I wonder if Work&Target should be here. It feels right except we will have to separate out consensus encoding before we can do it.

@tcharding
Copy link
Copy Markdown
Member Author

I wonder if Work&Target should be here.

I think so too.

It feels right except we will have to separate out consensus encoding before we can do it.

Why's that? Only CompactTarget needs consensus encoding.

@Kixunil
Copy link
Copy Markdown
Collaborator

Kixunil commented Sep 8, 2022

Indeed, and not putting CompactTarget there would feel a bit weird, wouldn't it? Nothing wrong with intermediate step probably.

@tcharding tcharding added this to the 0.30.0 milestone Sep 13, 2022
@tcharding tcharding added minor API Change This PR should get a minor version bump 1.0 Issues and PRs required or helping to stabilize the API aggregate release notes mention labels Sep 13, 2022
@Kixunil Kixunil added the crate smashing Issues and PRs splitting out parts of the main crate to smaller crates label Sep 20, 2022
@apoelstra
Copy link
Copy Markdown
Member

I don't think it'd be too weird if Target was in -units but CompactTarget was in -primitives (or -blockdata or whatever)

@tcharding
Copy link
Copy Markdown
Member Author

tcharding commented Sep 21, 2022

Hey @Kixunil, I rebased on #1297 (fixed a minor issue in macro) but I couldn't get it to build because a static string cannot be used to create a What object so this call fails, am I using InputString correctly?

impl fmt::Display for ParseAmountError {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        use ParseAmountError::*;

        match *self {
            ...
            UnknownDenomination(ref d) => write!(f, "{}", d.display_cannot_parse("denomination")),
           ... 

@Kixunil
Copy link
Copy Markdown
Collaborator

Kixunil commented Sep 21, 2022

a static string cannot be used to create a What object

Oh, forgot to add ?Sized, you could also use &"denomination" while the Sized bound is there.

Edit: removed the bound.

Kixunil
Kixunil previously approved these changes Dec 6, 2023
Copy link
Copy Markdown
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

ACK f2483a7c25f49f343063b1fd8853023c62b3a9dd

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 don't see the inline here.

@tcharding
Copy link
Copy Markdown
Member Author

tcharding commented Dec 6, 2023

Bizzare, the change is in my tree and git status says its up to date. I'll force push again and check it.

EDIT: In case you don't see the comment I made elsewhere, my mistake, I had only done it in units/lib.rs not in bitcoin/lib.rs

@tcharding
Copy link
Copy Markdown
Member Author

tcharding commented Dec 6, 2023

@tcharding IIUC we don't need LICENSE in the crate, just the value in Cargo.toml.

I'm not sure it matters but the bitcoin_hashes crate does not include the license file. I used this address

https://crates.io/api/v1/crates/bitcoin_hashes/0.13.0/download to download the file, which is a tarball even though it ends in .crate, extracted with tar -xzvf and looked inside.

@tcharding tcharding force-pushed the 09-01-bitcoin-units branch from f2483a7 to 40f2c7d Compare December 6, 2023 19:48
@tcharding
Copy link
Copy Markdown
Member Author

Rebased, no other changes.

@tcharding
Copy link
Copy Markdown
Member Author

Used doc(inline) in the bitcoin::amount module.

@tcharding
Copy link
Copy Markdown
Member Author

tcharding commented Dec 6, 2023

I've dropped the copy license patch, its unrelated to this PR since we have other crates already without it. (Force push includes fix to rebase fail also.)

Copy link
Copy Markdown
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

ACK 53fce7ba07be8927a7d66d5b6022f27e8b737b4e

units/Cargo.toml Outdated
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.

IIUC the commits before this one didn't support no-alloc and would fail if tested but I think it's OK since the crate was just created here.

Copy link
Copy Markdown
Member Author

@tcharding tcharding Dec 7, 2023

Choose a reason for hiding this comment

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

I ran cargo test --all--features in units on commit: f42033da Add ParseDenominationError just to make sure. It passes. The reason is that we only use write_err from internals until we introduce InputString usage, so I believe the features are updated in the correct patches.

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.

Actually you need to run --no-default-features.

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.

Still tests cleanly with no default features. Did you see the error or are you guessing from the diff?

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.

What kind of sorcery is this?! I was judging from the diff because there was no #[cfg] to remove the string where InputString is now. Which means my review wasn't very good and I should look into it better.

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.

oooo, took me a while to work this out, we have the very sneaky module declaration as:

// TODO: Make amount module less dependent on an allocator.
#[cfg(feature = "alloc")]
pub mod amount;

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.

There is still a bit of work to do to remove that TODO because of all the functions that return String.

@tcharding
Copy link
Copy Markdown
Member Author

@apoelstra you've been strangely quite on this PR, is it because it only moves amounts? I was planning on adding other types when it merges and before its released, I have not thought yet about which ones though.

@apoelstra
Copy link
Copy Markdown
Member

@apoelstra you've been strangely quite on this PR, is it because it only moves amounts? I was planning on adding other types when it merges and before its released, I have not thought yet about which ones though.

It's because there were a zilion comments from Kix, then fixes, then repeats. Now that Kix has ACKed I have a TODO to review it. Maybe tomorrow.

@tcharding
Copy link
Copy Markdown
Member Author

Sweet, no stress.

@apoelstra
Copy link
Copy Markdown
Member

In f42033dadec7d94dbc9c8efbb301e04d70e9f25c, cargo build --no-default-features in bitcoin/ does not work. Something about needing to import ToOwned from alloc.

But utACK 53fce7ba07be8927a7d66d5b6022f27e8b737b4e once you get it compiling.

@tcharding
Copy link
Copy Markdown
Member Author

I just used to_string since that is already imported, and in the following patch the call is removed anyway.

Copy link
Copy Markdown
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

ACK 4f7779174ca99fb8bb5970b3f867464f0da64eb2

@apoelstra
Copy link
Copy Markdown
Member

c36f07516e8f49ef7d9140848929795efefe611 has the same issue.

Add a new crate `bitcoin-units`, move the `amount` module over to it and
re-export all types from `bitcoin::amount` so this as not a breaking
change.
We have two variants in the `ParseAmountError` that both come from
parsing a denomination, these should be a separate error.
Done so that we can correctly support builds without an allocator.

Add two new error types that wrap `InputString`.
@tcharding
Copy link
Copy Markdown
Member Author

Bother, one day I'll start remembering to pass --all to cargo.

Copy link
Copy Markdown
Collaborator

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

ACK 396e049

Copy link
Copy Markdown
Member

@apoelstra apoelstra left a comment

Choose a reason for hiding this comment

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

ACK 396e049

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

API break This PR requires a version bump for the next release crate smashing Issues and PRs splitting out parts of the main crate to smaller crates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants