Commit Graph

6702 Commits

Author SHA1 Message Date
Jamil Lambert, PhD 20d3f16a54
Fix clippy lint in new rustc nightly
New nightly lint warning "called `Iterator::last` on a
`DoubleEndedIterator`; this will needlessly iterate the entire iterator"

Code that gives the warning is correct, allow the lint to remove the
warning.

Update rustc nightly to 2025-01-16
2025-01-22 10:13:26 +00:00
Shing Him Ng bfba2a85dd Kill remaining mutants 2025-01-21 17:01:36 -06:00
Shing Him Ng 871fa08f61 Fix typo in serde docs 2025-01-21 17:01:36 -06:00
Shing Him Ng 462c7a1130 Add weekly cargo-mutants workflow 2025-01-21 17:01:27 -06:00
merge-script 39dd3cad20
Merge rust-bitcoin/rust-bitcoin#3920: Make `io::Error` `Sync`
11a9dced76 api: Run just check-api (Tobin C. Harding)
31dda6d53d Make io::Error Sync (Tobin C. Harding)

Pull request description:

  Currently we use a marker that contains an `UnsafeCell` but `UnsafeCell` is not `Sync` so this makes `io::Error` not `Sync`. We can instead wrap the `UnsafeCell` and implement `Sync` for it.

  Fix: #3883

ACKs for top commit:
  apoelstra:
    ACK 11a9dced766c56d6258af6f43d8691aaf7b2110f; successfully ran local tests

Tree-SHA512: 77c89a32e6d409be9db3a40573b78f69eadf24f2d6d4739510753e339ba30a5e6082d21fef52b44481ff2b60f49c1b31dfe45fa12299f97176ba48853b9487a6
2025-01-21 20:40:13 +00:00
merge-script aea7b1affe
Merge rust-bitcoin/rust-bitcoin#3931: Remove mutagen
7277092af4 Remove mutagen (Tobin C. Harding)

Pull request description:

  Back in 2022 we elected to use `mutagen` for mutation testing. Since then `cargo mutants` has progressed to a point where we would now like to use it instead.

  Remove all the `mutagen` stuff.

  Close: #2829

ACKs for top commit:
  ndungudedan:
    tested ACK [7277092](7277092af4)
  apoelstra:
    ACK 7277092af44f44f59bdb6326561b0b47416cc085; successfully ran local tests

Tree-SHA512: bf271bbb30607cfc9970ed6b62e1671279517d6c14c165f063b1fcbef61f735916b1510cd2c10ff624bb8d031cb2783f9636bd7db4dadb6f7534e17db25cfcf2
2025-01-21 17:28:52 +00:00
merge-script b94f26848e
Merge rust-bitcoin/rust-bitcoin#3936: Remove unnecessary `doc(hidden)`
81d4c2e067 Remove unnecessary doc(hidden) (Tobin C. Harding)

Pull request description:

  This trait is private and is meant just for sealing. It already will not show up in public docs and cannot be used by downstream users.

  Resolve: #3912

ACKs for top commit:
  jamillambert:
    ACK 81d4c2e067
  apoelstra:
    ACK 81d4c2e067ec7ed1d39372783261704cb1e802d8; successfully ran local tests

Tree-SHA512: 55668b9013c76364fb4ff37d47502b87c38868d0113cab639415f70d93e99221c0df08e27bf9514390cd9e365cf27baa2bf0727877a694a3b078de7edc123023
2025-01-21 13:24:18 +00:00
jrakibi 7482fcd934 Run just check-api 2025-01-21 17:38:02 +05:30
jrakibi bcc38c40e0 Add Amount division by FeeRate
Implement `checked_div_by_fee_rate_floor` and `checked_div_by_fee_rate_ceil` methods to compute the maximum and minimum transaction weights.
These methods provide precise weight calculations using both floor and ceiling divisions.

- Introduce `checked_div_by_fee_rate_floor` for floor-based weight division.
- Add `checked_div_by_fee_rate_ceil` for ceiling-based weight division.
- Update `ops::Div` implementation for `Amount` to use floor division by default.
- Include unit tests to validate both floor and ceiling division methods.
2025-01-21 17:34:07 +05:30
merge-script 8dfd0bdbb1
Merge rust-bitcoin/rust-bitcoin#3933: Improve docs on `Denomination`
7c7fc36784 Improve docs on Denomination (Tobin C. Harding)

Pull request description:

  Document what each denomination means.

ACKs for top commit:
  jamillambert:
    ACK 7c7fc36784
  apoelstra:
    ACK 7c7fc36784603480df1975f4a77ec583b74efa5c; successfully ran local tests; sure

Tree-SHA512: c0f3a5172e4dfdc6195efc34f36d65700591fe19015e455aa20cacaacc9c516518cec7716028779fd408e8a639eb4a5962a372b1d1d70db06a0ea8130c3bd703
2025-01-21 04:24:10 +00:00
merge-script 2b6c94fe6d
Merge rust-bitcoin/rust-bitcoin#3938: units: Change `create` to `construct` in rustdocs
55470f7357 Change `create` to `construct` in rustdocs (Jamil Lambert, PhD)

Pull request description:

  In preparation for units 1.0 address #3868 and make sure "constructs" is used instead of "creates" in rustdocs.

ACKs for top commit:
  apoelstra:
    ACK 55470f73571ce0e0279f5697a252695e8c8df9b5; successfully ran local tests; sure
  tcharding:
    ACK 55470f7357

Tree-SHA512: 48f9b6cedfca782e698eec4520885f35834582ed098a65b00ccdfa54167c91fe62405f90c9c1e72a671e72ac349af74ac12808ce9e0708799f43d86749590649
2025-01-21 03:23:13 +00:00
Tobin C. Harding 11a9dced76
api: Run just check-api 2025-01-21 12:13:38 +11:00
merge-script 376e6dfa17
Merge rust-bitcoin/rust-bitcoin#3929: Polish `units::parse` docs
7ca5c5ccae Fix rustdoc title on hex_u128_* (Tobin C. Harding)
f1e2564821 Improve docs on parse::int_from_string (Tobin C. Harding)
d97cbc6d27 units: Correct docs on private Sealed trait (Tobin C. Harding)

Pull request description:

  Audit the `units::parse` module checking for sanity of the API. Could still possibly do with more improvements to the docs but for the `1.0-alpha` this is good to go IMO.

  Close: #3710

ACKs for top commit:
  apoelstra:
    ACK 7ca5c5ccae1efe5862f21bfc670257837a202517; successfully ran local tests; looks good!

Tree-SHA512: 937e8f6e1ae0a17217b770daffe1968ec9046c86728a360f1297d7027318511fece31440f462fdaeb94c2a69901a970e20bd2599a6d963bfbdf06b25378fe543
2025-01-21 00:15:00 +00:00
merge-script 8ff69fe9b2
Merge rust-bitcoin/rust-bitcoin#3926: units: Test for dyn compatibility
289a521426 units: Test for dyn compatibility (Tobin C. Harding)

Pull request description:

  Phew! dyn compatibility is a non-trivial concept. There are four public traits in `units`, only one is dyn compatible.

  This patch is done in order to check off C-OBJECT from the Rust API guidelines checklist.

  Add a test to check the public traits in `units` for dyn compatibility.

  While we are at it add a code comment on `Integer` stating why its not dyn-compatible.

  ref: https://rust-lang.github.io/api-guidelines/flexibility.html#c-object

ACKs for top commit:
  apoelstra:
    ACK 289a5214265a1f0d7b320b0121775f868a386c57; successfully ran local tests; nice!

Tree-SHA512: 6f247d4977a87acf68a03bfae12335a8f16ebbe44478da757128f54697c859fa278ddbc0e5c4479918797db91dbe8eef3d2adf60f83518182cb10e84e77120da
2025-01-20 23:32:43 +00:00
Tobin C. Harding 31dda6d53d
Make io::Error Sync
Currently we use a marker that contains an `UnsafeCell` but `UnsafeCell`
is not `Sync` so this makes `io::Error` not `Sync`. We can instead wrap
the `UnsafeCell` and implement `Sync` for it.

Fix: #3883
2025-01-21 10:01:30 +11:00
Tobin C. Harding 7277092af4
Remove mutagen
Back in 2022 we elected to use `mutagen` for mutation testing. Since
then `cargo mutants` has progressed to a point where we would now like
to use it instead.

Remove all the `mutagen` stuff and update the lock files.

Close: #2829
2025-01-21 09:43:12 +11:00
Jamil Lambert, PhD 55470f7357
Change `create` to `construct` in rustdocs 2025-01-20 16:06:29 +00:00
merge-script 274205e147
Merge rust-bitcoin/rust-bitcoin#3923: docs: fix fee rate serde module documentation
34bde36712 docs: fix fee rate serde module documentation (jrakibi)

Pull request description:

  Update `fee_rate/serde.rs` documentation to correctly reference fee rates instead of amount

ACKs for top commit:
  tcharding:
    ACK 34bde36712
  apoelstra:
    ACK 34bde3671212f17082db9ef862e26825602fc6a6; successfully ran local tests

Tree-SHA512: 6fba6ffe4e6c7bdb548967098596b2e7f34d0980710e4f3221b68fe20346a3c1a15d5f9c2a156fc01c8d9341402e61466618520aeb8bcf94a3f818e52828eb8f
2025-01-20 16:04:57 +00:00
Tobin C. Harding 81d4c2e067
Remove unnecessary doc(hidden)
This trait is private and is meant just for sealing. It already will not
show up in public docs and cannot be used by downstream users.

Resolve: #3912
2025-01-20 17:23:12 +11:00
Tobin C. Harding 7c7fc36784
Improve docs on Denomination
Document what each denomination means.
2025-01-20 16:20:04 +11:00
Tobin C. Harding 7ca5c5ccae
Fix rustdoc title on hex_u128_*
The `hex_u32` versions of these functions have better docs, copy them to
the `hex_u128` versions.
2025-01-20 13:47:41 +11:00
merge-script 05c28cf31d
Merge rust-bitcoin/rust-bitcoin#3915: Add FIFTY_BTC const to the amount types
e0028239cf api: Run just check-api (Tobin C. Harding)
5eb5941215 Add FIFTY_BTC const to the amount types (Tobin C. Harding)

Pull request description:

  The mining reward for the first epoc is 50 bitcoin. For mainnet this is old news but for regtest it is still relevant.

  Add and use a new const `FIFTY_BTC` to the `Amount` type. To keep the amount types uniform also add it to the `SignedAmount`.

ACKs for top commit:
  storopoli:
    ACK e0028239cf
  jamillambert:
    ACK e0028239cf
  apoelstra:
    ACK e0028239cf207660deb2873a92bacfa1315af634; successfully ran local tests

Tree-SHA512: 623ed8b1f5fe8dd95309179308fea83d68be4349becf6305769b0378cc9032961df2c062dc2bf702fec5e2394e8abb7360d2be6f19b6cf505db8769a5ae39e16
2025-01-20 02:42:45 +00:00
Tobin C. Harding f1e2564821
Improve docs on parse::int_from_string
I only just worked on this function a week ago and already I couldn't
see from reading the code why it exists. Add a paragraph to the rustdocs
to save the next guy the trouble of working it out.
2025-01-20 13:34:09 +11:00
Tobin C. Harding d97cbc6d27
units: Correct docs on private Sealed trait
Trivial fix to the rustdocs on private trait (required to keep linter
quiet).
2025-01-20 13:22:06 +11:00
Tobin C. Harding 289a521426
units: Test for dyn compatibility
Phew! dyn compatibility is a non-trivial concept. There are four public
traits in `units`, only one is dyn compatible.

This patch is done in order to check off C-OBJECT from the Rust API
guidelines checklist.

Add a test to check the public traits in `units` for dyn compatibility.

While we are at it add a code comment on `Integer` stating why its not
dyn-compatible.

ref: https://rust-lang.github.io/api-guidelines/flexibility.html#c-object
2025-01-20 09:39:38 +11:00
merge-script 3985333e23
Merge rust-bitcoin/rust-bitcoin#3914: units: Define constructor variable in amount tests
f01bb30121 Use sat variable for constructor (Tobin C. Harding)
34f846c074 Use ssat variable for constructor (Tobin C. Harding)

Pull request description:

  Add `sat` and `ssat` throughout the `amount::tests` module after new tests were added recently.

ACKs for top commit:
  jamillambert:
    ACK f01bb30121
  apoelstra:
    ACK f01bb30121ef5a59af069a55db727ee5a9ba71bb; successfully ran local tests

Tree-SHA512: 6a4cdc47000b22625132fe0d8faa7dbff59acfc0b6b4faffe091f885f8d0fd5f5ce15e2298c87e25bd4cc13a2611cecadb43b7d44ccd768a04cd150223577b6b
2025-01-19 16:31:10 +00:00
merge-script afc3690ac6
Merge rust-bitcoin/rust-bitcoin#3925: Automated nightly rustfmt (2025-01-19)
fec6a7669e 2025-01-19 automated rustfmt nightly (Fmt Bot)

Pull request description:

  Automated nightly `rustfmt` changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action

ACKs for top commit:
  tcharding:
    ACK fec6a7669e

Tree-SHA512: db7d2c8282059a6e19274e589e72da2477dda1cb6e618d2a237b371ed0d59a2cc5a32fa5203221bf6beb716477730dadfff97bfc9d5af448929c93230ec9faaa
2025-01-19 14:09:02 +11:00
merge-script b442d942bf
Merge rust-bitcoin/rust-bitcoin#3918: Remove deprecated `std::error::Error` trait method impls
0719997fee api: Run just check-api (Tobin C. Harding)
1e503a8d3b Remove deprecated std::error::Error trait method impls (Tobin C. Harding)

Pull request description:

  The `description` method was deprecated in Rust `v1.42`. The `cause` method was deprecated in Rust `v1.33`. Our MSRV is now Rust `v1.63`.

  We do not need to implement the deprecated functions any longer.

  Fix: #3869

ACKs for top commit:
  apoelstra:
    ACK 0719997feef4ef8b2686e570d4083f88be9c5bb0; successfully ran local tests

Tree-SHA512: e627f614ab8c36ce34109b8d8ef9216e9e802e6db286fa676eff3e6741da39f03cf6080cf47f7d6aa414c5acd790f94b389b219f18992cfcc8869b668e745152
2025-01-19 03:04:41 +00:00
Fmt Bot fec6a7669e 2025-01-19 automated rustfmt nightly 2025-01-19 01:19:33 +00:00
jrakibi 34bde36712 docs: fix fee rate serde module documentation 2025-01-18 18:17:56 +05:30
Tobin C. Harding 0719997fee
api: Run just check-api 2025-01-17 13:40:18 +11:00
Tobin C. Harding 1e503a8d3b
Remove deprecated std::error::Error trait method impls
The `description` method was deprecated in Rust `v1.42`. The `cause`
method was deprecated in Rust `v1.33`. Our MSRV is now Rust `v1.63`.

We do not need to implement the deprecated functions any longer.

Fix: #3869
2025-01-17 13:40:11 +11:00
Tobin C. Harding e0028239cf
api: Run just check-api 2025-01-17 10:21:55 +11:00
Tobin C. Harding 5eb5941215
Add FIFTY_BTC const to the amount types
The mining reward for the first epoc is 50 bitcoin. For mainnet this is
old news but for regtest it is still relevant.

Add and use a new const `FIFTY_BTC` to the `Amount` type. To keep the
amount types uniform also add it to the `SignedAmount`.
2025-01-17 10:08:09 +11:00
merge-script dc76043dcf
Merge rust-bitcoin/rust-bitcoin#3911: Make `Cursor` methods const
9ef8e294ac api: Run just check-api (Tobin C. Harding)
3542803c4e Make Cursor methods const (Tobin C. Harding)

Pull request description:

  Mirror the `std::io::Cursor` type by making the same methods `const`.

ACKs for top commit:
  jamillambert:
    ACK 9ef8e294ac
  apoelstra:
    ACK 9ef8e294ac81c79f413fbe47372a3f94c926ef12; successfully ran local tests

Tree-SHA512: 60ad8169c9bcc90360fcd3c3439256d86af4a77733a00a66e9b155bdb89580d4971efd55a93f1873363ed9d24f0b2b8f5a0da1857bb5aa8a112b13e27239a984
2025-01-16 19:47:47 +00:00
merge-script 70fc3999ae
Merge rust-bitcoin/rust-bitcoin#3900: units: Fix `missing_errors_doc` clippy lint
f9be30ddbe units: Fix `missing_errors_doc` clippy lint (Jamil Lambert, PhD)

Pull request description:

  Change the `missing_errors_doc` clippy lint to `warn`.
  Allow `missing_errors_doc` in `amount/serde.rs` and `fee_rate/serde.rs`. Add missing `# Errors` sections to rustdocs where the lint gives a warning.

  One of the TODO lints in Issue https://github.com/rust-bitcoin/rust-bitcoin/issues/3825

ACKs for top commit:
  tcharding:
    ACK f9be30ddbe
  apoelstra:
    ACK f9be30ddbe5c0837ab3e408dfadabc6c6cd2068e; successfully ran local tests

Tree-SHA512: 8039804ab86c18dceadb425c8531cd4064431393367c6053249e00386f48998d8d84a3aee6ad139e7e2ca3ac3c94e05ee694d72270bf285f6b90d0ff821e622e
2025-01-16 05:13:28 +00:00
Tobin C. Harding 9ef8e294ac
api: Run just check-api 2025-01-16 14:38:35 +11:00
Tobin C. Harding 3542803c4e
Make Cursor methods const
Mirror the `std::io::Cursor` type by making the same methods `const`.
2025-01-16 13:35:25 +11:00
merge-script f1abc779f5
Merge rust-bitcoin/rust-bitcoin#3907: units: Fix `ref_option` clippy lint
29f1a4613a Enable `ref_option` lint and allow individually (Jamil Lambert, PhD)

Pull request description:

  The last `TODO` in #3825

  Allow the `ref_option` lint in the cases where the lint wants us to change the API to ```use `Option<&T>` instead of `&Option<T>` ```

  The other option would be to keep the lint as `allow` and add a comment to `Cargo.toml` as to why we are allowing it like the other cases that are allowed.

  Close #3825

ACKs for top commit:
  apoelstra:
    ACK 29f1a4613a090cd23baded1ef577aa4e3da8d33f; successfully ran local tests; nice!
  tcharding:
    ACK 29f1a4613a

Tree-SHA512: 181d617060e8ae0e75f033b1f356106fc89bdee9841085c889b775e82711c147e5282ecb0e3bf80cdb058034365bbfc7289c029ba0bf8b0b0f26d22505c63aa2
2025-01-16 02:22:06 +00:00
merge-script 6bc12e9363
Merge rust-bitcoin/rust-bitcoin#3864: Update for ParsePublicKeyError Display and Error impl
b11ace359a Fix up ParsePublickeyError (Innocent Onyemaenu)

Pull request description:

  Resolves #3835

  In #945fcd09 we forgot to Update impl for ParsePublicKeyError Display and Error traits

ACKs for top commit:
  tcharding:
    ACK b11ace359a
  apoelstra:
    ACK b11ace359a52d9137b8fe5919d9825d61e3e9fad; successfully ran local tests; thanks!!

Tree-SHA512: 5c4e5e113605bc5b9c3c0d2ca65a0fdae80726a0f2f791255cc1d6567812a9132ff4f5bd8f30276fef916469d5fd29f6d72ddf4adb6340e52f4e0198ac4fb371
2025-01-16 01:37:12 +00:00
merge-script 7706675876
Merge rust-bitcoin/rust-bitcoin#3899: units: Fix `missing_panics_doc` clippy lint
e316e6e719 Fix `missing_panics_doc` clippy lint in units (Jamil Lambert, PhD)

Pull request description:

  Change the units `missing_panics_doc` clippy lint to `warn` and allow for the functions that can't panic.

  One of the TODO lints in Issue #3825

ACKs for top commit:
  tcharding:
    ACK e316e6e719
  apoelstra:
    ACK e316e6e7195993b7dd0e005d2f22f29dfea023c5; successfully ran local tests

Tree-SHA512: 3db74e499dc590a5158869d1a80613d37b3fb09f2d428918dc23b9f1521496d8afff63988f022d6cfd7688d33295f976effe73adbadd8da93dae8fb5d2d13dc5
2025-01-16 00:08:05 +00:00
Tobin C. Harding f01bb30121
Use sat variable for constructor
As we do in other places in the `amount::tests` module; use a local
`sat` variable bound to the `Amount::from_sat` constructor.

Internal change, no logic changes.
2025-01-16 10:42:41 +11:00
Tobin C. Harding 34f846c074
Use ssat variable for constructor
As we do in other places in the `amount::tests` module; use a local
`ssat` variable bound to the `SignedAmount::from_sat` constructor.

Internal change, no logic changes.
2025-01-16 10:39:18 +11:00
Jamil Lambert, PhD e316e6e719
Fix `missing_panics_doc` clippy lint in units
Change the lint to `warn` and allow for the functions that can't panic.
2025-01-15 20:52:12 +00:00
Jamil Lambert, PhD f9be30ddbe
units: Fix `missing_errors_doc` clippy lint
Change the lint to `warn` in `units/Cargo.toml`.
Allow `missing_errors_doc` in `amount/serde.rs` and `fee_rate/serde.rs`.
Add missing `# Errors` sections to rustdocs where the lint gives a
warning.
2025-01-15 20:44:19 +00:00
Innocent Onyemaenu b11ace359a Fix up ParsePublickeyError
In #3847 we added an `InvalidCharError` into one of the variants of
`ParsePublicKeyError` but we forgot to update the trait
implementations.

Fix the `error::Error` and `Display` implementations for
`ParsePublicKeyError`. While we are at it match on `*self` as is
typical in this codebase.

 With this applied #3835 is fully resolved.

 Close: #3835
2025-01-15 21:00:55 +01:00
merge-script 87d93891a3
Merge rust-bitcoin/rust-bitcoin#3905: units: Remove `InputString` from the public API
56286265a5 api: Run just check-api (Tobin C. Harding)
39523ea1f5 units: Remove InputString from the public API (Tobin C. Harding)

Pull request description:

  Currently `InputString` is in the public API of `units` because of the trait bound on `parse::int()`. We can just do the monomorphisisation manually to remove it.

  This patch renames `int` to have three different names, one for `&str` one for `String`, and one for `Box<str>` e.g., `units::parse::int_from_str`.

  Close #3708

ACKs for top commit:
  apoelstra:
    ACK 56286265a55368572c61b03bcb81fe04fb7921c0; successfully ran local tests; this looks great!

Tree-SHA512: 5c16640fe4651fbbafd5e3558d8918414df1bb1579ca64b2256f3c10df410481ae29a77ab89f7a1571bfdd710dc6c6bd8ee9217f2c54eeef06e21ab6ce4aa735
2025-01-15 19:20:11 +00:00
Jamil Lambert, PhD 29f1a4613a
Enable `ref_option` lint and allow individually
Enable the lint and allow the ref_option lint in the cases where the
lint wants us to change the API to use `Option<&T>` instead of
`&Option<T>`
2025-01-15 15:38:41 +00:00
Tobin C. Harding 56286265a5
api: Run just check-api 2025-01-15 08:09:38 +11:00
Tobin C. Harding 39523ea1f5
units: Remove InputString from the public API
Currently `InputString` is in the public API of `units` because of the
trait bound on `parse::int()`. We can just do the monomorphisisation
manually to remove it.

This patch renames `int` to have three different names, one for `&str`
one for `String`, and one for `Box<str>`.
2025-01-15 08:09:38 +11:00