Commit Graph

5478 Commits

Author SHA1 Message Date
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
yancy 667b7f1010 Remove unused extern statement
extern crate keywords are no longer needed to import a crate
2024-11-27 23:06:55 -06: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
merge-script f95d877d56
Merge rust-bitcoin/rust-bitcoin#3660: Update `from_next_work_required` to take an i64 for timespan
4d0d78a3af Fix typo in from_next_work_required documentation (Shing Him Ng)
5e47c4123d Update CompactTarget::from_next_work_required to take timespan as i64 (Shing Him Ng)

Pull request description:

  [In Core](f7144b24be/src/pow.cpp (L56)), the timespan is defined as a signed int64. This PR will update `from_next_work_required` to take in an `i64` instead of a `u64`

  Fixes #3652

ACKs for top commit:
  tcharding:
    ACK 4d0d78a3af
  apoelstra:
    ACK 4d0d78a3af2ca300c6b40348724e806bd51ef27a; successfully ran local tests

Tree-SHA512: eea33ec18b081a97ae2a22c681982ad8693200ff8de3a3fc8f46b84b5e72f41589b79140ddd79ba3fce628f1539baf8387422bcc2c6b409fcadc4c2043aa2901
2024-11-28 03:17:08 +00: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
Update Nightly Rustc Bot 987e31a188 Automated update to Github CI to rustc nightly-2024-11-27 2024-11-28 01:55:33 +00:00
merge-script 3a73a480c8
Merge rust-bitcoin/rust-bitcoin#3643: Account for data pushing opcodes in `is_standard_op_return`
e0442782c8 fix(script): account for data pushing opcodes in `is_standard_op_return` (Rob N)

Pull request description:

  While I believe the original commit used 80 bytes for the entire script as the limit, Bitcoin Core as of [this commit](1101837461/src/policy/policy.h (L68-L72)) will relay OP_RETURN outputs as long as the data itself is not above 80 bytes, meaning a script of maximum size 83 bytes should be standard.

ACKs for top commit:
  tcharding:
    ACK e0442782c8
  apoelstra:
    ACK e0442782c8c04bdc48c2743e70f46e41c507e5f4; successfully ran local tests

Tree-SHA512: edd627806c9b5c85050594d45fde49ce3945b9358ae67b4bd0e22f7feb855fe5f4d90f1770870716decbc70aa1a3e0758902c74e3c010977731b823fd72ec23b
2024-11-28 01:14:26 +00:00
Tobin C. Harding 60f43a893d
Remove duplicate test case
In commit:

 `a10d5e15b3 Extract the Script assembly creator from fmt::Debug`

A test case was refactored and where there used to be two test case, one
for `Debug` and one for `Display`, two identical test cases were left.

Remove duplicate test case.
2024-11-28 11:50:42 +11:00
merge-script 35d0e9ad38
Merge rust-bitcoin/rust-bitcoin#3651: Automated daily update to rustc (to nightly-2024-11-22)
3002a3c2f2 Automated update to Github CI to rustc nightly-2024-11-22 (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 3002a3c2f2

Tree-SHA512: f79c2e75398fd8b008966ef30b77b29e1935d3316eb1bd4a8815b2bed4f3e36a3ae8773f5d555ae5bd0448702b5f73f8a20df885d0c50095866bb22279bb23bc
2024-11-28 11:21:06 +11:00
merge-script a22dfc2897
Merge rust-bitcoin/rust-bitcoin#3667: Fix psbt fuzz crash
9aebb96fb9 Fix psbt fuzz crash (Sanket Kanjalkar)

Pull request description:

  Fixes: https://github.com/rust-bitcoin/rust-bitcoin/issues/3628

  This occurs when combining two PSBTs with different xpub key sources. Added a length check before indexing into slices to prevent out-of-bounds access.

  For some reason, the precommit hook complained about non-ascii files. I don't think any of the names here are non-ascii

ACKs for top commit:
  apoelstra:
    ACK 9aebb96fb99e8e9e019663659c6eff851a62f2ce; successfully ran local tests; thanks!
  tcharding:
    ACK 9aebb96fb9

Tree-SHA512: b61274c594bc1f2ea4d04c8a7ace673a7632bb9ea31f59b56779a008c35e61281ea4f6b869990d886779e3e556932a3b2e8b015733ef18e236f12ca77e211c26
2024-11-28 00:00:12 +00:00
yancy d9b48cc2ce Add p2wpkh address creation example 2024-11-27 15:09:14 -06:00
Rob N e0442782c8
fix(script): account for data pushing opcodes in `is_standard_op_return`
While I believe the original commit used 80 bytes for the entire script as the limit,
Bitcoin Core as of [this commit](7a172c76d2/src/policy/policy.h)
will relay OP_RETURN outputs as long as the data itself is not above 80 bytes, meaning a script of maximum size 83 bytes should be standard.
2024-11-27 07:28:23 -10:00
Shing Him Ng 4d0d78a3af Fix typo in from_next_work_required documentation 2024-11-27 11:27:26 -06:00
Shing Him Ng 5e47c4123d Update CompactTarget::from_next_work_required to take timespan as i64
Bitcoin Core's consensus rules allow this timespan interval to be
negative. This commit also updates Params::pow_target_timespan to be a
u32. This field is almost compared to u64 and i64s, so changing this to
a u32 will allow users to use `.into()` for converstions
2024-11-27 11:27:22 -06:00
Sanket Kanjalkar 9aebb96fb9 Fix psbt fuzz crash
Fixes: https://github.com/rust-bitcoin/rust-bitcoin/issues/3628

This occurs when combining two PSBTs with different xpub key sources. Added a length check before indexing into slices to prevent out-of-bounds access.
2024-11-26 21:35:14 -08: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
yancy f961f3c0ec Add test
Test that behavior of this function as it interacts with predict_weight_internal
2024-11-26 16:28:11 -06:00
yancy 3352032892 Fix internal weight calculation
This function calls helper function predict_weight_internal and that
function was refactored.  The refactor changed the interface to accept
the input_weight instead of partial input_weight, however this function
was not updated with the refactor and was still passing a partial input
weight.  This commit is a followup that fixes the internal calculation
error by pass input_weight instead of partial_weight to the helper
function predict_weight_internal.
2024-11-26 16:21:26 -06:00
merge-script cefcce5bbf
Merge rust-bitcoin/rust-bitcoin#3653: Deprecate iwp weight
261c8d8ae6 Add total_weight to Input Weight Prediction (yancy)
cc4c36e8ac Deprecate weight (yancy)

Pull request description:

  Closes https://github.com/rust-bitcoin/rust-bitcoin/issues/3645

  I'm not sure if `total_weight` is the most accurate.  Please advise if there's a different name that is better.

ACKs for top commit:
  apoelstra:
    ACK 261c8d8ae659d98fd3f63228f16d8f2eb4010b7e; successfully ran local tests

Tree-SHA512: f7fbcc587d3b72edf4add8a7bfecf99ee8133f679bd905c2ab6eeb959db455905c7e32ae91c95571599f09df605454f1e9953f1a47d1f1ee6d66270784c77793
2024-11-26 19:57:28 +00:00
merge-script 5958b0f8b8
Merge rust-bitcoin/rust-bitcoin#3656: Fix typo in hash tag type
d9ccb60a2f Fix typo in hash tag type (Tobin C. Harding)

Pull request description:

  In commit: `39f7dcb Reduce API surface of tagged wrapped hash types` I introduced a typo in the tagged hash tag type. Fortunately it has no effect because the tag type controls how an engine  is created (when the tag is input into the engine) and has no effect on the call to `from_engine`. However the typo makes the code confusing.

  This bug is currently unreleased.

  Fix: #3649

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

Tree-SHA512: 54cc78fb74ea119beaf4500d49a4d3954ffc3c52494b3ebc1539a3eec35078cb9388e72b42c59f371b53cced89b7b6303a0e3d3b02e59d72da182dd7bbfe2a55
2024-11-26 19:20:48 +00:00
merge-script 3aed196983
Merge rust-bitcoin/rust-bitcoin#3657: Re-export bech32 crate
f9ab3aea8a Re-export bech32 crate (Tobin C. Harding)

Pull request description:

  `rust-bitcoin` is a lot further from 1.0 than `bech32` is. We previously removed the re-export of `bech32` because we thought it might hold us up releasing `rust-bitcoin 1.0` but in hindsite this was incorrect.

  Having a public re-export of dependencies helps users keep their deps in sync with those in `rust-bitcoin` and is thus useful.

  Close: #3650

ACKs for top commit:
  apoelstra:
    ACK f9ab3aea8abb0bf17d0a03be29d510049a85d0a9; successfully ran local tests; Yeah, let's backport

Tree-SHA512: 62b240bcf7a7f9dd8d4620a44e06a28f07d96eb555ec14500750190f2f6248c915b38d6e0eeab953973c6233d4782d27ec3f7939370e3474ea944d40b9aa8ebb
2024-11-26 16:06:06 +00:00
yancy 261c8d8ae6 Add total_weight to Input Weight Prediction 2024-11-25 22:12:48 -06: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
Tobin C. Harding f9ab3aea8a
Re-export bech32 crate
`rust-bitcoin` is a lot further from 1.0 than `bech32` is. We previously
removed the re-export of `bech32` because we thought it might hold us up
releasing `rust-bitcoin 1.0` but in hindsite this was incorrect.

Having a public re-export of dependencies helps users keep their deps in
sync with those in `rust-bitcoin` and is thus useful.

Close: #3650
2024-11-26 10:13:19 +11:00
Tobin C. Harding d9ccb60a2f
Fix typo in hash tag type
In commit: `39f7dcb Reduce API surface of tagged wrapped hash types` I
introduced a typo in the tagged hash tag type. Fortunately it has no
effect because the tag type controls how an engine  is created (when the
tag is input into the engine) and has no effect on the call to
`from_engine`. However the typo makes the code confusing.

This bug is currently unreleased.

Fix: #3649
2024-11-26 10:06:58 +11:00
yancy cc4c36e8ac Deprecate weight
The name weight is misleading since it is actually only the segwit parts
of the weight calculation
2024-11-25 16:42:47 -06: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
merge-script 2a94004341
Merge rust-bitcoin/rust-bitcoin#3640: address: Add `Address::into_unchecked`
073ff81536 address: Simplify `Address::assume_checked` impl (Max Fang)
e4cf8ebc20 address: Add `Address::into_unchecked` (Max Fang)

Pull request description:

  ## Commits

  ### address: Add `Address::into_unchecked`

  Adds an ergonomic way to convert any `Address` (network can be checked
  or unchecked) into an `Address<NetworkUnchecked>` without cloning, which
  I've found useful in several contexts.

  ### address: Simplify `Address::assume_checked` impl

  Removes an unnecessary `match` which I noticed while implementing `Address::into_unchecked`.

  ## Small note on use of `Self`

  The style guide in `CONTRIBUTING.md` notes to return `Self` when possible, but that doesn't apply here as the `Address` being returned is different from the `Address` type referred to by `Self`, due to the changed `NetworkValidation` type.

ACKs for top commit:
  tcharding:
    ACK 073ff81536
  apoelstra:
    ACK 073ff81536e7a24883d6470ecf3054f4b7263186; successfully ran local tests; nice!

Tree-SHA512: dd6749cffad75d88568106169032d8af023ed56df4b1b38fa613ae7b140d1eb22933e7b0ffc1b17681a5db4b11b28d9db4efb62868755ca3c0f7cac20de0be4b
2024-11-25 13:00:00 +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
Update Nightly Rustc Bot 3002a3c2f2 Automated update to Github CI to rustc nightly-2024-11-22 2024-11-25 01:55:40 +00:00
merge-script b40be3fef6
Merge rust-bitcoin/rust-bitcoin#3637: README: Fix Kani badge and update `no-std` details
a0c79735c7 README: Fix Kani badge and update `no-std` details (S \times 3 🗿)

Pull request description:

  The Kani badge was not displayed due to using `imp` rather than `img` and link was broken. Also the `no-std` details need to be updated.

ACKs for top commit:
  tcharding:
    ACK a0c79735c7
  apoelstra:
    ACK a0c79735c79ab067f2518ecae1c533e75d194ab0; successfully ran local tests

Tree-SHA512: a4da661f14044ff3b5fac611849a14b80ca97f7125902712caa5910873686ff4f669ddf68fe4478b55b7d31d2443cba1260dae2729d50173d66df2641005607c
2024-11-23 16:03:54 +00:00
merge-script d662dba8b5
Merge rust-bitcoin/rust-bitcoin#3641: Fix documentation of Xpub::identifier
434e131660 Fix documentation of Xpub::identifier (LLFourn)

Pull request description:

  :^)

ACKs for top commit:
  tcharding:
    ACK 434e131660
  apoelstra:
    ACK 434e131660e82e06efd97981c1d975c04de2d010; successfully ran local tests; lol

Tree-SHA512: 5c86679a05b6cc7c77f6d6727520002ada1037b4df97c565ac383824afb4e68194a297bdaf8b0074138be54e6142b8f0819da056912c7feed0538bb1a7054254
2024-11-23 14:57:22 +00: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
merge-script 0bff8d05fc
Merge rust-bitcoin/rust-bitcoin#3646: Automated daily update to rustc (to nightly-2024-11-20)
571ba0c77c Automated update to Github CI to rustc nightly-2024-11-20 (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 571ba0c77c

Tree-SHA512: d926de595a816dddbe809717bb3eb2cf5445a1777354cc5a2eb8825e1d123d3bd56a5ec8845c58b634dd7b0d60ce4fdb748e331170d9b171e16e359061f223b1
2024-11-21 15:08:44 +11:00
Update Nightly Rustc Bot 571ba0c77c Automated update to Github CI to rustc nightly-2024-11-20 2024-11-21 01:52:28 +00:00
Max Fang 073ff81536 address: Simplify `Address::assume_checked` impl
Removes an unnecessary `match`.
2024-11-19 21:15:43 -08:00
Max Fang e4cf8ebc20 address: Add `Address::into_unchecked`
Adds an ergonomic way to convert any `Address` (network can be checked
or unchecked) into an `Address<NetworkUnchecked>` without cloning, which
I've found useful in several contexts.
2024-11-19 21:15:43 -08:00
S \times 3 🗿 a0c79735c7 README: Fix Kani badge and update `no-std` details 2024-11-19 10:08:06 +01:00
LLFourn 434e131660
Fix documentation of Xpub::identifier 2024-11-19 15:32:30 +11:00
merge-script c47a41a076
Merge rust-bitcoin/rust-bitcoin#3595: Automated nightly rustfmt (2024-11-17)
500cd10802 2024-11-17 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 500cd10802acc00df3664d7e7a03de7ad0bfe36e; successfully ran local tests; much less offensive this week
  tcharding:
    ACK 500cd10802

Tree-SHA512: 5dbd91260684f257277c5d2706ce8a95a4bf7d8d1e285e8e71261df35425cc7f512688c11643c4ea585905b05cbdfa221fb99731429d46eb5e33c12ab1088307
2024-11-18 16:59:46 +00:00
Jamil Lambert, PhD a8379bf005
Mark `checked_` functions const in bitcoin.
Replace `?` operators, which are not allowed in const context, with
match statements.
2024-11-18 14:54:15 +00: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
merge-script dbedac1bff
Merge rust-bitcoin/rust-bitcoin#3631: Automated daily update to rustc (to nightly-2024-11-17)
7876a0d5ee Automated update to Github CI to rustc nightly-2024-11-17 (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 7876a0d5ee

Tree-SHA512: 80f238cd5a8b5ddf7c71bc8d80cf6cbf930b3db615fbca2a52d59c8f57b38b0ef106d5480a6c18c37821fe58f85dfa8c950a238933376d82d831a08cc78dc46e
2024-11-18 15:29:54 +11:00
Update Nightly Rustc Bot 7876a0d5ee Automated update to Github CI to rustc nightly-2024-11-17 2024-11-18 01:55:58 +00:00
Fmt Bot 500cd10802 2024-11-17 automated rustfmt nightly 2024-11-17 01:23:55 +00:00