Commit Graph

258 Commits

Author SHA1 Message Date
Tobin C. Harding edab380ac0
bitcoin: Bump version to v0.33.0-alpha.0
Needs release notes but there are 20 pages of them, that feels like too
many to go through manually.

Includes a missing changelog entry in `units` for an already released
change that is included in this `bitcoin` release.
2024-12-04 15:58:36 +11:00
merge-script 58b087d946
Merge rust-bitcoin/rust-bitcoin#3674: Close `amounts` error types
fd2a5c1ec7 Close amounts error types (Tobin C. Harding)
23c77275b1 Reduce code comment lines (Tobin C. Harding)
d595f421c6 Remove whitespace between enum variants (Tobin C. Harding)

Pull request description:

  Close the two pubic enum error types in `units::amounts`. All the other structs are closed already because they either have private fields or marked `non_exhaustive`.

ACKs for top commit:
  apoelstra:
    ACK fd2a5c1ec79f337fb3695c030c9fb6b4671468f2; successfully ran local tests; thanks!

Tree-SHA512: f8d68ef821449e0829c926cf527df4b226b29c8d1d41b320a016fbf70b4b39cc54c8c218955caa0c3776158eeeae0ebacc1cc89dab67bafc399b94063324ab0e
2024-12-02 03:04:07 +00:00
Tobin C. Harding fd2a5c1ec7
Close amounts error types
Close the two pubic enum error types in `units::amounts`. All the other
structs are closed already because they either have private fields or
marked `non_exhaustive`.
2024-12-02 09:14:14 +11:00
Tobin C. Harding 23c77275b1
Reduce code comment lines
Make the comment more terse by using 'info' instead of 'information' and
reduce the line count by 2.
2024-12-02 09:14:06 +11:00
Fmt Bot 0990b30035 2024-12-01 automated rustfmt nightly 2024-12-01 01:41:12 +00:00
merge-script 85d1eb8289
Merge rust-bitcoin/rust-bitcoin#3677: units: Implement `iter::Sum` for all types that implement `ops::Add`
433f70939c Implement iter::Sum for BlockInterval (Tobin C. Harding)
0369e64b56 Implement Sum for an iterator of references to amounts (Tobin C. Harding)
31f883ac00 Implement iter::Sum for FeeRate (Tobin C. Harding)

Pull request description:

  Enables summing an iterator of values. Note that this does not include either `LockTime`s. `absolute::LockTime` should not be added and for `relative::LockTime` we have https://github.com/rust-bitcoin/rust-bitcoin/issues/3676

  Close: #1638

ACKs for top commit:
  apoelstra:
    ACK 433f70939c3ecc10702ab6502e3f9bcd94dab739; successfully ran local tests; nice!
  sanket1729:
    utACK 433f70939c

Tree-SHA512: 1eda00f3bbbc61f795198ce8525a5a9b690478a8abc268da6d2e40de7d91decc28dd8211df0c6abeaf30148c7ec3907b85e3c5351972c354590569840e84d562
2024-11-29 13:28:30 +00:00
merge-script 7d8b9bd883
Merge rust-bitcoin/rust-bitcoin#3673: units: Close the hex parse errors
22769268f3 units: Close the hex parse errors (Tobin C. Harding)

Pull request description:

  As part of the 1.0 effort close the errors in the `units::parse` module.

ACKs for top commit:
  apoelstra:
    ACK 22769268f34b45c0bd86c548eb13cfe1e290f0d7; successfully ran local tests; thanks!
  sanket1729:
    ACK 22769268f3

Tree-SHA512: 598ba236f8c08c3f750112e0d8b8e0aa0568be2700a328e4a2d8999ca59eada8a16a6a1d9e9121e7f42ce9bbe3da3f87221ba67c36056996a687e489f4c6007c
2024-11-29 03:41:48 +00:00
merge-script 99bf3f74b9
Merge rust-bitcoin/rust-bitcoin#3680: units: Test C-COMMON-TRAITS
c49f40fd9a units: Test C-COMMON-TRAITS (Tobin C. Harding)

Pull request description:

  Add structs to the `api` integration test file that verify the set of common traits.

ACKs for top commit:
  apoelstra:
    ACK c49f40fd9af1b9446a7c9a35aefdc02b30801275; successfully ran local tests; good idea!

Tree-SHA512: bc60ed8912e705d4c07714e9d19c0eee4fb2eb6be17a6ee67c2bb922ea27ef3a737eda3f7de690fa3a9fa364c34029989f20361d03f706fd3152ec4f20f33aab
2024-11-28 23:27:42 +00:00
merge-script 31bf3f1931
Merge rust-bitcoin/rust-bitcoin#3659: Add string regression tests in leaf crates
7e17eaf21c units: Add stringy regression tests (Tobin C. Harding)

Pull request description:

  Add regression tests for `Display` and `FromStr` impls. Exclude error types and helper types (`amount::Display`).

  Done as part of #2498 and also as part of the 1.0'ing effort.

ACKs for top commit:
  apoelstra:
    ACK 7e17eaf21c479338d5161b493f02578ef4186e62; successfully ran local tests; nice

Tree-SHA512: 6484806777501fe38557987c9c39b377f972fd4406cf3cfd8ac36f8426041484caab45d4ccff87221dbc5c34507d1be6a7b23839367bd3010855c92fd898c835
2024-11-28 22:47:53 +00:00
Tobin C. Harding c49f40fd9a
units: Test C-COMMON-TRAITS
Add structs to the `api` integration test file that verify the set of
common traits.
2024-11-28 16:59:00 +11:00
Tobin C. Harding 433f70939c
Implement iter::Sum for BlockInterval
We support adding two intervals; no obvious reason not to support
summing an iterator of intervals.
2024-11-28 15:56:07 +11:00
Tobin C. Harding 0369e64b56
Implement Sum for an iterator of references to amounts
We have `iter::Sum` already for `Amount` and `SignedAmount`. Add
an implementation for each to support iterators that yield references.
2024-11-28 15:51:29 +11:00
Tobin C. Harding 31f883ac00
Implement iter::Sum for FeeRate
The `FeeRate` implements `ops::Add`, no reason not to enable summing an
iterator of fee rates.
2024-11-28 15:49:01 +11:00
Tobin C. Harding d595f421c6
Remove whitespace between enum variants
We don't tend to put whitespace between enum variants.
2024-11-28 13:45:01 +11:00
Tobin C. Harding 22769268f3
units: Close the hex parse errors
As part of the 1.0 effort close the errors in the `units::parse` module.
2024-11-28 13:36:09 +11:00
Tobin C. Harding 77085a1fa1
units: Remove serde from amounts
The `Amount` and `SignedAmount` were not supposed to implement `serde`
traits by design because doing so implicitly uses sats. We provide two
modules `as_sat` and `as_btc` to allow users to explicitly serialize in
their preferred format.

In commit: `d57ec019d5 Use Amount type for TxOut value field` derives
were added for `serde` and we did not notice it during review.
2024-11-28 12:55:43 +11:00
Tobin C. Harding 7e17eaf21c
units: Add stringy regression tests
Add regression tests for `Display` and `FromStr` impls.

Exclude error types and helper types (`amount::Display`).
2024-11-27 13:35:45 +11:00
merge-script f27a788288
Merge rust-bitcoin/rust-bitcoin#3639: units: Add integration test of API surface
7b8369f381 units: Add integration test of API surface (Tobin C. Harding)

Pull request description:

  In an effort to check off items in the Rust API guidelines checklist (#3632) add an integration test file that tests:

  - The location of re-exports for various typical usage styles.
  - Regressions in the API surface (things being accidentally moved).
  - All public types implement Debug (C-DEBUG).
  - For all non-error types:
      - `Debug` representation is never empty (C-DEBUG-NONEMPTY)
  - For all error types:
      - Derive standard traits as defined by `rust-bitcoin` policy.
  - All data structures implement `serde` traits (C-SERDE).

  I used the `cargo check-api` script we have laying around from ages ago (#2986) to parse `units` and get a list of the public types.

ACKs for top commit:
  apoelstra:
    ACK 7b8369f381c3f3fc15ed536d5316e86e02914b4e; successfully ran local tests

Tree-SHA512: 6fa2a61f6b67a6b5a56950b87e6df68b761b69bd2a49e7aac48aa238cb84441ce04acd85097d28ae4055058052a7491eccda3da218812149a896e548b4018aaa
2024-11-25 23:48:42 +00:00
merge-script d54c04be00
Merge rust-bitcoin/rust-bitcoin#3647: units: Comment alloc feature
17ca5018eb units: Comment alloc feature (Tobin C. Harding)

Pull request description:

  Add a comment to the `serde` module about why we have all the `alloc` feature gating.

  Done as part of #3556 - auditing the whole crate for use of `alloc` feature.

ACKs for top commit:
  apoelstra:
    ACK 17ca5018ebb28d5d392d61aee62170fb3e4f2a5b; successfully ran local tests

Tree-SHA512: 6d13129903a9c530db811e9f64ae4fa653dbcc952a42502c53c6c622a80c1e58b3037edd0638de78867823ca370b3a4595a08a9ec07b84c71afb6200454f5d6d
2024-11-25 13:32:18 +00:00
Tobin C. Harding 7b8369f381
units: Add integration test of API surface
In an effort to check off items in the Rust API guidelines
checklist (#3632) add an integration test file that tests:

- The location of re-exports for various typical usage styles.
- Regressions in the API surface (things being accidentally moved).
- All public types implement Debug (C-DEBUG).
- For all non-error types:
    - `Debug` representation is never empty (C-DEBUG-NONEMPTY)
- For all error types:
    - Derive standard traits as defined by `rust-bitcoin` policy.

I used the `cargo check-api` script we have laying around from ages
ago (#2986) to parse `units` and get a list of the public types.
2024-11-25 13:33:15 +11:00
merge-script e0ba1b661c
Merge rust-bitcoin/rust-bitcoin#3636: Mark `checked_` functions as `const`
a8379bf005 Mark `checked_` functions const in bitcoin. (Jamil Lambert, PhD)
fe10ff2eb7 Mark functions `const` in `units` (Jamil Lambert, PhD)

Pull request description:

  Following on #3608, #3627 and #1174 the rest of the `checked_` functions in all `rust-bitcoin` have been marked as const.  Except for tests and traits.

ACKs for top commit:
  apoelstra:
    ACK a8379bf0053e66cf5984ce449d19e54e529b6b70; successfully ran local tests; thanks! I find this much easier to read
  tcharding:
    ACK a8379bf005

Tree-SHA512: b8d97b7a3d9fc33b57349f418ccc5aac2f3e8c4145a73bf0e24e85547217d41214696e9a80b1fb5a1bae7e766aad1c2b5df6044564772fe76cec9b3628bcd8e5
2024-11-23 11:46:29 +00:00
Tobin C. Harding 17ca5018eb
units: Comment alloc feature
Add a comment to the `serde` module about why we have all the `alloc`
feature gating.

Done as part of #3556 - auditing the whole crate for use of `alloc`
feature.
2024-11-22 10:42:17 +11:00
Jamil Lambert, PhD fe10ff2eb7
Mark functions `const` in `units`
Mark `checked_` functions const. Replace `map()` and `?` operators,
which are not allowed in const context, with match statements.
Use descriptive variable names in ceiling division to make
it easier to follow.
2024-11-18 14:54:01 +00:00
Fmt Bot 500cd10802 2024-11-17 automated rustfmt nightly 2024-11-17 01:23:55 +00:00
Jamil Lambert, PhD 68aac98753
Mark functions `const`
Mark `checked_` functions const.
Replace `map()` and `?` operators, which are not allowed in const
context, with match statements.
2024-11-15 15:58:52 +00:00
merge-script 3ba3079edf
Merge rust-bitcoin/rust-bitcoin#3614: Add test case
4223655829 Add test case (yancy)

Pull request description:

  Since there are test cases for other functions here, add test case as follow up for https://github.com/rust-bitcoin/rust-bitcoin/pull/3604.  I forgot to request this during review.

ACKs for top commit:
  apoelstra:
    ACK 422365582964cf405529de3a1cf63d766b0d0e2e; successfully ran local tests
  tcharding:
    ACK 4223655829

Tree-SHA512: 8629cfff3e3eb800aa4d4625627e0a777c389566f4125bc63e67fe4c5a597ca63b9fb92da42f6c9dab12e6c63839eef35a13957f98606a37ed687eb96d896c2e
2024-11-15 04:24:13 +00:00
merge-script 7f1237572f
Merge rust-bitcoin/rust-bitcoin#3621: Remove Amount::fmt_value_in
0348801ef3 Remove Amount::fmt_value_in (Shing Him Ng)

Pull request description:

  Saw this mentioned in #3556

  Fixes #2952

ACKs for top commit:
  apoelstra:
    ACK 0348801ef30d1cdfdc40cd2316671532d4c06141; successfully ran local tests
  tcharding:
    ACK 0348801ef3

Tree-SHA512: 29a1d230672a22d059d2ef0870e68dec0fe6d6ae9d3fed51275d9b6779d097578a38a514544df11bdf23908c2d8e3c5fd5c6de2e460aab9792770d6b9e396fc6
2024-11-14 21:44:32 +00:00
yancy 4223655829 Add test case 2024-11-14 13:22:22 -06:00
merge-script 72760bbe96
Merge rust-bitcoin/rust-bitcoin#3606: Deprecate function
eacb1e7831 Deprecate function (yancy)

Pull request description:

  closes https://github.com/rust-bitcoin/rust-bitcoin/issues/3602

ACKs for top commit:
  tcharding:
    ACK eacb1e7831
  apoelstra:
    ACK eacb1e7831bdf2058a674a106b91447c1fe9470e; successfully ran local tests; lol

Tree-SHA512: 9da7881ee62e1808d83c92e232cef42055cce6e3ba03dc1001472948380c16a1968da1d4ce4f7ad13d78d1d70e143851f2635ba167c4df34be61ecf3f2fdee4e
2024-11-14 18:21:20 +00:00
yancy eacb1e7831 Deprecate function 2024-11-13 22:31:24 -06:00
Shing Him Ng 0348801ef3 Remove Amount::fmt_value_in 2024-11-13 19:49:26 -06:00
yancy 971167d0fd Remove test suffix from test names 2024-11-13 17:04:14 -06:00
merge-script 7315ca9a4e
Merge rust-bitcoin/rust-bitcoin#3608: Mark funtions const
4c94695942 Mark funtions const (yancy)

Pull request description:

  May as well mark these const as well.  Follow up to https://github.com/rust-bitcoin/rust-bitcoin/pull/3605

ACKs for top commit:
  apoelstra:
    ACK 4c94695942de41e5eca4ac120db2e069c0bb037d; successfully ran local tests; yeah, I think this are all worth consting
  tcharding:
    ACK 4c94695942
  sanket1729:
    ACK 4c94695942

Tree-SHA512: bf41e416cb8a2eb90e26d7bd640df5c2a5a868e3b721bde7cc8a3b97c687bab4d1cb4ab1c4b04ed625e8657e25c59e386720cb0f9d735ffc492e98f5b8b2ca3c
2024-11-13 14:47:40 +00:00
merge-script a9bc1c7db5
Merge rust-bitcoin/rust-bitcoin#3605: Mark function as const
1db4b723dc Mark function as const (yancy)

Pull request description:

  We discussed marking from_vb as const here: https://github.com/rust-bitcoin/rust-bitcoin/issues/3602

  However, from what I can tell, map() isn't const and I don't see a tracking issue for changing it.  Also, the question mark operator isn't available in const context either, although there is a tracking issue for that: https://github.com/rust-lang/rust/issues/74935.  It will be a long while before that makes it into this projects MSRV if/when it lands.

  There are some other functions in this module that could use the same re-write to make them const as well it looks like.

ACKs for top commit:
  tcharding:
    ACK 1db4b723dc
  apoelstra:
    ACK 1db4b723dc59568c14c76598e7c63c58651ed1cd; successfully ran local tests

Tree-SHA512: 62b612791dd3ce2f6ebf27f586a1262633a46566b9fd3583984171f62209714ad979439345fe86d8ef87d2f78a2cee21d619e2eb3621689faf59d81640e9f77c
2024-11-13 02:01:09 +00:00
yancy 4c94695942 Mark funtions const 2024-11-12 18:16:12 -06:00
yancy 1db4b723dc Mark function as const 2024-11-12 16:10:38 -06:00
Rob N b96501981f
feat(units): add kvb constructor to `FeeRate`
Namely, the feefilter expresses the fee as sat per 1000 vbyte
2024-11-12 08:13:53 -10:00
Tobin C. Harding 84ede349b0
Run the formatter
Run `just fmt`, no manual changes.
2024-11-11 14:19:17 +11:00
yancy 8b928a1515 Split checked_div_by_weight into floor and ceiling version 2024-11-07 16:28:44 -06:00
Jamil Lambert, PhD 1649b68589
Standardize wording to `constructs a new`
There is a range of different wordings used in the docs of constructor
type functions.

Change all to start with `Constructs a new` or `Constructs an empty`.
2024-11-05 13:02:26 +00:00
Jamil Lambert, PhD 27f94d5540
Replace `creates` with `constructs`
In functions that act like constructors there is a mixture of the usage
of `creates` and `constructs`.

Replace all occurrences of `creates` with `constructs` in the first line
of docs of constructor like functions.
2024-11-05 12:47:28 +00:00
merge-script 3b0cb0e87d
Merge rust-bitcoin/rust-bitcoin#3539: Improve the `amount` module
81d8699b55 units: Put no_std up top (Tobin C. Harding)
3e332c3839 amount: Fix docs on FromStr (Tobin C. Harding)
5bec76aa51 amount: Fix rustdocs (Tobin C. Harding)
41c80cc476 amount: Improve docs on div by weight (Tobin C. Harding)
2b4a61739a Add type to debug output for Amount (Tobin C. Harding)
42e5043b33 Add from_int_btc group of functions (Tobin C. Harding)

Pull request description:

  Improve the `amount` module by doing:

  - Patch 1: Add/update `from_int_btc` and `from_int_btc_const` functions
  - Patch 2:  Add type to debug output for `Amount`
  - Patch 3: Fix incorrect docs
  - Patch 4: Make docs use correct style and be uniform across the two amount types
  - Patch 5: Fix docs on `FromStr`

ACKs for top commit:
  apoelstra:
    ACK 81d8699b55dad570247cb14d2b3eea64270a83cf; successfully ran local tests
  jamillambert:
    ACK 81d8699b55

Tree-SHA512: ddd6e02b4cd9a9aa8cbdd2d2f7ae289a6bcca9eb002ef0c6d83a6eca950b2cd08f5918286bb33e814f321e3bfe83fdf75ae051cf8f91ee45d3e4abe76c1c2a4c
2024-11-04 23:32:41 +00:00
Tobin C. Harding 81d8699b55
units: Put no_std up top
The `no_std` attribute has significant ramifications, as opposed to the
clippy attributes etc.

Put the `no_std` attribute up top so it catches the eye. This is also
uniform with other crates in this repo.
2024-11-05 07:49:35 +11:00
Tobin C. Harding 3e332c3839
amount: Fix docs on FromStr
The docs on `FromStr` say "string slice is zero" but actually mean to
document the behaviour when the value represented is zero.

Also the fact that `FromStr` returns an error if parsing fails is self
evident.
2024-11-05 07:49:35 +11:00
Tobin C. Harding 5bec76aa51
amount: Fix rustdocs
Fix the rustdocs on `Amount` and `SignedAmount` by doing:

- Make them uniform
- Use correct style (looks like `SignedAmount` got left behind when we
  improved `Amount`)
2024-11-05 07:49:35 +11:00
Tobin C. Harding 41c80cc476
amount: Improve docs on div by weight
Make an effort to improve the docs on `Amount::checked_div_by_weight`
and `ops::Div<weight> for Amount`.
2024-11-05 07:49:28 +11:00
Fmt Bot 5ecf7f2d67 2024-11-03 automated rustfmt nightly 2024-11-03 01:21:14 +00:00
Tobin C. Harding 2b4a61739a
Add type to debug output for Amount
Debug output usually includes the type (and we do so for
`SignedAmount`). Add the type to the `Debug` output of `Amount`.
2024-11-02 10:19:03 +11:00
Tobin C. Harding 42e5043b33
Add from_int_btc group of functions
Add/update the from_int group of functions to provide one that errors
and one that is const and panics (errors in const context are not useful
because one cannot call `unwrap` in const context).
2024-11-02 10:19:03 +11:00
Tobin C. Harding 38b8c6f5ea
units: Remove a bunch of feature gateing
Remove `alloc` feature gating from all modules in `units`!
2024-11-02 08:24:28 +11:00