Commit Graph

5659 Commits

Author SHA1 Message Date
Tobin C. Harding 00b71a670f
Use from_sat_unchecked for hardcoded ints
We have an `_unchecked` amount constructor that makes no assumptions
about the argument. We would like to start enforcing MAX_MONEY but the
diff to introduce this is massive. In an effort to make it smaller we
can do all the hardcoded ints first. We did this already but a bunch
more snuck in or were missed.

In any amount constructor that passes in a hardcoded const as a decimal
integer (i.e., not hex) use the `_unchecked` version.

Done in preparation for enforcing MAX_MONEY.
2025-01-24 09:05:00 +11:00
Tobin C. Harding 8fdec67f7d
Change local var ua to sat
As we did for the signed amount; match other identifiers in the `amount`
test module.
2025-01-24 08:58:54 +11:00
Tobin C. Harding c6f056672b
Change local var sa to ssat
Match other identifiers in the `amount` test module. Only done for the
signed amount to make review brain dead easy.
2025-01-24 08:58:08 +11:00
Tobin C. Harding f3e853e07a
units: Do trivial refactor of amount::tests
We are trying to make changes to `units::amount` but the diff is too
big - do the remove-whitespace change on its own.

Whitespace only.
2025-01-24 08:54:24 +11:00
Tobin C. Harding dbec9807f9
Shorten identifiers by removing _in_sats
Using `_in_sats` is not meaningful because an `Amount` is an amount,
period.

Remove `_in_sats` and `_IN_SATS` from identifiers.

Internal change only.
2025-01-24 08:54:24 +11:00
Tobin C. Harding 154a4420fc
Stop using FQP on Amount type
Using `crate::Amount` adds no additional information - stop doing that.

Internal change only.
2025-01-24 08:54:24 +11:00
Tobin C. Harding 8e16a48252
Run the formatter
Manually run `just fmt` - no other changes.
2025-01-24 08:54:24 +11:00
merge-script 67f3d498af
Merge rust-bitcoin/rust-bitcoin#3943: Add `µBTC` as a recognized `str` form of a MicroBitcoin Denomination
4dcdf73cfa Add `µBTC` and `µbtc` to tests (Jamil Lambert, PhD)
afba28e188 Change `uBTC` to `µBTC` in rustdocs (Jamil Lambert, PhD)
2ca24f00f2 Add `µBTC` as a recognized `str` form of `uBTC` (Jamil Lambert, PhD)

Pull request description:

  `µ` is the correct letter for the SI unit micro but is not on most standard keyboards.  `u` was used instead because it looks similar.

  Add `µBTC` to the list of recognized strings for MicroBitcoin.  This is an addition only, `uBTC` still works as normal.

  Change `uBTC` to `µBTC` in the rustdocs.  The examples have been left as `uBTC` since this is easier for most people to use.

  Add `µBTC` and `µbtc` to the tests.

  Close #3941

ACKs for top commit:
  apoelstra:
    ACK 4dcdf73cfa896b2c095cda9064c6e0a0e9aeec2b; successfully ran local tests
  storopoli:
    ACK 4dcdf73cfa
  tcharding:
    ACK 4dcdf73cfa

Tree-SHA512: 0f6e8b8b9c04f1a4dc6536c0420b2ded568ab96d2301b7d488807cb26003b91a787a6cf9023705c731682580f73ae5247f3f3b1e8646e4eb720c5a65da582933
2025-01-23 03:44:59 +00:00
merge-script 97f86100b9
Merge rust-bitcoin/rust-bitcoin#3937: Manual update to rustc (to nightly-2025-01-16)
6d0c6c61ef Run just check-api (Jamil Lambert, PhD)
20d3f16a54 Fix clippy lint in new rustc nightly (Jamil Lambert, PhD)

Pull request description:

  Automated update #3922 failed due to a new clippy lint and a change in the `cargo-public-api` format.

  Update nightly to 2025-01-16, fix the clippy lint and run `just check-api`.

ACKs for top commit:
  tcharding:
    ACK 6d0c6c61ef
  apoelstra:
    ACK 6d0c6c61ef759ac4bfc3b16d32e93f1b483b9365; successfully ran local tests

Tree-SHA512: a4fb8c3dd253acc0d587399771d4ce7893fc5e16cd9637c4968fd730e101456ecaad786506dc83a3d8447b1ac35617ec649d0af2ca52f1d7deb79b04c5366b56
2025-01-23 02:56:29 +00:00
merge-script f064a6e5a1
Merge rust-bitcoin/rust-bitcoin#3804: Introduce cargo-mutants workflow
bfba2a85dd Kill remaining mutants (Shing Him Ng)
871fa08f61 Fix typo in serde docs (Shing Him Ng)
462c7a1130 Add weekly cargo-mutants workflow (Shing Him Ng)

Pull request description:

  This PR introduces `cargo-mutants` via a Github weekly workflow, similar to how the formatter job runs. It can also be updated to run against [incremental changes in a PR](https://mutants.rs/pr-diff.html) or to create an issues that list the new mutants. To address #3796, I've configured it to only run in `units` for now since that's nearing 1.0.

  Here's a [sample run](https://github.com/shinghim/rust-bitcoin/actions/runs/12457984710) i did in my fork, if anyone would like to see what's in the `mutants-out` artifact that gets generated.

ACKs for top commit:
  tcharding:
    ACK bfba2a85dd
  apoelstra:
    ACK bfba2a85ddaad6b366a7502cbda1ff2462dfd4c7; successfully ran local tests

Tree-SHA512: e4a44b6f5121e4238c1c3576616f551f4f43349cf5fd5ac1d6331f958a4458753a55519bdafc16965cb2e67201ef6c91b188c79ffcc222f780c421df9a701063
2025-01-22 21:21:54 +00:00
merge-script 11f5012758
Merge rust-bitcoin/rust-bitcoin#3893: feat: add Amount division by FeeRate
7482fcd934 Run just check-api (jrakibi)
bcc38c40e0 Add Amount division by FeeRate (jrakibi)

Pull request description:

  Add checked_div_by_fee_rate method to Amount that computes the maximum weight for a transaction with a given fee rate. This complements the existing `fee = fee_rate * weight `and `fee_rate = fee / weight` operations

  - Add `checked_div_by_fee_rate` method that returns Option<Weight>
  - Implement` Div<FeeRate>` for Amount for operator syntax support
  - Use `floor` division to ensure weight doesn't exceed intended fee

  This allows calculating the maximum transaction weight possible for a given fee amount and fee rate.

  Closes #3814

ACKs for top commit:
  apoelstra:
    ACK 7482fcd934c09e3cd6cd25fd4328960b02f8e976; successfully ran local tests
  tcharding:
    ACK 7482fcd934

Tree-SHA512: 622ca42bde1f67782a3c2996efcba0132fedb5e984f594603aece974de6acdeb4b22d63239d29d46fb8623c8082841c33b1d5b9ad2ea51e2f63e6f5d859daa7e
2025-01-22 14:26:39 +00:00
Jamil Lambert, PhD 4dcdf73cfa
Add `µBTC` and `µbtc` to tests 2025-01-22 13:26:36 +00:00
Jamil Lambert, PhD afba28e188
Change `uBTC` to `µBTC` in rustdocs
Clippy thinks `µBTC` in the docs needs backticks. Allow it without
backticks.
2025-01-22 13:26:03 +00:00
Jamil Lambert, PhD 2ca24f00f2
Add `µBTC` as a recognized `str` form of `uBTC`
`µ` is the correct letter for the SI unit micro but is not on most
standard keyboards.  `u` was used instead because it looks similar.

Add `µBTC` to the list of recognized strings for MicroBitcoin and to the
rustdocs.
2025-01-22 13:12:40 +00:00
Jamil Lambert, PhD 6d0c6c61ef
Run just check-api 2025-01-22 10:18:11 +00:00
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