Commit Graph

6323 Commits

Author SHA1 Message Date
Andrew Poelstra 82d9d1aeea
amount: rename `from_int_btc_const` unctions to hungarian ones
We have `from_int_btc_const` on both `Amount` and `SignedAmount` because
the "real" `from_int_btc` is generic over the integer type it accepts,
which means that it cannot be a constfn. But we do want a constfn.

However, just because `from_int_btc_const` exists for the sake of
constfn doesn't mean that that's what it *is*. So rename these methods
to reflect what they *are*.
2025-03-18 19:27:51 +00:00
Martin Habovstiak 9ea2e9262f Don't use references to `TaprootMerkleBranchBuf`
The new unsized type is more flexible and so are the references to it.
Just like we pass around `&str` instead of `&String` we should be
passing `&TaprootMerkleBranch` instead of `&TaprootMerkleBranchBuf`.
2025-03-18 16:33:05 +01:00
Martin Habovstiak c528f52894 Change `Deref::Target` of `TaprootMerkleBranchBuf`
`TaprootMerkleBranchBuf` previously derefed to a slice which lost the
information about length being valid. This commit changes the type
which, while API-breaking, is not disruptive because the type has API
very similar to slice.
2025-03-18 16:32:55 +01:00
Martin Habovstiak 04a4efbe63 Introduce unsized `TaprootMerkleBranch`
`TaprootMerkleBranchBuf` being a vec introduced intermediate allocation
when creating or decoding `Witness`. However the representation on the
wire is the same as in-memory (aside from `#[repr(transparent)]`) so
this allocation wasn't really needed.

This commit introduces `TaprootMerkleBranch` type which is unsized and
can be used in place of `TaprootMerkleBranchBuf` within `ControlBlock`.
Aside from removing the intermediate allocation, this improves the API a
bit: the conversion from array to other type is no longer needed because
it's performed by `ControlBlock` in its methods. Thus, consumers who
have an array can simply set it as `merkle_branch` field and then encode
the `ControlBlock` into witness. A convenience method is also provided
to push the `ControlBlock` along with other parts at the end of the
`Witness`.
2025-03-18 16:31:46 +01:00
Martin Habovstiak 370c2597c6 Add `as_mut_slice` to `TaprootMerkleBranchBuf`
`TaprootMerkleBranchBuf` already had `as_slice` method and `DerefMut`
but was missing `as_slice_mut`, so this change adds it.
2025-03-18 16:20:16 +01:00
Martin Habovstiak 33d75659da Push `merkle_branch` module one level deeper.
This moves the content of the module into `buf` submodule making future
changes clearer.
2025-03-18 16:20:16 +01:00
Martin Habovstiak 277045bad7 Add `Buf` suffix to `TaprootMerkleBranch`
This type actually contains a `Vec` but we would prefer to have an
unsized type. Rename it first so that we can reuse the name later.
2025-03-18 16:20:16 +01:00
Tobin C. Harding 2ec1c2a044
units: Make from_int_btc_const take a 16 bit integer
The `from_int_btc_const` constructors are specifically designed for
easily creating amount types in const context but currently they return
an error which is annoying to handle in const context. If we make the
`whole_bitcoin` parameter a 16 bit integer this gives us a nicer const
constructor with the downside that it can only create values upto a
maximum of

- unsigned: 65_536
- signed: 32_767

That is plenty high enough for most use cases.

Then use the new `from_int_btc_const` in associated consts.

Note that because `from_sat` checks max (and min) values we must
define max and min from sats directly.
2025-03-18 14:49:34 +00:00
Jamil Lambert, PhD 7b114e3893
Increase test coverage in relative.rs
Increase test coverage in `locktime/relative.rs`
2025-03-18 14:30:50 +00:00
Jamil Lambert, PhD c97bebdcba
Increase test coverage in absolute.rs
Modify existing tests and add new ones to increase test coverage in
`locktime/absolute.rs`.
2025-03-18 14:28:52 +00:00
merge-script cfccd389a9
Merge rust-bitcoin/rust-bitcoin#4242: Automated nightly rustfmt (2025-03-16)
a74e08a53d 2025-03-16 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 a74e08a53d
  apoelstra:
    ACK a74e08a53df42a822b3e4840f37bf72b24418fe1; successfully ran local tests

Tree-SHA512: ca233e517c6734181e86940ba92bde1c2b138b66ff27e80a10f98d5ae1aac5ac73ec46633bba2a94ba143d01602764bfe6ffad2378cdf8bbfe4210be620113ea
2025-03-18 12:27:46 +00:00
merge-script 78538bc8a6
Merge rust-bitcoin/rust-bitcoin#4251: Enable getting the network kind from an address
f4f79f88eb Enable getting the network kind from an address (Tobin C. Harding)

Pull request description:

  Users may wish to ask of an address 'what kind of address is this?' We have the `NetworkKind` struct that abstracts over the answer but currently no API to ask the question.

  The address may have been parsed or constructed and weather the network has been checked already is immaterial. Hence we add the function for both `NetworkChecked` and `NetworkUnchecked` addresses.

  Fix: #4247

ACKs for top commit:
  apoelstra:
    ACK f4f79f88eb2c6c80c46c95c69fcc43b17d306be2; successfully ran local tests
  Kixunil:
    ACK f4f79f88eb

Tree-SHA512: 57bdf7a0f2ae8bf599b3830d10201af3f6312a802ab72c0d86e346af660cbc4f430954e46d6698032a062514ec3ee1ee7edc732beff79af99a84ce718a519afa
2025-03-17 23:22:15 +00:00
merge-script ac502b0fc3
Merge rust-bitcoin/rust-bitcoin#4246: fix spelling issues
441e173792 Update owned.rs (planetBoy)
dd6687d992 Update sighash.rs (planetBoy)

Pull request description:

  bitcoin/examples/sighash.rs
  inde - index `fix errors`

  bitcoin/src/blockdata/script/owned.rs
  paics - panics `fix errors`

ACKs for top commit:
  Kixunil:
    ACK 441e173792
  tcharding:
    ACK 441e173792

Tree-SHA512: a040cfd58f0ce17d8698da6f815705da77557d99d6c1b0e7d30696ff38a72857ed17e93aea169890983bdd6c36b9b8617e435178b94014a5bba3eacc7f4286b0
2025-03-17 21:31:12 +00:00
merge-script f6c97d300d
Merge rust-bitcoin/rust-bitcoin#4244: chore: spellchecker
427bfb82d7 chore: spellchecker (healthyyyoung)

Pull request description:

ACKs for top commit:
  Kixunil:
    ACK 427bfb82d7
  tcharding:
    ACK 427bfb82d7
  apoelstra:
    ACK 427bfb82d75cdc98d31ec270c2011d6f6d75bcd4; successfully ran local tests

Tree-SHA512: 979bdbcd865f336388c144d7ebc5aff4b061847be79c7e880140a044619d68fc80d4eada5c76dc5f66bb4b4464cd0d3c79c9ba0d549a13556efb55673254117f
2025-03-17 19:49:51 +00:00
Tobin C. Harding f4f79f88eb
Enable getting the network kind from an address
Users may wish to ask of an address 'what kind of address is this?' We
have the `NetworkKind` struct that abstracts over the answer but
currently no API to ask the question.

The address may have been parsed or constructed and weather the network
has been checked already is immaterial. Hence we add the function for
both `NetworkChecked` and `NetworkUnchecked` addresses.

Fix: #4247
2025-03-17 12:27:11 +11:00
merge-script ffb5bac2b6
Merge rust-bitcoin/rust-bitcoin#4239: Automated weekly update to cargo-semver-checks (to 0.40.0)
cacf734ccf Automated update to Github CI to cargo-semver-checks version-0.40.0 (Update cargo-semver-checks Bot)

Pull request description:

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

ACKs for top commit:
  tcharding:
    ACK cacf734ccf

Tree-SHA512: 7fb8c6b5c5d8614d39ee14b961f29371b135596cbbe6930183495baf81fa6dcaf53866f853986d5f924c0e2fbd0e7c06193bb65e5249d64d82c373e27644c064
2025-03-17 07:22:20 +11:00
merge-script 4bd91b0067
Merge rust-bitcoin/rust-bitcoin#4240: Automated daily update to rustc (to nightly-2025-03-14)
058e8285f0 Automated update to Github CI to rustc nightly-2025-03-14 (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 058e8285f0

Tree-SHA512: d3211e78dbb5717b9369a7d331f07d7c2c3560e24de8ffadf6c60170f60ffbb4a9991e5dba174ddb8e0cb11bbbfed91737b2fda04b7d199f383050a26ff442e1
2025-03-17 07:21:32 +11:00
planetBoy 441e173792
Update owned.rs 2025-03-16 16:14:13 +01:00
planetBoy dd6687d992
Update sighash.rs 2025-03-16 16:13:21 +01:00
healthyyyoung 427bfb82d7 chore: spellchecker 2025-03-16 07:23:18 +00:00
Fmt Bot a74e08a53d 2025-03-16 automated rustfmt nightly 2025-03-16 01:25:25 +00:00
Update Nightly Rustc Bot 058e8285f0 Automated update to Github CI to rustc nightly-2025-03-14 2025-03-15 01:44:24 +00:00
Update cargo-semver-checks Bot cacf734ccf Automated update to Github CI to cargo-semver-checks version-0.40.0 2025-03-15 01:07:34 +00:00
merge-script 0ca9fcfd0e
Merge rust-bitcoin/rust-bitcoin#4157: Enforce MAX_MONEY invariant in amount types
ab4ea7c13d Enforce the MAX_MONEY invariant in amount types (Tobin C. Harding)

Pull request description:

  Enforcing the `MAX_MONEY` invariant is quite involved because it means multiple things:

  - Constructing amounts is now fallible
  - Converting from unsigned to signed is now infallible
  - Taking the absolute value is now infallible
  - Integer overflow is eliminated in various places

  Details:
  - Update `from_sat` to check the invariant
  - Fix all docs including examples
  - Use the unchecked constructor in test code
  - Comment any other use of the unchecked constructor
  - Deprecate `unchecked_abs`
  - Fail serde (using the horrible string error variant)
  - Try not to use the unchecked constructor in rustdocs, no need to encourage unsuspecting users to use it.
  - Use `?` in rustdoc examples (required by Rust API guidlines)
  - Remove `TryFrom<Amount> for SignedAmount` because the conversion is now infallible. Add a `From` impl.
  - Fix the arbitrary impls
  - Maintain correct formatting
  - Remove private `check_max` function as its no longer needed

  Close #620

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

Tree-SHA512: bec963d8ea69e202f399cd19bca864b06f3e86323d376c2d2126d74093598f8bbbf19792b2327dba0862ef6f0201202778014a2be7a14991f02917d8ca312afb
2025-03-13 23:35:40 +00:00
merge-script 2f711b0c07
Merge rust-bitcoin/rust-bitcoin#4235: Use impl_op_for_references macro in fee module
93c6c8cef5 Use impl_op_for_references macro in fee module (Erick Cestari)

Pull request description:

  This pr replaces the individual operator implementations in the fee module with the impl_op_for_references macro to handle reference operations. This removes the need to manually implement reference combinations for operands, simplifying the code and improving consistency.

  ### Changes:
  - Replaces direct implementations of operators with macro usage
  - Adds tests to verify that reference operations work correctly
  - Maintains the same semantics as the original implementation

  Closes #4173

ACKs for top commit:
  tcharding:
    ACK 93c6c8cef5
  apoelstra:
    ACK 93c6c8cef59ceed56932d62daeb212c2b40fc4a1; successfully ran local tests; yeah, I think the docs loss is fine -- the docs are hard to find and say exactly what users expect of the / operator

Tree-SHA512: 51d7643c2cecd16a0cb16afcd195fd87bc9eca9116e16518d888ba61a8edb5684162af987ea52611c9463f5299810f92a057dedc3fa8e89cdef21ef40528bca1
2025-03-13 19:37:59 +00:00
merge-script d1365eb376
Merge rust-bitcoin/rust-bitcoin#4219: Rename then new `Timestamp` type
c707b959b7 Rename timestamp module to time (Tobin C. Harding)
e2dee4900f Re-name Timestamp to BlockTime (Tobin C. Harding)

Pull request description:

  Done in two patches so we can bikeshed the name of the type and separately the name of the module.

  - Rename type: `Timestamp` to `BlockTime`
  - Rename module: `timestamp` to `time`

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

Tree-SHA512: de3855b38445a58b6767a6081919eecb81c6c12aee3f6699f3bfa10efaf5770b54fb412da23991a9ee734e14dfb642af670f0218d1886cdc8c8d3f393ef65d7e
2025-03-13 15:13:31 +00:00
merge-script 1798679145
Merge rust-bitcoin/rust-bitcoin#4217: primitives: Increase test coverage in `block.rs`
c1ea20b958 Increase test coverage in block.rs (Jamil Lambert, PhD)
3e750d7ba1 Create test helper function to create a header (Jamil Lambert, PhD)

Pull request description:

  Add tests to `primitive::block` module to increase test coverage.

  Coverage tested with `cargo-tarpaulin`

  `block.rs` coverage:
  before 13.79%
  after 100%

ACKs for top commit:
  apoelstra:
    ACK c1ea20b958f448a5a35073ce3d5bd5394918eb9b; successfully ran local tests
  tcharding:
    ACK c1ea20b958

Tree-SHA512: 70bbdce9c45e9bdcea76026b7a27582a32b796099329c429527d7dfe574788604020e53e417afd3cf53886ceb87df37b6dcb34a7ff40260b9d8a3811e22a478c
2025-03-13 13:19:54 +00:00
merge-script 80dcbd618a
Merge rust-bitcoin/rust-bitcoin#4234: chore: add missing backquotes
61e7226299 chore: add missing backquotes (kevincatty)

Pull request description:

  add missing backquotes

ACKs for top commit:
  apoelstra:
    ACK 61e7226299fbfb13f34ba27e45042019a92b050d; successfully ran local tests
  tcharding:
    ACK 61e7226299

Tree-SHA512: 232cdcd9627cb1ae06e9c9c022460ee4fc405845bdf8863aaadf38d22dc022891f3f9a6a49b6aeeeceef62e48493357cbf293458f687f5d5d41a697c152da007
2025-03-13 03:15:02 +00:00
merge-script bc8de7846e
Merge rust-bitcoin/rust-bitcoin#4233: test: add coverage for ServiceFlags::P2P_V2
c0e20dbf2e test: add coverage for ServiceFlags::P2P_V2 (Bruno Garcia)

Pull request description:

  Include `P2P_V2` on `service_flags_test`

ACKs for top commit:
  tcharding:
    ACK c0e20dbf2e
  apoelstra:
    ACK c0e20dbf2e1406a3f3df5538d1397b233078cd7c; successfully ran local tests

Tree-SHA512: 6ebb2f493bcc8fc6643cec67945a81692f03ceb976d75e10ce6052e775901846b9795f31817439b4484ef2d1eaae122d7da270cac2b59d7bb41cb2015593d1f5
2025-03-13 01:51:10 +00:00
merge-script d8a90f6865
Merge rust-bitcoin/rust-bitcoin#4232: fix comment ecdsa-psbt.rs
968406cb95 Update ecdsa-psbt.rs (planetBoy)

Pull request description:

  desciptor - descriptor -> `fix typo`

ACKs for top commit:
  tcharding:
    ACK 968406cb95
  apoelstra:
    ACK 968406cb95d7490869de9f23022f5c77a3665de8; successfully ran local tests

Tree-SHA512: 40e1d1133b16aaf14e7a0d8a2a40db8e233a1736c1c4caa2f340aa1f243283ef2b3dd2bc238a44122301b5e171b15f3638a21f6cc2089bc324dba54c49daaba2
2025-03-12 23:31:50 +00:00
Tobin C. Harding ab4ea7c13d
Enforce the MAX_MONEY invariant in amount types
Enforcing the MAX_MONEY invariant is quite involved because it means
multiple things:

- Constructing amounts is now fallible
- Converting from unsigned to signed is now infallible
- Taking the absolute value is now infallible
- Integer overflow is illuminated in various places

Details:

- Update from_sat to check the invariant
- Fix all docs including examples
- Use the unchecked constructor in test code
- Comment any other use of the unchecked constructor
- Deprecate unchecked_abs
- Fail serde (using the horrible string error variant)
- Try not to use the unchecked constructor in rustdocs, no need to encourage unsuspecting users to use it.
- Use ? in rustdoc examples (required by Rust API guidlines)
- Remove TryFrom<Amount> for SignedAmount because the conversion is now infallible. Add a From impl.
- Fix the arbitrary impls
- Maintain correct formatting
- Remove private check_max function as its no longer needed
2025-03-13 09:07:14 +11:00
merge-script 1f74571401
Merge rust-bitcoin/rust-bitcoin#4230: Fix BIP32 validation for private keys and master key constraints (#4195)
8f74b823ab Add validation for private key format and master key constraints (Erick Cestari)

Pull request description:

  This PR addresses issue #4195 by adding proper validation when decoding extended private keys:

  ### Changes

  - Add validation to ensure byte 45 is zero as required by BIP-32 specification for private keys
  - For master keys (depth=0), add validation to ensure parent fingerprint is zero
  - For master keys (depth=0), add validation to ensure child number is zero
  - Add corresponding error types to handle these validation failures
  - Add unit tests to verify each validation rule

  ### Validation Rationale
  These checks improve security by rejecting malformed extended keys that could potentially lead to unexpected behavior. As noted in the issue discussion, these validations are explicitly required by the BIP-32 specification.

  ### Testing
  Added three new unit tests to verify each validation rule:

  - test_reject_xpriv_with_non_zero_byte_at_index_45
  - test_reject_xpriv_with_zero_depth_and_non_zero_index
  - test_reject_xpriv_with_zero_depth_and_non_zero_parent_fingerprint

  Fixes #4195

ACKs for top commit:
  jrakibi:
    ACK 8f74b823ab
  tcharding:
    ACK 8f74b823ab
  apoelstra:
    ACK 8f74b823ab8ef44bde7d003f8ba43fbe44dbef3e; successfully ran local tests

Tree-SHA512: 6a013e4917f83cfd7e39a2a18f7491853d791ab1d981a99eeea6204e1dab723fed7a168ff2a89e8850d512c3c381bfa1afef7fa32e5a0d246d949a46b01a3023
2025-03-12 21:59:24 +00:00
Erick Cestari 93c6c8cef5 Use impl_op_for_references macro in fee module
This commit replaces the individual operator implementations in the fee
module with the impl_op_for_references macro to handle reference operations.
This removes the need to manually implement reference combinations for
operands, simplifying the code and improving consistency.

The change:
- Replaces direct implementations of operators with macro usage
- Adds tests to verify that reference operations work correctly
- Maintains the same semantics as the original implementation
2025-03-12 15:24:53 -03:00
merge-script b18aa6f9d4
Merge rust-bitcoin/rust-bitcoin#4229: feature: introduce MAX_BLOCK_SERIALIZED_SIZE to check limit
e4513bf925 feat: add MAX_BLOCK_SERIALIZED_SIZE existing in core (ChrisCho-H)

Pull request description:

  fad0d9ea2d1e807806fa141238e279fddea6ae99: add `MAX_BLOCK_SERIALIZED_SIZE` as constant, which also exists in [bitcoin-core](59ff17e5af/src/consensus/consensus.h (L13)).

  I originally thought it would be better to use this value for checking limit of push_bytes [here](0870cd1660/bitcoin/src/blockdata/script/push_bytes.rs (L31)), as it's the actual limit(`OP_PUSHDATA4` semantic says it could allow up to 4GB though). However, I'm not sure whether there might be need to push_bytes larger than `MAX_BLOCK_SERIALIZED_SIZE`, so just let developer use this constant to check the actual limit rather than enforcing it.

ACKs for top commit:
  tcharding:
    ACK e4513bf925
  apoelstra:
    ACK e4513bf9250799bc18a10728af184d6c86a561a4; successfully ran local tests

Tree-SHA512: 44c5a4882666ad286c1e1c40b9738929e2a8ad4bb44aaf48865fc395291185ae5aae351d26ac9334671e47a11e844bd037bd251a921b6b028a116d1b442b9183
2025-03-12 14:21:32 +00:00
merge-script 3cef539aac
Merge rust-bitcoin/rust-bitcoin#4164: Prepare to enforce MAX_MONEY invariant
5d851f1c3e Remove deprecated amount methods (Tobin C. Harding)
76a2d70b28 Make mul weight by fee return NumOpResult (Tobin C. Harding)
f9eb307953 Remove panic in dust value functions (Tobin C. Harding)
13595fbe7d Fix amount whole bitcoin constructors (Tobin C. Harding)
ac71680202 Pick one - MAX or MAX_MONEY (Tobin C. Harding)
6d70c77cf9 Enforce newtype sanity rules for amount types (Tobin C. Harding)
e6f7b26d80 Use _unchecked in amount const types (Tobin C. Harding)
ef0af8d62e Use sat/ssat constructors throughout tests (Andrew Poelstra)
8ecdc7c275 Use den_ prefix for local Denomination variable (Tobin C. Harding)
938461cc65 psbt: Use Amount::ZERO in unit test (Tobin C. Harding)

Pull request description:

  We want to start enforcing MAX_MONEY as an invariant in the amount types. There are a few more steps we can do first to make that change easier to review.

ACKs for top commit:
  jamillambert:
    ACK 5d851f1c3e
  apoelstra:
    ACK 5d851f1c3e98d7d426e5897b2d734b77a299ccfb; successfully ran local tests

Tree-SHA512: 9e28b273d41fc143656e3a84736b6abe477fae5721b02bce7436551bd489cc235dc7e9fc68ffafa98f75a61065470ac514570a42bea94e90fedbb31f3cd61031
2025-03-12 12:14:14 +00:00
Jamil Lambert, PhD c1ea20b958
Increase test coverage in block.rs
Add tests to `primitive::block` module to increase test coverage.
2025-03-12 09:29:01 +00:00
Jamil Lambert, PhD 3e750d7ba1
Create test helper function to create a header
Move the header creation to the helper function so it can be used in
further tests.
2025-03-12 09:28:00 +00:00
kevincatty 61e7226299 chore: add missing backquotes
Signed-off-by: kevincatty <zhanshanmao@outlook.com>
2025-03-12 16:51:55 +08:00
Bruno Garcia c0e20dbf2e test: add coverage for ServiceFlags::P2P_V2 2025-03-11 18:24:16 -03:00
planetBoy 968406cb95
Update ecdsa-psbt.rs 2025-03-11 15:43:09 +01:00
merge-script c23402c330
Merge rust-bitcoin/rust-bitcoin#4228: docs: Update README to replace use of mutagen with cargo-mutants
199f57849a Remove references to cfg(mutate) from lint allow - no longer allowed (AM)
a65d1d8b95 docs: Update README to replace use of mutagen with cargo-mutants (AM)

Pull request description:

  Hey there!

  I am just getting up to speed with the project and in following the README discovered that there are still references to the previous mutation testing tool `mutagen`. I updated the README to refer to the new tool, `cargo-mutation`.

  I'm suggesting the user use the same command, `cargo mutants --in-place --no-shuffle`, as is run in the weekly CI workflow.

  I noticed that there are still references to the old `mutate` attribute in the following files. I removed these as well as per [feedback](https://github.com/rust-bitcoin/rust-bitcoin/pull/4228#issuecomment-2709407253).

  `primitives/Cargo.toml`:
  ```
  [lints.rust]
  unexpected_cfgs = { level = "deny", check-cfg = ['cfg(mutate)'] }
  ```

  and

  `bitcoin/Cargo.toml`:
  ```
  unexpected_cfgs = { level = "deny", check-cfg = ['cfg(bench)', 'cfg(fuzzing)', 'cfg(kani)', 'cfg(mutate)'] }
  ```

  Update to PR: removed incorrect understanding of logic in PR description as per [feedback](https://github.com/rust-bitcoin/rust-bitcoin/pull/4228#issuecomment-2709408598) and removed `cfg(mutate)` from above 2 files.

ACKs for top commit:
  tcharding:
    ACK 199f57849a
  apoelstra:
    ACK 199f57849acd9845902a8090ad6490a61ee03d24; successfully ran local tests

Tree-SHA512: e154c504aa5283f1da05d0120ea8dda97d1159389e692b0d57d7d864032ecb2b48c496054ede5500477367bc732dc34b0870f2709b8bd6e7b3f5c18a10f7a29e
2025-03-11 14:00:59 +00:00
merge-script 951a030bab
Merge rust-bitcoin/rust-bitcoin#4227: docs: The quotation marks are incorrect.
a824b79206 docs: The quotation marks are incorrect. (RiceChuan)

Pull request description:

  docs: The quotation marks are incorrect.

ACKs for top commit:
  tcharding:
    ACK a824b79206
  apoelstra:
    ACK a824b79206edb79fc990ff0022e10f4a5ebe4cb3; successfully ran local tests

Tree-SHA512: b5893fa564af72b31c0893236f29751702764e20e8f05576861e9a47b96c216066838bd48e38277ee1acbdb983a55edc64f9c2466826546f65d70ba309839927
2025-03-11 04:59:41 +00:00
merge-script 856ff4c34c
Merge rust-bitcoin/rust-bitcoin#4226: fix typos
08ced04d12 fix typos (wgyt)

Pull request description:

ACKs for top commit:
  tcharding:
    ACK 08ced04d12
  apoelstra:
    ACK 08ced04d124440d6b18d5815fd378f4f301f6d7d; successfully ran local tests

Tree-SHA512: 003fc80d2f2dd4e3b088e299776f811ab404314902314ee0136c08363328b2ddf72e7bace8b0440b58c4421922e99c9685b65cd5ef450433cc8b63023545fea9
2025-03-11 03:33:33 +00:00
ChrisCho-H e4513bf925 feat: add MAX_BLOCK_SERIALIZED_SIZE existing in core 2025-03-11 10:04:13 +09:00
Tobin C. Harding 5d851f1c3e
Remove deprecated amount methods
When we enforce the MAX_MONEY invariant these functions would require
the function signature changing - might as well just delete them.
2025-03-11 05:37:40 +11:00
Tobin C. Harding 76a2d70b28
Make mul weight by fee return NumOpResult
Now that we have the `NumOpResult<Amount>` type that is used to show a
math calculation returned a valid amount we can use it when multiplying
weight and fee rates thus removing panics.
2025-03-11 05:37:40 +11:00
Tobin C. Harding f9eb307953
Remove panic in dust value functions
Calculating the minimum non-dust fee currently panics if either the
script is really big or the dust fee rate is really big.

Harden the API by returning an `Option` instead of panicing.
2025-03-11 05:37:40 +11:00
Tobin C. Harding 13595fbe7d
Fix amount whole bitcoin constructors
I royally botched the recent effort to make const amount constructors
use a smaller type. I left in an  unnecessary panic and forgot to do
both of them.

Note these function return values will change again very shortly when we
start enforcing the MAX_MONEY invariant. However the 64 to 32 bit change
is unrelated to that and is easier to review if done separately.

Whole bitcoin can not in any sane environment be greater than 21,000,000
which fits in 32 bits so we can take a 32 bit integer in the whole
bitcoin constructors without loss of utility. Doing so removes the
potential panic.

This is a breaking API change. We elect not to deprecate because we want
to keep the same function names.
2025-03-11 05:37:40 +11:00
Tobin C. Harding ac71680202
Pick one - MAX or MAX_MONEY
Just use MAX everywhere in this codebase.

After discussion in PR consensus was to just use MAX throughout the
codebase.

ref: https://github.com/rust-bitcoin/rust-bitcoin/pull/4164#discussion_r1979441438
2025-03-11 05:37:39 +11:00
Tobin C. Harding 6d70c77cf9
Enforce newtype sanity rules for amount types
The unchecked-should-be-unsafe conversation is out of scope for this
patch. We want to bite off small chunks so the constructors are left as
they currently are - we are just doing the encapsulation here. This is
in preparation for enforcing the MAX_MONEY invariant which is not
currently enforced.

As per the sanity rules policy outline in:

 https://github.com/rust-bitcoin/rust-bitcoin/discussions/4090

For both amount types create a private `encapsulate` module that
consists of exactly the type and a single constructor and a single
getter.
2025-03-11 05:37:19 +11:00