Commit Graph

5846 Commits

Author SHA1 Message Date
Jamil Lambert, PhD 2d73746ad1
Improve `from_consensus` example
The existing example at first look seemed to contradict the doc above
that the function would not round trip.

Update the example to show the useage for both a time and height based
lock time.

Replace unwrap() with ?
2025-01-29 16:07:49 +00:00
Jamil Lambert, PhD 25a6742573
Add examples to `relative::LockTime` 2025-01-29 16:07:35 +00:00
Tobin C. Harding 5134025180
api: Run just check-api 2025-01-29 12:28:24 +11:00
Tobin C. Harding 9b81a8a2ed
hashes: Remove sha256t::Hash Default impl
The other hash types do not implement `Default` but the tagged one does
still - bad bitcoin devs, no biscuit.
2025-01-29 12:27:48 +11:00
Jamil Lambert, PhD 6cde537d9b
Add `ScriptBuf` tests
Add tests to `owned` to kill the mutants found by `cargo mutants`.
2025-01-28 20:31:17 +00:00
Jamil Lambert, PhD 566a6e5da6
Add `Script` tests
Add tests to `borrowed` to kill the mutants found by `cargo mutants`.
Tests for `to_bytes` were not added since it is deprecated.
2025-01-28 20:30:31 +00:00
merge-script 28b867d8de
Merge rust-bitcoin/rust-bitcoin#3966: Change `#[must_use]` to be the same as stdlib
cb5ffde9ee Change `#[must_use]` to be the same as stdlib (Jamil Lambert, PhD)

Pull request description:

  Change the iterator `#[must_use]` message to be the same as stdlib uses.

  Message taken from https://doc.rust-lang.org/src/core/iter/traits/iterator.rs.html#38

  Close #3962

ACKs for top commit:
  Kixunil:
    ACK cb5ffde9ee
  tcharding:
    ACK cb5ffde9ee

Tree-SHA512: 4866d9bddccdc28e2ba2b15cb4041851abb1512cea0317f20d2e2306df6dcd1addb828d61a84a2083d3ef47abb5cf9276e857cf098de2d28b4706ecd0a1f24fa
2025-01-28 16:53:58 +00:00
merge-script b99a81a0fe
Merge rust-bitcoin/rust-bitcoin#3955: Refactor `LockTime` tests
bc8a378187 Rename `day_` variables to `time_` (Jamil Lambert, PhD)
922392268f Combine satisfied by into singe tests (Jamil Lambert, PhD)
33a7a35bbb Make naming consistent in tests (Jamil Lambert, PhD)

Pull request description:

  As mentioned in https://github.com/rust-bitcoin/rust-bitcoin/pull/3948#discussion_r1927690822 the variable naming in the tests in both `relative::LockTime` and `absolute::LockTime` is inconsistent and possibly confusing.

  Make variable names consistent.

  In `absolute::LockTime` incorporate the two standalone tests `satisfied_by_same` into `satisfied_by` to simplify the tests and conform to what is done in `relative::LockTime` .

ACKs for top commit:
  tcharding:
    ACK bc8a378187
  apoelstra:
    ACK bc8a378187b9fade96223c8ae9578b78f941f449; successfully ran local tests

Tree-SHA512: 643498e05a9fce16d2880c1fdd39422e239bfc60b959d9207d704e9d1de7bc6508761da602bc53217b74c8b7f1986f6d5a0f769507918235ddba72d5f77ca15f
2025-01-28 13:37:01 +00:00
merge-script 21a4b7a3db
Merge rust-bitcoin/rust-bitcoin#3954: Update `README.md`
fe09896c7d Update `README.md` (Jamil Lambert, PhD)

Pull request description:

  `.github/workflows/README.md` is stale

  Add the new `API` check and reorder jobs to match `rust.yml`.

  Close #3942

ACKs for top commit:
  Kixunil:
    ACK fe09896c7d
  tcharding:
    ACK fe09896c7d
  apoelstra:
    ACK fe09896c7d87a0ae6a1b6d6c2525bd5fdff4f3ea; successfully ran local tests

Tree-SHA512: bbd9c57f20022a1383541ce574adc2db3cf02994b71749543ad080ecb585fae7c3577a4d832351948f749edebb5525da50ff79ba6354e1510e83081ba36481f3
2025-01-28 04:07:27 +00:00
Jamil Lambert, PhD cb5ffde9ee
Change `#[must_use]` to be the same as stdlib 2025-01-27 20:13:29 +00:00
Jamil Lambert, PhD fe09896c7d
Update `README.md`
`.github/workflows/README.md` is stale

Add the new `API`
check and reorder jobs to match `rust.yaml`.
2025-01-27 16:59:40 +00:00
Jamil Lambert, PhD bc8a378187
Rename `day_` variables to `time_`
To be consistent with similar lock height test function rename
`day_after/before` to `time_after/before` and change the same `time` to
`time_same`.
2025-01-27 16:45:24 +00:00
Jamil Lambert, PhD 922392268f
Combine satisfied by into singe tests
Include the satisfied by same time/height into the previous test that
checks above and below.
2025-01-27 16:44:41 +00:00
Jamil Lambert, PhD 33a7a35bbb
Make naming consistent in tests
Rename all occurrences of LockTime to specify if it is by height or
time.
2025-01-27 16:42:45 +00:00
merge-script 9c15a31559
Merge rust-bitcoin/rust-bitcoin#3957: Automated daily update to rustc (to nightly-2025-01-24)
75303b331e Automated update to Github CI to rustc nightly-2025-01-24 (Update Nightly Rustc Bot)

Pull request description:

  Automated update to Github CI workflow `rust.yml` by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action

ACKs for top commit:
  tcharding:
    ACK 75303b331e

Tree-SHA512: 81cd6635d412697256c01a6b149631b02555847ceda359823ae20dd78393c9e9d129bc29ceba3e95c4c9e0af4a874419e148db13b828d81f7ae89282327ca41a
2025-01-27 11:22:35 +11:00
merge-script 3daec876f3
Merge rust-bitcoin/rust-bitcoin#3874: io: Improve the docs
71fab82a1b io: Improve docs on macro (Tobin C. Harding)
9c81d5e747 io: Move macro_export below docs (Tobin C. Harding)
b109177e11 io: Improve rustdocs (Tobin C. Harding)
07d8703a00 io: Add SPDX identifier (Tobin C. Harding)
b844637935 io: Remove rustdoc for private module (Tobin C. Harding)

Pull request description:

  As part of #3643 improve the public documentation on the `io` crate.

  While doing this I also checked:

  - C-FAILURE
  - C-LINK
  -  C-METADATA
  - C-RELNOTES
  - C-HIDDEN

ACKs for top commit:
  apoelstra:
    ACK 71fab82a1b32e6077adb896be9d8ac12d5513e0a; successfully ran local tests

Tree-SHA512: 91b8807102277fb7f6602837b7d0e64e4276c9c5bf748ab875ea0e4f1f7f91bc989413acd25e4412d72d6f3744a22b746ed63cbac20d9b42217cd3164c7e6847
2025-01-26 21:44:58 +00:00
merge-script 6b8c5aaf9a
Merge rust-bitcoin/rust-bitcoin#3959: Automated nightly rustfmt (2025-01-26)
a3d2b2a93a 2025-01-26 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:
  apoelstra:
    ACK a3d2b2a93ac8daecb9dc6670c2dcccd24d428b28; successfully ran local tests

Tree-SHA512: 1058c96aacddb3f82ec6dafc8ce037965de9d21a2ec3b8973fa8e4e8385b347975b562b9eabd0536c1daa4ba9283529a34ead64d3568edf893f6d5fb2c8c05b1
2025-01-26 20:23:42 +00:00
merge-script 571402657d
Merge rust-bitcoin/rust-bitcoin#3951: Improve examples on `Denomination`
5f75bfaa63 Improve examples on Denomination (Tobin C. Harding)

Pull request description:

  Reduce the noise in the examples.

ACKs for top commit:
  apoelstra:
    ACK 5f75bfaa63309c7526136d430ca8092197ab7c8e; successfully ran local tests; yeah, agreed, this is nicer to read

Tree-SHA512: 01c5863f8712a8ca3b38d3f96be9d08078ca28d8cfc3dd8e8528c388e5f82406a0d43def552b7b53f034c9bf440f7d2d0fec6a760cf69a245b109d0ce4e288c3
2025-01-26 16:50:08 +00:00
merge-script 2f09da8e47
Merge rust-bitcoin/rust-bitcoin#3950: Use MAX_MONEY in serde regression test
4dad4730a8 Add unreleased changelog entry (Tobin C. Harding)
08bb57e499 Use MAX_MONEY in serde regression test (Tobin C. Harding)

Pull request description:

  We plan on enforcing MAX_MONEY in the amount types. In preparation use MAX_MONEY in the serde regression test instead of the arbitrary, and too large DEADBEEFCAFEBABE value.

ACKs for top commit:
  apoelstra:
    ACK 4dad4730a81f9f08a565f196e5699f054e28f977; successfully ran local tests

Tree-SHA512: 10fefdb75289f4c93537e031410eb729420729563b262d6104948a0176a78c4f6130956b550cc08ffc924b1bce1c42f0544542879a4d44165022196ef695718a
2025-01-26 14:54:13 +00:00
merge-script 72e2b00721
Merge rust-bitcoin/rust-bitcoin#3953: Refactor amounts
13a3f490b8 Use Self instead of amount type (Tobin C. Harding)
34e3049ae0 Use sats instead of satoshi (Tobin C. Harding)
00b71a670f Use from_sat_unchecked for hardcoded ints (Tobin C. Harding)
8fdec67f7d Change local var ua to sat (Tobin C. Harding)
c6f056672b Change local var sa to ssat (Tobin C. Harding)
f3e853e07a units: Do trivial refactor of amount::tests (Tobin C. Harding)
dbec9807f9 Shorten identifiers by removing _in_sats (Tobin C. Harding)
154a4420fc Stop using FQP on Amount type (Tobin C. Harding)
8e16a48252 Run the formatter (Tobin C. Harding)

Pull request description:

  Do a bunch of refactorings to tease out changes from #3794.

  The first 8 are uncontroversial. The 9th one is subjective. The last one is unusual but IMO worth doing because of the relationship between the two amount modules.

  Do note that this PR is 100% internal changes - please please don't bike shed this to death.

ACKs for top commit:
  apoelstra:
    ACK 13a3f490b80e4c8f8e1753111a914315eefd73e6; successfully ran local tests; lgtm

Tree-SHA512: e2ef0e7fbdaaf632a9840920a227a901fbeb55a29398013cd6cb764b1ff7c0a7c5a1648fd8f606e8b5f7523943886f5eff54cf4054d24349feb72f0b4de05b91
2025-01-26 01:57:30 +00:00
Fmt Bot a3d2b2a93a 2025-01-26 automated rustfmt nightly 2025-01-26 01:16:37 +00:00
Update Nightly Rustc Bot 75303b331e Automated update to Github CI to rustc nightly-2025-01-24 2025-01-25 01:34:42 +00:00
Tobin C. Harding 4dad4730a8
Add unreleased changelog entry
We want to be sure to mention the new MAX_MONEY invariant and the fact
that we silently broke serde while doing it.
2025-01-25 06:52:26 +11:00
Tobin C. Harding 13a3f490b8
Use Self instead of amount type
I claim that if the two amount modules are coded as similarly as
possible it will be easier to ensure that we have the API's uniform and
bug free. To make auditing the modules easier and less error prone use
`Self` instead of the explicit type. This makes it easier to see
differences in the modules and to ensure the differences are correct and
required.

Internal change, no logic changes whatsoever.
2025-01-25 06:46:57 +11:00
merge-script 5504e062a9
Merge rust-bitcoin/rust-bitcoin#3948: Fix mutants in `LockTime`
40dc896932 Improve relative::LockTime tests (Jamil Lambert, PhD)
2c73546454 Improve absolute::LockTime tests (Jamil Lambert, PhD)

Pull request description:

  Cargo mutant found untestesd mutants in `relative::Locktime` and `absoulte::LockTime`

  Add/improve tests to kill the mutants.

ACKs for top commit:
  tcharding:
    ACK 40dc896932
  apoelstra:
    ACK 40dc8969322f18bd2f4cb8d9a49eee0b4ed927cc; successfully ran local tests; nice

Tree-SHA512: 0224c38f960b34ed185c24bbfb45488644ee77a3f7b90ed0d58b8ea402f0dd8d82074c7d337e5cc91cc8fa865eafc4d246af0d640545354859652911ca949c99
2025-01-24 04:42:20 +00:00
merge-script 94b40902d4
Merge rust-bitcoin/rust-bitcoin#3946: Fix mutants in units
420e8c043e Fix mutants in units (Jamil Lambert, PhD)

Pull request description:

  Cargo mutant found missed mutants in the bitcoin constants in both signed and unsigned amounts.

  Add a test to check their values.

ACKs for top commit:
  tcharding:
    ACK 420e8c043e
  apoelstra:
    ACK 420e8c043e34817fa51939c0484ed77cb972ad46; successfully ran local tests; sure, this is reasonable enough

Tree-SHA512: 7a3834b9ac8a6c4742405d67e7a5d5b4eecdb6ec262d7525ba9538201c84fd4aef1a900c43a7dfc041cc09741dfc6fa34e7664ae371b66e9554718af0a85083b
2025-01-24 03:55:24 +00:00
Tobin C. Harding 34e3049ae0
Use sats instead of satoshi
No one says that, just use `sats`.

Internal change only.
2025-01-24 12:16:29 +11:00
Tobin C. Harding 08bb57e499
Use MAX_MONEY in serde regression test
We plan on enforcing MAX_MONEY in the amount types. In preparation use
MAX_MONEY in the serde regression test instead of the arbitrary, and too
large DEADBEEFCAFEBABE value.
2025-01-24 12:15:13 +11:00
Tobin C. Harding 5f75bfaa63
Improve examples on Denomination
Reduce the noise in the examples.
2025-01-24 12:09:24 +11:00
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
Jamil Lambert, PhD 40dc896932
Improve relative::LockTime tests
Cargo mutants found some untested mutants.

Add test cases to kill the mutants.
2025-01-23 19:29:42 +00:00
Jamil Lambert, PhD 2c73546454
Improve absolute::LockTime tests
Cargo mutants found some untested mutants.

Add test cases and refactor to improve readability.
2025-01-23 19:29:35 +00:00
Jamil Lambert, PhD 420e8c043e
Fix mutants in units
Cargo mutant found missed mutants in the bitcoin consts in both signed
and unsigned amounts.

Add a test to check their values.
2025-01-23 12:14:16 +00: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