Commit Graph

1904 Commits

Author SHA1 Message Date
merge-script 60e15b8007
Merge rust-bitcoin/rust-bitcoin#3194: priority: Prepare moving script types to `primitives`
8f2f4cbb3c Re-order optional dependencies (Tobin C. Harding)
95f2a8dab6 Do not access ScriptBuf inner from builder (Tobin C. Harding)
900af453ff Stop accessing inner ScriptBuf field when encoding (Tobin C. Harding)
8b82363d97 Use Script::as_bytes instead of inner when indexing (Tobin C. Harding)
b0675a4a4f Use Script::len instead of inner field (Tobin C. Harding)
374c6118dc Deprecate Script::fmt_asm and to_asm_str (Tobin C. Harding)

Pull request description:

  Move the `Script` and `ScriptBuf` types to `primitives`. There were still a few preparations required, things we had missed while creating the extension traits.

  Note also please, in the last patch, we enable `hex` from the `serder` feature. This is not the final state we want but like we did for `alloc` it is a step to reduce the size of the diff.

ACKs for top commit:
  Kixunil:
    ACK 8f2f4cbb3c
  apoelstra:
    ACK 8f2f4cbb3c successfully ran local tests

Tree-SHA512: 62a5f3c253ecb54d95c37fdc7eb955f3952909dc3bca20444b85c44665f54d5a0c48daf729bed0dd60ff3e9571b41deed039984c8b757b075ac6e136cacd17d7
2024-09-13 16:58:59 +00:00
Nadav Ivgi b593c886e3
Support GetKey where the Xpriv is a direct child of the looked up KeySource 2024-09-13 14:49:54 +03:00
Nadav Ivgi 055aa9d4dc
Refactor GetKey to take the KeyRequest by reference
To avoid cloning when looking it up in sets.
2024-09-13 14:49:54 +03:00
Nadav Ivgi d15c57bd1f
Refactor GetKey for sets to internally use Xpriv::get_key() 2024-09-13 14:49:46 +03:00
Nadav Ivgi d25c62bf45
Fix GetKey for sets to properly compare the fingerprint 2024-09-13 11:28:17 +03:00
merge-script 0c2737f25a
Merge rust-bitcoin/rust-bitcoin#3288: priority: Move txid hash types to `primitives`
0403e52ce3 Move the transaction hash types over to primitives (Tobin C. Harding)
7e454d756d Define extension traits for txid types (Tobin C. Harding)
832b726d03 Stop using all_zeros (Tobin C. Harding)
d69c241b5c Improve docs on associated consts (Tobin C. Harding)
68c9e28165 Do not use private constructor for txid hash types (Tobin C. Harding)
98328b5a7b Use as_byte_array to encode hash type (Tobin C. Harding)

Pull request description:

  Move the `Txid` and `Wtxid` hash wrapper types over to `primitives`. This introduces to `primitves` an unconditional dependency on `hashes`.

ACKs for top commit:
  Kixunil:
    ACK 0403e52ce3
  apoelstra:
    ACK 0403e52ce3 successfully ran local tests

Tree-SHA512: d14fa95bc12c2399d30d4d640b5a3fce625d51adf587a8037158f7d7e7b6288170b2d4418ca2cb68f612086ea0bdd0fae3b577f84f0d60627072fdb2217a6531
2024-09-13 03:31:00 +00:00
merge-script eacdd69688
Merge rust-bitcoin/rust-bitcoin#3344: Deprecate `OutPoint::new` constructor
e064686397 Deprecate OutPoint::new constructor (Tobin C. Harding)

Pull request description:

  The `OutPoint` type has two public fields, providing a `new` constructor that just sets these two fields adds no value.

  Done after discussion in #3340 as part of `primitives` work.

ACKs for top commit:
  Kixunil:
    ACK e064686397
  apoelstra:
    ACK e064686397 successfully ran local tests

Tree-SHA512: d80cac85093946b3678883f4e3ad7fd2052d858dbd3fab4127916b0eb6153999d30827c84ccf8c6e4412fbc3842bd127a2e4d3ca0248d2307d0bca467a2555ce
2024-09-12 17:43:48 +00:00
merge-script e027be6457
Merge rust-bitcoin/rust-bitcoin#3350: Stop using deprecated `OutPoint` functions
f811e0adb6 Stop using deprecated OutPoint functions (Tobin C. Harding)

Pull request description:

  Either our CI is failing us or `deprecated` does not work as expected, either way we should not be using the `OutPoint::null()` or `is_null` functions any more because we deprecated them already.

ACKs for top commit:
  Kixunil:
    ACK f811e0adb6
  apoelstra:
    ACK f811e0adb6 successfully ran local tests

Tree-SHA512: 64e75601ce8062da78bbd9aea97792e35c728aa31255348413fe9b57ee585974370d3f59b5467d7e4a65dc05d2718aea18bb381e128c8410fbfde4a851006416
2024-09-12 16:32:50 +00:00
Tobin C. Harding e064686397
Deprecate OutPoint::new constructor
The `OutPoint` type has two public fields, providing a `new` constructor
that just sets these two fields adds no value.
2024-09-12 11:44:27 +10:00
Tobin C. Harding 0403e52ce3
Move the transaction hash types over to primitives
Move the `Txid` and `Wtxid` hash wrapper types over to `primitives`.
This introduces to `primitves` an unconditional dependency on
`hashes`.
2024-09-11 11:02:32 +10:00
Tobin C. Harding 8f2f4cbb3c
Re-order optional dependencies
The optional dependencies are ordered and separated by whitspace in a
manner that may not be obvious (or even have a reason).

Some of this is because since use of `?` deps changed name.

Put all the optional deps together in alphabetic order.
2024-09-11 10:50:18 +10:00
Tobin C. Harding 95f2a8dab6
Do not access ScriptBuf inner from builder
The `Builder` is staying in `bitcoin` while the `ScriptBuf` is moving to
`primitives`, so we cannot access the inner field of `ScriptBuf`.

Use the new `as_byte_vec` hack to mutate the inner `ScriptBuf` field.
2024-09-11 10:50:18 +10:00
Tobin C. Harding 900af453ff
Stop accessing inner ScriptBuf field when encoding
In preparation for moving the `ScriptBuf` type to `primitives` stop
accessing the inner field when encoding/decoding, use `as_script`
and `from_bytes` instead.
2024-09-11 10:50:18 +10:00
Tobin C. Harding 8b82363d97
Use Script::as_bytes instead of inner when indexing
In preparation for moving the `Script` type to `primitives` stop
accessing the inner field before doing slice operations, use `as_bytes`
to first get at the slice.
2024-09-11 10:50:18 +10:00
Tobin C. Harding b0675a4a4f
Use Script::len instead of inner field
In preparation for moving the `Script` type to `primitives` stop
accessing the inner field to get the length, call `len` directly.
2024-09-11 10:50:18 +10:00
Tobin C. Harding 374c6118dc
Deprecate Script::fmt_asm and to_asm_str
The `Script::fmt_asm` function is a legacy from days yore before
`Display` printed asm. We no longer need it.

Deprecate `Script::fmt_asm` and use the private `bytes_to_asm_fmt` or
`Display` impls.
2024-09-11 10:50:17 +10:00
Tobin C. Harding 7e454d756d
Define extension traits for txid types
Use the `define_extension_trait` macro to define two extension traits
for the two txid types. Each trait holds the deprecated `all_zeros`
function. There are no users of this trait in the code base.
2024-09-11 10:44:29 +10:00
Tobin C. Harding 832b726d03
Stop using all_zeros
Recently we deprecated the `all_zeros` functions on `Wtxid` and
`Txid` but for some reason our usage of them is not triggering a lint
warning.

Note please that this changes logic slightly, for example by using an
array of `0xFF` bytes instead of all zeros. Done in an effort to make it
even more obvious that the value is a dummy value and not mix it up with
the all zeros being used for coinbase thing.
2024-09-11 10:39:49 +10:00
Tobin C. Harding d69c241b5c
Improve docs on associated consts
In #3308 we added associated consts to the `Txid`, `Wtxid`, and
`OutPoint` types. During review and afterwards we realised the docs
could do with improving. Since we now want to move the types we should
do this first.

Close: #3331
2024-09-11 10:34:45 +10:00
Tobin C. Harding 68c9e28165
Do not use private constructor for txid hash types
In preparation for moving the txid hash types to `primitives` stop using
private constructors and cast the hash types as is typical.
2024-09-11 10:34:44 +10:00
Tobin C. Harding 98328b5a7b
Use as_byte_array to encode hash type
Instead of accessing the inner type of a hash wrapper type when
consensus encoding we can call `as_byte_array()`.

Done in preparation for moving `Txid` and `Wtxid` to `primitives`.

Internal change only.
2024-09-11 10:34:44 +10:00
merge-script 060ad58620
Merge rust-bitcoin/rust-bitcoin#3259: priority: Introduce and use a new `compact_size` module
d65de7c7de Introduce and use new compact_size module (Tobin C. Harding)

Pull request description:

  We would like to move the witness module to `primitives` but there is a bunch of usage of `VarInt`.

  Introduce a module that does the encoding and decoding instead, note that while the functionality is internal decoding returns an error which may one day end up in the public API. So put the module in `primitives` and make it public.

  Adds the module to `primitives`, adds a public `MAX_ENCODABLE_SIZE` variable that is commented with an issue link.

  https://github.com/rust-bitcoin/rust-bitcoin/issues/3264

ACKs for top commit:
  apoelstra:
    ACK d65de7c7de successfully ran local tests
  Kixunil:
    ACK d65de7c7de

Tree-SHA512: d9483c29b2b324e27460564a23f4639dde4037e6e773f4356216b02ebdea893a6361c342002b8e93a54de47b71ac69369431554f8cd0a2522fc451bf8493c81c
2024-09-10 13:27:24 +00:00
Tobin C. Harding f811e0adb6
Stop using deprecated OutPoint functions
Either our CI is failing us or `deprecated` does not work as expected,
either way we should not be using the `OutPoint::null()` or `is_null`
functions any more because we deprecated them already.
2024-09-10 09:32:06 +10:00
merge-script 08710d81a6
Merge rust-bitcoin/rust-bitcoin#3324: Add tests for witness_program
733505148c Add tests for witness_program (Shing Him Ng)

Pull request description:

  Add tests for witness_program

ACKs for top commit:
  tcharding:
    ACK 733505148c
  Kixunil:
    ACK 733505148c
  apoelstra:
    ACK 733505148c successfully ran local tests

Tree-SHA512: c1ee82edf22c7b39bc110d03836ba5ebfa785a63185a75c1a61781180ff907c1ea0c491c963629450f360152766845dacedccc6cf56bc3d8c607e66281427dd3
2024-09-09 20:28:24 +00:00
merge-script 1aed58a6d6
Merge rust-bitcoin/rust-bitcoin#3128: hashes: Remove `io` feature
ae93e226e3 Remove hashes io feature (Tobin C. Harding)

Pull request description:

  Currently we only get `std::io::Write` impls when the `bitcoin-io` dependency is used. This is overly restrictive, it would be nice to have `std::io::Write` imlps even without the `bitcoin-io` dependency.

  Copy the logic out of the `bitcoin_io::impl_write` macro into `hashes` but feature gate it differently.

  Call the new macro inside `hash_type` (and in `hmac`), remove the `impls` module, and move the tests to the integration test directory.

  Remove the `io` feature from `hashes`, now if users enable `std` they get `std::io::Write` impls and if they enable `bitcoin-io` they get `bitcoin_io::Write` impls as well.

ACKs for top commit:
  Kixunil:
    ACK ae93e226e3
  apoelstra:
    ACK ae93e226e3 successfully ran local tests

Tree-SHA512: d47c9c060750e8a024c46cbf7afe8d0d1245fa1f5e575f36b3a11e2460d3620ad9def1a6331dafe77d46affc99b043ec9679e619ce8ddfa32436a5826ece09e4
2024-09-09 19:28:51 +00:00
merge-script 9797e50ab5
Merge rust-bitcoin/rust-bitcoin#3310: Shoosh linter in bench build
fe46225ed0 Allow unused imports when running bench code (Tobin C. Harding)
eb67e873e0 Allow unused variables in release mode (Tobin C. Harding)

Pull request description:

  Two patches to clear the million warnings when running the bench code.

ACKs for top commit:
  apoelstra:
    ACK fe46225ed0 successfully ran local tests; though in the first commit you could also use `cfg_attr` FWIW
  Kixunil:
    ACK fe46225ed0

Tree-SHA512: 3f705e0441d8c0e41e9ceb5473572810ff2513f7e5531c1b7889418a3a85ac8622e50e271c7a3b5c386fb3f5629b85d4bd79739c4a02b51d58da86890721d8d2
2024-09-09 17:56:45 +00:00
merge-script cfe6c0a999
Merge rust-bitcoin/rust-bitcoin#3293: priority: Re-write (and re-name) `read_uint_iter`
0f897f80a5 Re-write (and re-name) read_uint_iter (Tobin C. Harding)

Pull request description:

  The `UintError` type (returned by `read_uint_iter`) is not that useful because one variant is unreachable. Re-write the function by doing:n

  - Re-write the function to reduce the error cases returned.
  - Re-name it to `read_push_data_len`
  - Move it to `internals`
  - Use `PushDataLenLen` enum instead of an int parameter

ACKs for top commit:
  apoelstra:
    ACK 0f897f80a5 successfully ran local tests; lol so much better than the old code
  Kixunil:
    ACK 0f897f80a5

Tree-SHA512: 095017a32c2d5bb2268cb1a059d0022e122faf8b41295f14970e7968374dd1c35c3b95357aba5aabaa17843439aebc237000009015ea9b8bc58ab1b337e8e1bc
2024-09-09 16:37:30 +00:00
merge-script 929eaf23d4
Merge rust-bitcoin/rust-bitcoin#3308: priority: Add coinbase associated consts
ea2efc155e Add coinbase associated consts (Tobin C. Harding)

Pull request description:

  Currently we have `all_zeros` functions and `null` functions but we can do better.

  Add associated consts and improve the names to better describe what these dummy zero hashes are used for.

  Deprecate related functions.

ACKs for top commit:
  Kixunil:
    ACK ea2efc155e
  apoelstra:
    ACK ea2efc155e successfully ran local tests

Tree-SHA512: bc7e840622a558bc46798e3606452ad24c16b7d23e7fe7a68fdf8a719326eb9d6d872ec1647620506f1de76b8086ae36cce0e1399e55e50bbd794efb8b4dda47
2024-09-09 16:01:43 +00:00
Tobin C. Harding ae93e226e3
Remove hashes io feature
Currently we only get `std::io::Write` impls when the `bitcoin-io`
dependency is used. This is overly restrictive, it would be nice to have
`std::io::Write` imlps even without the `bitcoin-io` dependency.

Copy the logic out of the `bitcoin_io::impl_write` macro into `hashes`
but feature gate it differently.

Call the new macro inside `hash_type` (and in `hmac`), remove the
`impls` module, and move the tests to the integration test directory.

Remove the `io` feature from `hashes`, now if users enable `std` they
get `std::io::Write` impls and if they enable `bitcoin-io` they get
`bitcoin_io::Write` impls as well.
2024-09-09 06:37:49 +10:00
Tobin C. Harding 0f897f80a5
Re-write (and re-name) read_uint_iter
The `UintError` type (returned by `read_uint_iter`) is not that useful
because one variant is unreachable. Re-write the function by doing:n

- Re-write the function to reduce the error cases returned.
- Re-name it to `read_push_data_len`
- Move it to `internals`
- Use `PushDataLenLen` enum instead of an int parameter
2024-09-09 06:31:39 +10:00
Shing Him Ng 733505148c Add tests for witness_program 2024-09-08 13:58:30 -05:00
Fmt Bot 9a5ba9b6df 2024-09-08 automated rustfmt nightly 2024-09-08 01:17:12 +00:00
merge-script 9afeb711e4
Merge rust-bitcoin/rust-bitcoin#3301: Deprecate `from_slice` methods in favor of arrays
c00afe8d52 Change MessageSignatureError to secp256k1::Error (Jamil Lambert, PhD)
a20d0bc4eb Deprecate `from_slice()` in sha256.rs (Jamil Lambert, PhD)
089043546f Deprecate `from_slice` methods in favor of arrays (Jamil Lambert, PhD)

Pull request description:

  As brought up in issue #3102 support for Rust arrays is now much better so slice-accepting methods that require a fixed length can be replaced with a method that accepts an array.

  `from_slice()` methods that require a fixed length have been deprecated and where needed a `from_byte_array()` method created that accepts an array.

  There are still `from_slice` methods that rely on changes to external crates before they can be changed to arrays.

ACKs for top commit:
  apoelstra:
    ACK c00afe8d52 successfully ran local tests
  tcharding:
    ACK c00afe8d52
  Kixunil:
    ACK c00afe8d52

Tree-SHA512: c505b78d5ca57e7e1004df6761ac6760d5d9b63c93edc6ac1f9adf047bc67011883575f835b06f6d35d7f6c2b6a4c6c7f0a82a3f0e293bfb4ef58123b75d3809
2024-09-06 22:33:19 +00:00
merge-script c63695ac1e
Merge rust-bitcoin/rust-bitcoin#3286: Add additional docs to Witness
333c8ab297 Add additional docs to Witness (Tobin C. Harding)

Pull request description:

  The `Witness` struct is non-trivial, in particular it is not immediately obvious where and when the compact size encode value for each witness element is stored.

  Make an effort to improve the docs on `Witness` in relation to the compact size encoded length of each witness element.

ACKs for top commit:
  apoelstra:
    ACK 333c8ab297 successfully ran local tests
  Kixunil:
    ACK 333c8ab297

Tree-SHA512: 1c61a9ad071c035d5ad2e54446120d29ebf8cc4a779c96f04eda825890687dcbd53accc17522f57ef4ffb226eb1d85c6a3a115f27bebcfc7ad3c677033a8a414
2024-09-06 14:28:04 +00:00
Jamil Lambert, PhD c00afe8d52
Change MessageSignatureError to secp256k1::Error
`from_byte_array` cannot error due to InvalidLength so the returned
MessageSignatureError has been changed to return a secp256k1::Error,
which is the only error type returned by the function.
2024-09-06 12:49:11 +01:00
Jamil Lambert, PhD 089043546f
Deprecate `from_slice` methods in favor of arrays
Support for Rust arrays is now much better so slice-accepting methods
that require a fixed length can be replaced with a method that accepts
an array.

`from_slice()` has been deprecated and replaced with `from_byte_array()`
2024-09-06 12:33:51 +01:00
Tobin C. Harding ea2efc155e
Add coinbase associated consts
Currently we have `all_zeros` functions and `null` functions but we can
do better.

Add associated consts and improve the names to better describe what
these dummy zero hashes are used for.

Deprecate related functions.
2024-09-06 09:04:56 +10:00
Tobin C. Harding fe46225ed0
Allow unused imports when running bench code
Running the bench code results in a million warnings, instead of
solving these just allow unused imports as we do for fuzz code.
2024-09-05 12:46:13 +10:00
Tobin C. Harding eb67e873e0
Allow unused variables in release mode
In release mode we have a few unused variable warnings, lets just
allow them.

Found when running bench code, interestingly `cargo bench` must build
in release mode.
2024-09-05 12:46:13 +10:00
Tobin C. Harding d65de7c7de
Introduce and use new compact_size module
We would like to move the witness module to `primitives` but there is
a bunch of usage of `VarInt`.

Introduce a module that does the encoding and decoding instead, this
code is internal so put it in `internals`.

Note we add an unused public `MAX_ENCODABLE_SIZE` variable that is
commented with an issue link. Done like this because its quite
important that we see to it and it makes it clear that we are not and
we know about it.

 https://github.com/rust-bitcoin/rust-bitcoin/issues/3264
2024-09-05 09:49:56 +10:00
Tobin C. Harding 333c8ab297
Add additional docs to Witness
The `Witness` struct is non-trivial, in particular it is not immediately
obvious where and when the compact size encode value for each witness
element is stored.

Make an effort to improve the docs on `Witness` in relation to the
compact size encoded length of each witness element.
2024-09-05 07:42:41 +10:00
merge-script f6287fb445
Merge rust-bitcoin/rust-bitcoin#3287: Move `transaction::Version` to `primitives`
c48d9d6523 Move transaction::Version to primitives (Tobin C. Harding)
f490222068 Introduce the VersionExt trait (Tobin C. Harding)
fb89974b82 Run the formatter (Tobin C. Harding)
bb3a3ecbaa Introduce temporary module for Version (Tobin C. Harding)
1fde868f51 Separate Version impl blocks (Tobin C. Harding)

Pull request description:

  As per title, in tiny small chunks, move the `transaction::Version` over to `primitives`. Only the type, its associated consts, and its `Display` impl are moved. The two methods are left in an extension trait.

  Was originally attempted in #3253

ACKs for top commit:
  Kixunil:
    ACK c48d9d6523
  apoelstra:
    ACK c48d9d6523 successfully ran local tests

Tree-SHA512: 83415cf0762dca5c263deb743734fc7abede804a6daac31df3d0101b51c6261e6d54452eb744727ae680cacce9e4ef726a6fa253d86c4e7a5d8ec789b137566c
2024-09-04 01:21:43 +00:00
Tobin C. Harding c48d9d6523
Move transaction::Version to primitives
We would like to move the `Transaction` type to `primitives`, as a step
towards this move the `transaction::Version` and its trait imps (just
`Display`) over there.
2024-09-03 11:01:29 +10:00
Tobin C. Harding f490222068
Introduce the VersionExt trait
In preparation for moving the `transaction::Version` type to
`primitives`; add a `VersionExt` trait using our macro.
2024-09-03 10:57:58 +10:00
Tobin C. Harding fb89974b82
Run the formatter
Run `just fmt`. No manual changes.
2024-09-03 10:56:59 +10:00
Tobin C. Harding bb3a3ecbaa
Introduce temporary module for Version
In preparation for using the formatter to indent add a temporary module.
Done as part of adding an extension trait.
2024-09-03 10:56:06 +10:00
Tobin C. Harding 1fde868f51
Separate Version impl blocks
In preparation for adding an extension trait; separate the
`transaction::Version` impl blocks into stuff that will stay here and
stuff that will go to `primitives`.

Refactor only, no logic changes.
2024-09-03 10:54:48 +10:00
merge-script 3b057ad2f5
Merge rust-bitcoin/rust-bitcoin#3150: Create a macro that implements `to_hex` for types that have `core::fmt::LowerHex` implemented
30bb93c676 Implement impl_to_hex_from_lower_hex macro for types that implement fmt::LowerHex (Shing Him Ng)

Pull request description:

  Created a macro that implements `to_hex` for types that currently have `core::fmt::LowerHex` and called it on types that have `core::fmt::LowerHex` implemented. I put the macro in the `internals` crate since there are types across the whole project that can potentially use this.

  Resolves #2869

ACKs for top commit:
  Kixunil:
    ACK 30bb93c676
  apoelstra:
    ACK 30bb93c676 successfully ran local tests

Tree-SHA512: d3ebc7b5c0c23f1a8f8eef4379c1b475e8c23845e18ce514cb1e98eb63fc4f215e6bc4425f97c7303053df13374ef931ae9d9373badd7ca1975a55b0d00d0e40
2024-09-02 21:18:44 +00:00
merge-script 3bbe821ce5
Merge rust-bitcoin/rust-bitcoin#3268: Fix clippy rustdocs warnings
b6371b5801 Fix clippy rustdocs warnings (Tobin C. Harding)

Pull request description:

  A new nightly version (`nightly-2024-08-28`) introduces a few warnings because of our rustdocs. These are valid warnings and should be fixed, thanks `clippy` team.

  (The `bip152` change is a bit sloppy, open to suggestions.)

ACKs for top commit:
  apoelstra:
    ACK b6371b5801 successfully ran local tests
  Kixunil:
    ACK b6371b5801

Tree-SHA512: 503fb9d48772b74a5acdb26c0f77a85c52323c03360f983204fccee0f28bedeff142237b067caa1ce6ea04ea9842cc493e0d06dc141ca00a98151fa002b62392
2024-09-02 14:20:44 +00:00
merge-script 6a06c023e0
Merge rust-bitcoin/rust-bitcoin#3276: fix: deprecate wrong and unused max script num
345d3daa72 fix: deprecate wrong and unused max script num (ChrisCho-H)

Pull request description:

  ~~Script number can be up to 2^39 - 1 to encode locktime.~~
  ~~If it's only for the integer operation besides locktime, it must be 2^31 - 1, not 2^31.~~

  I agree with apoelstra  opinion to deprecate this value.

ACKs for top commit:
  apoelstra:
    ACK 345d3daa72 successfully ran local tests
  Kixunil:
    ACK 345d3daa72

Tree-SHA512: df4205415634d8db1412f16a75d1dbc110ed69930cefa085bdaa268a7fcaf47776dd1d8ed6965e6bbb476825b5f80e5c00bb375730ad102bae8868abe5894068
2024-09-02 00:01:32 +00:00
ChrisCho-H 345d3daa72 fix: deprecate wrong and unused max script num 2024-09-01 22:14:39 +09:00
merge-script 0a3f5330a8
Merge rust-bitcoin/rust-bitcoin#3279: Automated nightly rustfmt (2024-09-01)
fa71b0e044 2024-09-01 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 fa71b0e044 successfully ran local tests; a bit big this week

Tree-SHA512: 875e8d54a06a22ccbef690a21f9d48a0acc1e6ea073a2d16632dd7ce63400cc7f2522339b7cb808653dade407517cd03d4fece4c8dec24abacf5303418aeaa75
2024-09-01 13:03:01 +00:00
Shing Him Ng 30bb93c676 Implement impl_to_hex_from_lower_hex macro for types that implement fmt::LowerHex 2024-08-31 22:41:40 -05:00
merge-script d1e7116321
Merge rust-bitcoin/rust-bitcoin#3278: Show compressed public key in Debug for CompressedPublicKey
9db6234ea9 Show compressed public key in Debug for CompressedPublicKey (Jiri Jakes)

Pull request description:

  Currently `CompressedPublicKey` debug produces output of form:

  ```
  CompressedPublicKey(PublicKey(2f8b18dc0adcb73d75f7934d9523ea7347083e41c48115398cb37e295a0a6ffe86e0bf8b1ef65888c880c8d8813a30e69e466380cbe2daec18f3ed1e7a553ff2))
  ```

  Although it shows real internal structure together with inner uncompressed public key, it is not too helpful for the purpose of debugging _compressed_ public key.

  After this patch, `Debug` output will be equal to `Display` (it, in fact, delegates rendering to `Display`), prepended by the name of the struct:

  ```
  CompressedPublicKey(02fe6f0a5a297eb38c391581c4413e084773ea23954d93f7753db7dc0adc188b2f)
  ```

ACKs for top commit:
  Kixunil:
    ACK 9db6234ea9 unless other maintainers agree to drop the struct name.
  apoelstra:
    ACK 9db6234ea9 successfully ran local tests; we should keep the struct name since it is canonical for Debug output

Tree-SHA512: e2626678a4144357d3ff4ddd888459ae1283ea50bc7c8ef86deb9902d7d543de79109ac42883e5538f7e2f6a29426224bb43eb44a34f366821e47a9aca563753
2024-09-01 01:30:30 +00:00
Fmt Bot fa71b0e044 2024-09-01 automated rustfmt nightly 2024-09-01 01:22:04 +00:00
merge-script 753961fdb8
Merge rust-bitcoin/rust-bitcoin#3215: Improve const_assert
3c7c8c44b6 Improve const_assert (Tobin C. Harding)

Pull request description:

  Now that we can panic in const context we can improve the `const_assert` macro by adding a message string.

  Original idea by Kix:

    https://github.com/rust-bitcoin/rust-bitcoin/pull/2972#discussion_r1726328228

ACKs for top commit:
  Kixunil:
    ACK 3c7c8c44b6 in the sense that it does what it's supposed to with the only tiny issue being that the `bool` looks weird but not broken in any other way I can think of.
  apoelstra:
    ACK 3c7c8c44b6 successfully ran local tests

Tree-SHA512: 5ff721c0056f87d42c934818da6f780cd945f235291eb4b044752d67405a74f992d7f85853fec129e794ec3fcda1f319cc40daabc6a349d21bbdc977640d2572
2024-08-31 20:00:28 +00:00
merge-script 2a54c1c1f2
Merge rust-bitcoin/rust-bitcoin#3271: Move import inside feature gate
a184066660 Move import inside feature gate (Tobin C. Harding)

Pull request description:

  The `String` type is only used if the `serde` feature is enabled, move the import statement inside the already feature gated block.

ACKs for top commit:
  apoelstra:
    ACK a184066660 successfully ran local tests; sure
  Kixunil:
    ACK a184066660

Tree-SHA512: 688adb1e4489b0242856ac36ed9cf3503b147b84954cf1e6fd34b5e708ed6c1dd92da91e739243face1c1b4e4c8b19ce88e215117bef2a7af2e732859a6e108a
2024-08-31 18:22:51 +00:00
Jiri Jakes 9db6234ea9
Show compressed public key in Debug for CompressedPublicKey 2024-08-31 22:41:12 +08:00
merge-script 0d9e8f8c99
Merge rust-bitcoin/rust-bitcoin#3204: Do many cleanups (and bug fix)
dae42bef9d do not enable bitcoin-io by default (Antoni Spaanderman)
a14cdaf859 don't enable std by default when testing (Antoni Spaanderman)
e83830dcfc use slice instead of array to not have to hardcode the length (Antoni Spaanderman)
55749d6f61 use `hash.to_byte_array` to check equality with `test.output` (Antoni Spaanderman)
969864e3b0 use fixed size array if possible, otherwise `&'static [u8]` (Antoni Spaanderman)
28ccf70fa6 remove unnecesarry borrow operator (`&`) (Antoni Spaanderman)
fa3a3afd02 remove unnecessary slicing (Antoni Spaanderman)
22e42ab86c fix test code being unnecessarily feature gated (Antoni Spaanderman)

Pull request description:

  - remove 2 unnecessary cfg attributes from tests left over from  #3167 (it made them not dependent on `alloc` anymore)
  - simplify assertion logic by removing unnecessary conversions before comparing
  - make tests `no_std` compatible by adding imports to alloc or std
  - feature gate tests behind the `alloc` feature if they use anything from the alloc crate (like the `format!` macro)
  - `schemars` feature enables `alloc` because (for example) its trait wants implementations to return `String`
  - fix `bitcoin-io` always enabling when `std` is enabled (only useful if people depend on `hashes` only, `bitcoin` depends on `bitcoin-io` already)

ACKs for top commit:
  tcharding:
    ACK dae42bef9d
  Kixunil:
    ACK dae42bef9d
  apoelstra:
    ACK dae42bef9d successfully ran local tests

Tree-SHA512: 622fd4963ef21530a98af89bcfc71abe8723aac12d363ab88d9bd30dcf2f75392711bec10e2901fab5f1a30e11897d1aae36e22892738aa1e5670166f91fddd4
2024-08-29 21:20:10 +00:00
Tobin C. Harding 3c7c8c44b6
Improve const_assert
Now that we can panic in const context we can improve the `const_assert`
macro by adding a message string.

Original idea by Kix:

  https://github.com/rust-bitcoin/rust-bitcoin/pull/2972#discussion_r1726328228
2024-08-30 06:33:31 +10:00
Tobin C. Harding b6371b5801
Fix clippy rustdocs warnings
A new nightly version (`nightly-2024-08-28`) introduces a few warnings
because of our rustdocs. These are valid warnings and should be fixed,
thanks `clippy` team.

(The `bip152` change is a bit sloppy, open to suggestions.)
2024-08-30 05:47:31 +10:00
Tobin C. Harding a184066660
Move import inside feature gate
The `String` type is only used if the `serde` feature is enabled, move
the import statement inside the already feature gated block.
2024-08-30 05:25:51 +10:00
merge-script 98252f36df
Merge rust-bitcoin/rust-bitcoin#3255: fix: re-implement `Psbt` (de)serialization from/to readers/writers
cf129ad314 fix: re-implement (de)serialization from/to readers/writers (elsirion)

Pull request description:

  Fixes #3250.

  The serialization is less than ideal and still allocates a lot. I can understand not wanting to (ab)use the consensus encoding traits, but they have a pretty good interface, copying it and creating some `EncodePsbt` and `DecodePsbt` traits with similar interfaces would have been nice imo.

ACKs for top commit:
  Kixunil:
    ACK cf129ad314
  apoelstra:
    ACK cf129ad314 successfully ran local tests; LGTM -- I believe this is non-breaking, as does cargo-semver-checks, so we can backport this to 0.32

Tree-SHA512: d7f218164d772db3a9fb4436953c3b5fd3677b92078d0843233197629df7d852d80615a3ff38c5b70771381ba1aeb30defdc98ee63653e570bb75dc553400cad
2024-08-28 22:26:07 +00:00
Jamil Lambert, PhD 9fce57b738
Change T::from_str(s) to s.parse::<T>() in tests
`s.parse` is more idiomatic and produces more helpful error messages.

This has been changed repo wide in tests.
2024-08-28 16:13:03 +01:00
Jamil Lambert, PhD 4ad86148c7
Change Address::from_str(s) to s.parse
`s.parse` is more idiomatic and produces more helpful error messages.

This has been changed for parsing a string as an `Address`.
2024-08-28 13:50:43 +01:00
Jamil Lambert, PhD 64e668f99e
Change from_str(s) to parse::<T>() in Examples
`s.parse` is more idiomatic and produces more helpful error messages.

This has been changed in examples.
2024-08-28 13:50:43 +01:00
Jamil Lambert, PhD c835bb9eab
Change T::from_str(s) to s.parse::<T>() in docs
`s.parse` is more idiomatic and produces more helpful error messages.

This has been changed repo wide in docs.
2024-08-28 13:50:42 +01:00
merge-script e048b7b003
Merge rust-bitcoin/rust-bitcoin#3256: Change `T::from_str(s)` to `s.parse::<T>()`
a76d76eca1 Change `T::from_str(s)` to `s.parse::<T>()` (Jamil Lambert, PhD)

Pull request description:

  As mentioned in issue #3234 `s.parse::<T>()` is more idiomatic and produces more helpful error messages.

  This has been changed in the main codebase, not including examples, rustdocs, and in the `test` modules.

  `use std::str::FromStr;` has been removed where this change makes it unnecessary.

  To close the issue it may also need to be changed in the examples and the `test` modules and `contributing.md` updated.

ACKs for top commit:
  Kixunil:
    ACK a76d76eca1
  storopoli:
    ACK a76d76eca1
  tcharding:
    ACK a76d76eca1

Tree-SHA512: 18be389579b5c2d0ba567dfb02b9c8d71c108a749ec5168c60a50e7af9d7f498e364c8f4c0ce1698d960e7d146486899cd10214ebc9c96708ed158a04dfff425
2024-08-28 12:47:16 +00:00
Jamil Lambert, PhD a76d76eca1
Change `T::from_str(s)` to `s.parse::<T>()`
`s.parse` is more idiomatic and produces more helpful error messages.

This has been changed repo wide in the main codebase, not including
examples, rustdocs, and in the test module.

`use std::str::FromStr;` has been removed where this change makes
it unnecessary.
2024-08-27 17:31:00 +01:00
elsirion cf129ad314
fix: re-implement (de)serialization from/to readers/writers 2024-08-27 11:49:34 +02:00
Tobin C. Harding b61adf7ca4
Introduce TxOutExt trait
In preparation for moving the `TxOut` type over to `primitives` ad an
extension trait as is becoming customary.
2024-08-27 18:44:00 +10:00
Tobin C. Harding 8b089ffe40
Run the formatter
Run `cargo +nightly fmt`, no manual changes.
2024-08-27 17:57:44 +10:00
Tobin C. Harding 02c7d504fa
Add tmp module around TxOut impl block
The two `TxOut` fields are public and there are no construtors or
getters to move, only the associated const `NULL`.

Add a tmp module around the big impl block so we can trick the formatter
into indenting before we add the extension trait.
2024-08-27 17:57:44 +10:00
Tobin C. Harding fa946796eb
Create a separate TxOut impl block
Everything except the associated const is going to stay here in
`bitcoin` when we move `TxOut` to `primitives`.
2024-08-27 17:57:41 +10:00
Antoni Spaanderman e83830dcfc
use slice instead of array to not have to hardcode the length 2024-08-26 17:22:09 +02:00
merge-script 1058cbb9f8
Merge rust-bitcoin/rust-bitcoin#3233: Automated nightly rustfmt (2024-08-25)
fbf7f41875 2024-08-25 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 fbf7f41875 successfully ran local tests

Tree-SHA512: 2612a860db6e900558d840d2bd9f1a1f6d7d5fff823b2686613aecad84268c2d0f9cb024d023f91d010652aecf0b7b7e36eb00c930a601121e61a30bfc5ddd35
2024-08-25 14:21:11 +00:00
merge-script 51af258eaa
Merge rust-bitcoin/rust-bitcoin#3015: Add Arbitrary
3e034d5ede Add Arbitrary dependency (yancy)

Pull request description:

  Adds an example draft showing what is needed to use Arbitrary for coin selection.

  Shot out to how nice Arbitrary is for fuzzing a target by taking unstructured randomness and creating structured rust-bitcoin types for fuzzing.  Is there a way we could add this to rust-bitcoin for structuring the fuzz data needed?

  This is then the example to fuzz test a SRD algo (after applying this PR to rust-bitcoin) using rust-bitcoin types :)

  ```
  #![no_main]

  use arbitrary::Arbitrary;
  use bitcoin::{Amount, FeeRate};
  use bitcoin_coin_selection::{select_coins_srd, WeightedUtxo};
  use libfuzzer_sys::fuzz_target;
  use rand::thread_rng;

  #[derive(Arbitrary, Debug)]
  pub struct Params {
      target: Amount,
      fee_rate: FeeRate,
      weighted_utxos: Vec<WeightedUtxo>,
  }

  fuzz_target!(|params: Params| {
      let Params { target: t, fee_rate: f, weighted_utxos: wu } = params;
      select_coins_srd(t, f, &wu, &mut thread_rng());
  });
  ```

ACKs for top commit:
  tcharding:
    ACK 3e034d5ede
  Kixunil:
    ACK 3e034d5ede
  apoelstra:
    ACK 3e034d5ede successfully ran local tests

Tree-SHA512: accd565815de3b37730d2ff12a24fcfc84e52ad357e5c940b1500a1e0bb17f4ff5fd6e52d31e8e96bb5290ee4fa050cfd2a9bbd6bbae13fc378f43093b64177f
2024-08-25 13:16:49 +00:00
Fmt Bot fbf7f41875 2024-08-25 automated rustfmt nightly 2024-08-25 01:14:09 +00:00
merge-script 18bdd92d34
Merge rust-bitcoin/rust-bitcoin#3216: ecdsa: Improve error types
9fb5edb39e ecdsa: Improve error types (Tobin C. Harding)

Pull request description:

  There are a couple of issues around the ECDSA signature decoding / parsing code. We have duplicate code in `from_str` and `from_slice` and both use the same error type even though it is impossible to get a hex error in `from_slice`.

  Create two errors:

  - A `DecodeError` returned by `from_slice`
  - A `FromStrError` that has a decode variant and a hex variant

  Call through to `from_slice` after parsing hex into a byte vector.

  Removes an instance of `unreachable!`.

  Fix: #1193

ACKs for top commit:
  Kixunil:
    ACK 9fb5edb39e
  apoelstra:
    ACK 9fb5edb39e successfully ran local tests

Tree-SHA512: 3b3ae31887d603f1739d261b491b99f7847987f94dbbfefb9aa84d4250736eba2d007d28746bbb064946d3055e4cca01510677bf2cdbb11bbf83d7388dbd2620
2024-08-24 17:52:08 +00:00
merge-script 837fc9c9c2
Merge rust-bitcoin/rust-bitcoin#2972: Use index size rather than pointer size to enforce convertibility of `u32` to `usize`
c427d8b213 bitcoin: Compile time assert on index size (Tobin C. Harding)
49a6acc1a0 internals: Remove double parenthesis in const_assert (Tobin C. Harding)
2300b285ef units: Remove compile time pointer width check (Tobin C. Harding)

Pull request description:

  3 patches in preparation for other size related work, this PR does not touch the `ToU64` issue which will be handled separately.

  - Patch 1: Don't check pointer width in `units` because its not consensus code
  - Patch 2: Modify internal macro `const_assert`
  - Patch 3: Use index size to enforce not building on a 16 bit machine

ACKs for top commit:
  Kixunil:
    ACK c427d8b213 though I think the last commit was kinda a waste of time and it should have been adding the trait instead or leave it for later.
  apoelstra:
    ACK c427d8b213 successfully ran local tests; unsure if we want to merg this or wait for #3215

Tree-SHA512: 823df5b6a5af3265bce2422c00d287f45816faeb5f965685650ac974a1bd441cf548e25ac2962591732ff221bee91a55703da936382eb166c014ca5d4129edf8
2024-08-24 14:16:31 +00:00
merge-script 6f335b011c
Merge rust-bitcoin/rust-bitcoin#3223: Use TBD in deprecated attribute
a2be82c0c9 Use TBD in deprecated attribute (Tobin C. Harding)

Pull request description:

  Our `release` job checks for 'TBD', I can't remember exactly why but I thought we introduced `0.0.0-NEXT-RELEASE` because CI was failing when we used TBD - clearly this is not the case now because we have a bunch of `TBD`s in the code base.

  Change all the instances of `0.0.0-NEXT-RELEASE` to be `TBD`.

ACKs for top commit:
  Kixunil:
    ACK a2be82c0c9
  apoelstra:
    ACK a2be82c0c9 successfully ran local tests

Tree-SHA512: b383cc4095484291a7b4dca593ad5e017e3a9de9bfae9d6e9447ae36da32aa1c0d1fd593f49fd52c04db5ca5cdbaae8b30a772f792df13542f0a157a86295746
2024-08-24 02:55:37 +00:00
yancy 3e034d5ede Add Arbitrary dependency
Implement Arbitrary for a select subset of types.
2024-08-23 15:39:20 -05:00
merge-script b4bda00141
Merge rust-bitcoin/rust-bitcoin#3221: feat(bip158): compute canonical filter hash
96e0e720fd feat(bip158): compute canonical filter hash (Rob N)

Pull request description:

  From [BIP-157](https://github.com/bitcoin/bips/blob/master/bip-0157.mediawiki#filter-headers)

  > The canonical hash of a block filter is the double-SHA256 of the serialized filter.

  If a user forgets the "double" in double-SHA256 they will be computing a nonsensical filter hash when this is easily handled by the API.

ACKs for top commit:
  Kixunil:
    ACK 96e0e720fd
  tcharding:
    ACK 96e0e720fd

Tree-SHA512: 5fc0b1632e2327adacbd0ab56b4cd7edce0774f8be2f819782519c51b9691a748f4b3c01887f3bf1146dee49a35f9dfac833f53ae69ee7a53858bd2cedcec01a
2024-08-23 13:57:22 +00:00
Tobin C. Harding 9fb5edb39e
ecdsa: Improve error types
There are a couple of issues around the ECDSA signature decoding /
parsing code. We have duplicate code in `from_str` and `from_slice`
and both use the same error type even though it is impossible to get a
hex error in `from_slice`.

Create two errors:

- A `DecodeError` returned by `from_slice`
- A `ParseSignatureError` that has a decode variant and a hex variant

Call through to `from_slice` after parsing hex into a byte vector.

Removes an instance of `unreachable!`.

Fix: #1193
2024-08-23 16:08:47 +10:00
Tobin C. Harding a2be82c0c9
Use TBD in deprecated attribute
Our `release` job checks for 'TBD', I can't remember exactly why but I
thought we introduced `0.0.0-NEXT-RELEASE` because CI was failing when
we used TBD - clearly this is not the case now because we have a bunch
of `TBD`s in the code base.

Change all the instances of `0.0.0-NEXT-RELEASE` to be `TBD`.
2024-08-23 14:49:57 +10:00
Rob N 96e0e720fd
feat(bip158): compute canonical filter hash 2024-08-22 10:33:14 -10:00
Andrew Poelstra d04b6aabe5
bitcoin: add a couple missing prelude imports
These were accidentally removed in #2892 and not noticed because of gaps
in all of our testing infrastructure. These gaps have been since fixed.
2024-08-22 16:55:32 +00:00
merge-script 8f851967a2
Merge rust-bitcoin/rust-bitcoin#3184: Reduce API surface of tagged wrapped hash types
c97389596b Remove stale docs from sha256t_hash_newtype (Tobin C. Harding)
39f7dcb816 Reduce API surface of tagged wrapped hash types (Tobin C. Harding)

Pull request description:

  Recently we made it so that wrapper types created with `hash_newtype` were not general purpose hash types i.e., one could not easily hash arbitrary data into them. We would like to do the same for tagged wrapped hash types.

  In `hashes` do:

  - Create a new macro `sha256_tag` that does just the tag/engine stuff out of the `sha256t_hash_newtype` macro.
  - Deprecate the `sha256t_hash_newtype` macro.

  In `bitcoin` do:

  - Use a combination of `sha256_tag` and `hash_newtype` to create tagged wrapped hash types.

  Note that we do not add private helper functions `engine` and `from_engine` to the tagged wrapper types as we do for legacy/segwit in `sighash`. Can be done later if wanted/needed.

  Fix: #3135

ACKs for top commit:
  Kixunil:
    ACK c97389596b
  apoelstra:
    ACK c97389596b successfully ran local tests

Tree-SHA512: d937a8eac1a77298231f946f9dfbc2f7739af8da00f2075b0b54803b4111c0cec810bc6564515153769193056cf102a9c954e216664f055b249d4a6153b14bca
2024-08-22 14:42:58 +00:00
Tobin C. Harding 39f7dcb816
Reduce API surface of tagged wrapped hash types
Recently we made it so that wrapper types created with `hash_newtype`
were not general purpose hash types i.e., one could not easily hash
arbitrary data into them. We would like to do the same for tagged
wrapped hash types.

In `hashes` do:

- Create a new macro `sha256t_tag` that does just the tag/engine stuff
out of the `sha256t_hash_newtype` macro.
- Deprecate the `sha256t_hash_newtype` macro.

In `bitcoin` do:

- Use a combination of `sha256t_tag` and `hash_newtype` to create tagged
wrapped hash types.

Note that we do not add private helper functions `engine` and
`from_engine` to the tagged wrapper types as we do for legacy/segwit in
`sighash`. Can be done later if wanted/needed.
2024-08-22 10:07:58 +10:00
merge-script b05cf43d22
Merge rust-bitcoin/rust-bitcoin#3187: Remove misleading version metadata
c9053511b2 Remove misleading version metadata (Martin Habovstiak)

Pull request description:

  The metadata in dependency specification was misleading because the version was not guaranteed to be the same anyway this was correctly linted but nobody so far cared to fix it. This change fixes it and adds a hint how to get the real version since some people seem still confused about how these things work.

ACKs for top commit:
  apoelstra:
    ACK c9053511b2 successfully ran local tests
  tcharding:
    ACK c9053511b2

Tree-SHA512: 99d849b1c1b202a429bc7eb25394ff84ba720b3ca6e73bce615f767e0924f5ef63a87553214f0f4fadd3b68ea84246ab8284d75df56cbbe794da7dea0d169dd9
2024-08-21 12:34:14 +00:00
merge-script c061d936fb
Merge rust-bitcoin/rust-bitcoin#3164: Extension traits for `ScriptBuf`
2bb90b8203 Introduce two extensions traits for ScriptBuf (Tobin C. Harding)
ae0a5bd64a Run cargo fmt (Tobin C. Harding)
3fdc574851 Add temporary script buf modules (Tobin C. Harding)
4ff5d6886b Add private ScriptBufAsVec type (Tobin C. Harding)
c81fb93359 Make push_slice_no_opt pub(crate) (Tobin C. Harding)
1001a33f19 Add second ScriptBuf impl block (Tobin C. Harding)
3625d74e8b Make pub in crate functions pub crate (Tobin C. Harding)
b368384317 Separate ScriptBuf POD methods (Tobin C. Harding)

Pull request description:

  Similar to #3155 but for `ScriptBuf`, however it is a little more involved.

  Note:
  - the change to use `impl` syntax (and addition of #3179)
  - mad trickery of `ScriptBufAsVec` (props to Kix)
  - widening of scope of private functions

  Onward and upward!

ACKs for top commit:
  Kixunil:
    ACK 2bb90b8203
  apoelstra:
    ACK 2bb90b8203 successfully ran local tests

Tree-SHA512: 7209d8dc436e52b23e1dbfd9db8432df225ebdb701f465e4d1b55328e22988c98a0f28efdf2a8b3edbafc754354d718ab36bd2f5b1621d12e061b2dadaf49a05
2024-08-20 16:32:29 +00:00
Martin Habovstiak c9053511b2 Remove misleading version metadata
The metadata in dependency specification was misleading because the
version was not guaranteed to be the same anyway this was correctly
linted but nobody so far cared to fix it. This change fixes it and adds
a hint how to get the real version for people who are mistakenly
investigating wrong file.
2024-08-20 09:07:02 +02:00
merge-script 95a78058d9
Merge rust-bitcoin/rust-bitcoin#3182: Refactor Rust version checking
ad34a98c61 Refactor Rust version checking (Martin Habovstiak)
7d5ce89dad Fix type ambiguity in IO tests (Martin Habovstiak)

Pull request description:

  Conditional compilation depending on Rust version using `cfg` had the disadvantage that we had to write the same code multiple times, compile it multiple times, execute it multiple times, update it multiple times... Apart from obvious maintenance issues the build script wasn't generating the list of allowed `cfg`s so those had to be maintained manually in `Cargo.toml`. This was fixable by printing an appropriate line but it's best to do it together with the other changes.

  Because we cannot export `cfg` flags from a crate to different crates we take a completely different approach: we define a macro called `rust_version` that takes a very naturally looking condition such as `if >= 1.70 {}`. This macro is auto-generated so that it produces different results based on the compiler version - it either expands to first block or the second block (after `else`).

  This way, the other crates can simply call the macro when needed.

  Unfortunately some minimal maintenance is still needed: to update the max version number when a newer version is used. (Note that code will still work with higher versions, it only limits which conditions can be used in downstream code.) This can be automated with the pin update script or we could just put the pin file into the `internals` directory and read the value from there. Not automating isn't terrible either since anyone adding a cfg with higher version will see a nice error about unknown version of Rust and can update it manually.

  Because this changes syntax to a more naturally looking version number, as a side effect the `cond_const` macro could be also updated to use the new macro under the hood, providing much nicer experience - it is no longer needed to provide human-readable version of the version string to put in the note about `const`ness requiring a newer version. As such the note is now always there using a single source of truth.

  It's also a great moment to introduce this change right now since there's currently no conditional compilation used in `bitcoin` crate making the changes minimal. However it is not yet added to `bitcoin-io` since `bitcoin-io` is not depending on `internals`. It might be a reason to start depending on it but that's for later discussion.

ACKs for top commit:
  apoelstra:
    ACK ad34a98c61 successfully ran local tests
  tcharding:
    ACK ad34a98c61

Tree-SHA512: 7a82017fc51ba1b473ca638c7bdbf5c893da0a78c70ea8f1a0241049e7874592fad328abd60b3e09a00439b771e7cfc5ebad5e874314d15a48271ec6cb2d7bb7
2024-08-20 00:18:27 +00:00
Tobin C. Harding 2bb90b8203
Introduce two extensions traits for ScriptBuf
In preparation for moving the `ScritpBuf` type to `primitives` add a
public and private extension trait for the functions we want to leave
here in `bitcoin`.

Note, includes a change to the `difine_extension_trait` metavariable
used on `$gent` from `ident` to `path` to support the generic
`AsRef<PushBytes>`.
2024-08-20 09:34:34 +10:00
Martin Habovstiak ad34a98c61 Refactor Rust version checking
Conditional compilation depending on Rust version using `cfg` had the
disadvantage that we had to write the same code multiple times, compile
it multiple times, execute it multiple times, update it multiple
times... Apart from obvious maintenance issues the build script wasn't
generating the list of allowed `cfg`s so those had to be maintained
manually in `Cargo.toml`. This was fixable by printing an appropriate
line but it's best to do it together with the other changes.

Because we cannot export `cfg` flags from a crate to different crates we
take a completely different approach: we define a macro called
`rust_version` that takes a very naturally looking condition such as
`if >= 1.70 {}`. This macro is auto-generated so that it produces
different results based on the compiler version - it either expands to
first block or the second block (after `else`).

This way, the other crates can simply call the macro when needed.

Unfortunately some minimal maintenance is still needed: to update the
max version number when a newer version is used. (Note that code will
still work with higher versions, it only limits which conditions can be
used in downstream code.) This can be automated with the pin update
script or we could just put the pin file into the `internals` directory
and read the value from there. Not automating isn't terrible either
since anyone adding a cfg with higher version will see a nice error
about unknown version of Rust and can update it manually.

Because this changes syntax to a more naturally looking version number,
as a side effect the `cond_const` macro could be also updated to use the
new macro under the hood, providing much nicer experience - it is no
longer needed to provide human-readable version of the version string to
put in the note about `const`ness requiring a newer version. As such the
note is now always there using a single source of truth.

It's also a great moment to introduce this change right now since
there's currently no conditional compilation used in `bitcoin` crate
making the changes minimal.
2024-08-19 15:21:01 +02:00
leichak 2756b7fd7a Removed unneeded usages of vec! macro 2024-08-19 10:12:09 +02:00
Tobin C. Harding ae0a5bd64a
Run cargo fmt
Run the formatter and commit only the changes to `owned`, no other
changes.
2024-08-19 10:40:06 +10:00
Tobin C. Harding 3fdc574851
Add temporary script buf modules
In order to use the formatter to mechanically indent code ready for
adding two extension traits; add two temporary modules.
2024-08-19 10:40:06 +10:00
Tobin C. Harding 4ff5d6886b
Add private ScriptBufAsVec type
Add a private type that allows us to mutate the inner vector of a
`ScriptBuf` only using public functions and never touching the inner
field.

Done in preparation for moving the `ScriptBuf` to `primitives`.

Mad hackery by Kix!
2024-08-19 10:40:06 +10:00
Tobin C. Harding c81fb93359
Make push_slice_no_opt pub(crate)
In preparation for adding script buf extension make the
`push_slice_no_opt` have the same scope as the other private functions,
this will be the scope of the private extension trait.
2024-08-19 10:40:05 +10:00
Tobin C. Harding 1001a33f19
Add second ScriptBuf impl block
In preparation for adding two script buf extension traits; move the
private `ScriptBuf` functions into a separate impl block.

Code move only.
2024-08-19 10:40:05 +10:00
Tobin C. Harding 3625d74e8b
Make pub in crate functions pub crate
In preparation for adding a private extension trait change the scope to
`pub(crate)` because the more specific `pub(in ...)` is not currently
supported by our `define_extension_trait` macro.
2024-08-19 10:40:05 +10:00
Tobin C. Harding b368384317
Separate ScriptBuf POD methods
In preparation for moving the `ScriptBuf` as a plain old datatype to
`primitives`; separate the POD methods into their own impl block.

Refactor only, no logic changes.
2024-08-19 10:40:05 +10:00
merge-script d862077d07
Merge rust-bitcoin/rust-bitcoin#3154: Parse MSRV minor version number from env
b8067da934 Parse MSRV minor version number from env (yancy)

Pull request description:

  Parse MSRV minor version number from env

  replaces: https://github.com/rust-bitcoin/rust-bitcoin/pull/3145

ACKs for top commit:
  Kixunil:
    ACK b8067da934
  tcharding:
    ACK b8067da934
  apoelstra:
    ACK b8067da934 successfully ran local tests

Tree-SHA512: 60b3898c9b2739ca4858218b21d5c136b91b6ef45b1dc8f798d97aac861c42d046f114efcefdfa79f514d6da392f715a715ee6b3f230eb459f34e554b48ccf0e
2024-08-15 17:51:47 +00:00
merge-script 3119ade372
Merge rust-bitcoin/rust-bitcoin#3155: Extension trait for `Script`
0857697665 Replace impl blocks with extension traits (Martin Habovstiak)
b99bdcfdd6 Format `Script` blocks (Martin Habovstiak)
b027edffe7 Wrap `Script` impl blocks in temporary modules (Martin Habovstiak)
5a461545c7 Separate private `Script` methods (Martin Habovstiak)
27adc09e9f Generalize fn params in `define_extension_trait` (Martin Habovstiak)
fcc3cb03f0 Support non-doc attrs in extension trait macro (Martin Habovstiak)
ca1735f24c Separate POD methods (Tobin C. Harding)

Pull request description:

  This moves methods from `Script` to extension traits in steps that should be easy to follow.

  Moving to `primitives` requires doing the same with `ScriptBuf` so I'm holding off until this approach gets concept ACK (or alternatively someone else can do it :))

  Closes #3161

ACKs for top commit:
  tcharding:
    ACK 0857697665
  apoelstra:
    ACK 0857697665 successfully ran local tests

Tree-SHA512: 3768d879e36139cf971c1921d3236141cbe87d707fd4bab7852f6ed8857b7867fa4146dfe720bd54e3d8cc50ecdc93886a10254cf9a82246358253f0312ffb47
2024-08-15 17:11:03 +00:00
merge-script 49e420a6e0
Merge rust-bitcoin/rust-bitcoin#3059: Move `CompactTarget` to `primitives`
2ec901fd63 Move the CompactTarget type to primitives (Tobin C. Harding)
a00bd7cc4d Introduce CompactTargetExt trait (Tobin C. Harding)
100ce03643 Run cargo +nightly fmt (Tobin C. Harding)
9c4a629659 Wrap CompactTarget impl block in temporary module (Tobin C. Harding)
578143c09e Separate CompactTarget impl blocks (Tobin C. Harding)
22d5646f7b Stop using CompactTarget inner field (Tobin C. Harding)
244d7dbe6c Remove generic test impl (Tobin C. Harding)
3d85ee3a02 primitives: Fix alloc feature (Tobin C. Harding)

Pull request description:

  Done in preparation for moving `BlockHash` and `block::Header` to `primitives`.

  - Patch 1 introduces an extension trait using `define_extension_trait!`
  - Patch 2 is the trivial copy and past to move the type to `primitives`

  This one shouldn't be to arduous to review, thanks.

ACKs for top commit:
  Kixunil:
    ACK 2ec901fd63
  apoelstra:
    ACK 2ec901fd63 successfully ran local tests

Tree-SHA512: b0e4f1af0b268e249a056cae71d7cafd1b025c4a079e5393ce80cd0b9c9bb6d2c6306531dc6786d986ff8a094b61866a86285b20d54037ef1395d127876bfd9c
2024-08-15 13:30:35 +00:00
Martin Habovstiak 0857697665 Replace impl blocks with extension traits
In preparation to move script types to `primitives` we replace impl
block with extension traits by replacing the temporary modules with
`define_extension_trait`.
2024-08-13 13:14:00 +02:00
Martin Habovstiak b99bdcfdd6 Format `Script` blocks
This commit is produced by running `cargo +nightly fmt`
2024-08-13 13:13:50 +02:00
Martin Habovstiak b027edffe7 Wrap `Script` impl blocks in temporary modules
`rustfmt` is unable to format macro calls so instead we wrap the impl
blocks in modules to enable formatting in the next commit. We need to
change the visibility of the methods but that's OK since they're
internal.
2024-08-13 13:13:40 +02:00
Martin Habovstiak 5a461545c7 Separate private `Script` methods
These will need a private extension trait and to make the review easier,
we separate them.
2024-08-13 13:13:29 +02:00
Martin Habovstiak 27adc09e9f Generalize fn params in `define_extension_trait`
The macro was trying to "parse" the parameters of functions defined in
extension trait. This was not needed and it was causing problems around
the `self` parameter. In this commit we change the macro to just pass
the parameters through.
2024-08-13 13:13:10 +02:00
Tobin C. Harding 2ec901fd63
Move the CompactTarget type to primitives
Potentially the whole `pow` module will move to `primitives` but this
is not possible easily right now. However, we would like to be able to
move the `BlockHash` and `block::Header` types over to `primitives`
and doing so requires the `CompactTarget` to be there.

Move the `CompactTarget` type to `primitives` and re-export it from the
`primitives` crate root.

Note also, we re-export the type publicly from `bitcoin::pow`.
2024-08-13 05:29:22 +10:00
Tobin C. Harding a00bd7cc4d
Introduce CompactTargetExt trait
In preparation for moving the `CompactTarget` type to `primitives`
introduce an extension trait for code that will be left behind in
`bitcoin`.
2024-08-13 05:26:59 +10:00
yancy b8067da934 Parse MSRV minor version number from env 2024-08-12 14:24:31 -05:00
Tobin C. Harding 100ce03643
Run cargo +nightly fmt
No manual changes.
2024-08-13 05:23:35 +10:00
Tobin C. Harding 9c4a629659
Wrap CompactTarget impl block in temporary module
`rustfmt` is unable to format macro calls so instead we wrap the impl
blocks in a module to enable formatting in the next commit.
2024-08-13 05:23:31 +10:00
Tobin C. Harding 578143c09e
Separate CompactTarget impl blocks
In preparation for adding an `CompactTargetExt` trait move the
primitives methods to a separate impl block.

Refactor only, no logic changes.
2024-08-13 05:23:26 +10:00
Tobin C. Harding 22d5646f7b
Stop using CompactTarget inner field
In preparation for moving the `CompactTarget` type to `primitives` stop
using the inner field in code that will stay behind in the
`bitcoin::pow` module.
2024-08-13 05:23:10 +10:00
Tobin C. Harding 244d7dbe6c
Remove generic test impl
In preparation for moving the `CompactTarget` to `primitives` remove the
generic `Into` impl and explicitly implement for just the `From` impls
that the `pow` unit tests use.

Test code only.
2024-08-13 05:23:10 +10:00
Antoni Spaanderman 7c8601a696
implement IndexMut for PushBytes 2024-08-11 21:57:20 +02:00
Antoni Spaanderman 71d760b3f2
Add and fix documentation on PushBytes's functions 2024-08-11 21:55:15 +02:00
Martin Habovstiak fcc3cb03f0 Support non-doc attrs in extension trait macro
The `define_extension_trait` macro originally didn't support `#[inline]`
or other attributes for simplicity. We still want them so this commit
adds basic support for it. It adds the `doc` attributes to trait
*definition* only and adds all other attributes to the *implementation*
only. This should support `#[inline]` and other attributes. The downside
is it doesn't support adding non-doc attributes to trait *definition*
but I can't think of any relevant ones that we would want and we can
find a solution later if we do.
2024-08-11 14:57:47 +02:00
Tobin C. Harding ca1735f24c Separate POD methods
We want to move `Script` as a plain old data type to `primitives`.

Step 1: Move the methods that will go to `primitives` to a separate impl
block.
2024-08-11 14:40:08 +02:00
merge-script bee044fbb9
Merge rust-bitcoin/rust-bitcoin#3137: De-sugar `self`
34e8212594 Replace &self with self: &Self (Tobin C. Harding)

Pull request description:

  `foo(&self)` is syntax sugar for `foo(self: &Self)`.

  The `define_extension_trait` is currently large, ugly, and not that expressive. If we use `self: &Self` then the macro is greatly simplified.

  (Also consuming version `self: Self`)

  De-sugar only, no logic changes.

ACKs for top commit:
  apoelstra:
    ACK 34e8212594 successfully ran local tests; lol this looks so much better
  Kixunil:
    ACK 34e8212594

Tree-SHA512: 7ec81bee99ede328d73a661c9e683a774ba14404ceb89ecb06765bedddf04dc9721672775b9ad3a9e3356d510c76681848f24ce4392a59d53216d23e6a27d9ad
2024-08-08 19:55:07 +00:00
merge-script c59b9e3d1a
Merge rust-bitcoin/rust-bitcoin#2929: Introduce `ToU64` trait
579b76b7cb Introduce ToU64 conversion trait (Tobin C. Harding)

Pull request description:

  The idea for this was pulled out of Steven's work in #2133

  We already explicitly do not support 16 bit machines.

  Also, because Rust supports `u182`s one cannot infallibly convert from a `usize` to a `u64`. This is unergonomic and results in a ton of casts.

  We can instead limit our code to running only on machines where `usize` is less that or equal to 64 bits then the infallible conversion is possible.

  Since 128 bit machines are not a thing yet this does not in reality introduce any limitations on the library.

  Add a "private" trait to the `internals` crate to do infallible conversion to a `u64` from `usize`.

  Implement it for all unsigned integers smaller than `u64` as well so we have the option to use the trait instead of `u32::from(foo)`.

ACKs for top commit:
  Kixunil:
    ACK 579b76b7cb
  apoelstra:
    ACK 579b76b7cb successfully ran local tests

Tree-SHA512: 2eaddfff995987a346e052386c6dfef3510e4732e674e3a2cfab60ee391b4cce1bf7ba4fb2dfd4926f8203d7251eea2198ccb61f0b40332e624c88fda4fa7f48
2024-08-08 19:05:23 +00:00
merge-script 5a53cfe81f
Merge rust-bitcoin/rust-bitcoin#3138: Manually format
191897f9ea Manually format (Tobin C. Harding)

Pull request description:

  Run `rustfmt` and manually fix the places where comments are moved to the wrong place.

ACKs for top commit:
  Kixunil:
    ACK 191897f9ea
  apoelstra:
    ACK 191897f9ea successfully ran local tests

Tree-SHA512: f977ff373d1d410012734208c090bfcd8f9dbda414d0b19400acf8f552df481b4a2bc20d77c61538895a6fb66197be13cbdadf74956d67fd4d055b99ba8ab356
2024-08-08 17:36:36 +00:00
Tobin C. Harding 579b76b7cb
Introduce ToU64 conversion trait
We already explicitly do not support 16 bit machines.

Also, because Rust supports `u182`s one cannot infallibly convert from a
`usize` to a `u64`. This is unergonomic and results in a ton of casts.

We can instead limit our code to running only on machines where `usize`
is less that or equal to 64 bits then the infallible conversion is
possible.

Since 128 bit machines are not a thing yet this does not in reality
introduce any limitations on the library.

Add a "private" trait to the `internals` crate to do infallible
conversion to a `u64` from `usize`.

Implement it for all unsigned integers smaller than `u64` as well so
we have the option to use the trait instead of `u32::from(foo)`.
2024-08-08 15:32:40 +10:00
Tobin C. Harding abe7b3f202
Remove build cfg for versions less than MSRV
Recently we upgraded the MSRV but forgot to remove the Rust version
specific `cfg`s.
2024-08-08 12:03:06 +10:00
Tobin C. Harding 191897f9ea
Manually format
Run `rustfmt` and manually fix the places where comments are moved to
the wrong place.
2024-08-08 09:38:45 +10:00
Tobin C. Harding 34e8212594
Replace &self with self: &Self
`foo(&self)` is syntax sugar for `foo(self: &Self)`.

The `define_extension_trait` is currently large, ugly, and not that
expressive. If we use `self: &Self` then the macro is greatly
simplified.

De-sugar only, no logic changes.
2024-08-08 09:17:47 +10:00
merge-script 2dac88b416
Merge rust-bitcoin/rust-bitcoin#3126: Remove catch all pattern
6836de9ee6 Remove catch all pattern (Tobin C. Harding)

Pull request description:

  The `PushBytes` type enforces len is less than 0x100000000 so we do not need to panic in a catch all pattern after explicitly matching against less than 0x100000000.

  Refactor only because of the invariant on `PushBytes` - no logic changes.

ACKs for top commit:
  apoelstra:
    ACK 6836de9ee6 successfully ran local tests
  Kixunil:
    ACK 6836de9ee6

Tree-SHA512: a7cdb31683a8c00eecbdd0879886bec48133f9029f899b5279f1f5294ef40320592db196bfcafdeef4507636fc785a7ab87879b25b6d1b4905ae573b545f1ff4
2024-08-06 13:06:20 +00:00
Tobin C. Harding 6836de9ee6
Remove catch all pattern
The `PushBytes` type enforces len is less than 0x100000000 so we do
not need to panic in a catch all pattern after explicitly matching
against less than 0x100000000.

Refactor only because of the invariant on `PushBytes` - no logic
changes.
2024-08-06 10:23:47 +10:00
merge-script 5cca2f271d
Merge rust-bitcoin/rust-bitcoin#3122: Introduce helper function name policy
84df3438ca Fix markdown list items (Tobin C. Harding)
0a45c68cf8 Introduce helper function name policy (Tobin C. Harding)

Pull request description:

  As much as it hurts the C hacker inside me we have settled on using `_internal` to mark private function names that clash with a public function of the same name.

  Introduce a policy section and rename one instance, I did not grep the codebase looking for other violations.

  This came up because I had to look at what `_inner` implied when reading the function name somewhere else.

ACKs for top commit:
  storopoli:
    ACK 84df3438ca
  apoelstra:
    ACK 84df3438ca successfully ran local tests; sgtm. should probably update rust-miniscript which uses a `real_` prefix

Tree-SHA512: aece73fac54c4f34bdba72c08721586eb6d76dc9191442bbca43301f2af3d3b3e3217383f1ad20752fa7654e7f5d09927d1a4b72602aa064e76d550b5d6e81bd
2024-08-05 23:11:05 +00:00
Tobin C. Harding 0a45c68cf8
Introduce helper function name policy
As much as it hurts the C hacker inside me we have settled on using
`_internal` to mark private function names that clash with a public
function of the same name.

Introduce a policy section and rename one instance, I did not grep the
codebase looking for other violations.

This came up because I had to look at what `_inner` implied when reading
the function name somewhere else.
2024-08-06 04:17:28 +10:00
Tobin C. Harding ea9f6e8f97
Cast after calling min
In an effort to reduce the cognitive load of reading code we are
removing casts unless they are useful or obvious.

Move the cast onto the call to `min` and comment it for good measure.
This allows us to call infallible `from` for conversion when needed.

Refactor only, no logic changes.
2024-08-05 07:59:35 +10:00
Tobin C. Harding 342fe18ad0
Use From in map_to_range
In an effort to remove unnecessary casts use `u128::from` to convert
from `u64`s. Leave the cast to `u64` in there because it is right after
a shift right and is brain-dead obvious.
2024-08-05 07:59:35 +10:00
Tobin C. Harding d9331794f1
bip158: Fix typo 2024-08-05 07:59:35 +10:00
Tobin C. Harding c427d8b213
bitcoin: Compile time assert on index size
Currently we enforce that our code only runs on machines with a
certain pointer width (32 or 64 by failing to compile if pointer size
width is 16). One of the underlying reasons is because of requirements
in consensus code in Bitcoin Core which requires containers with more
than 2^16 (65536) items [0].

We can better express our requirements by asserting on Rust's index
size (the `usize` type).

As a side benefit, there is active work [1] to make Rust support
architectures where pointer width != idex size. With this patch applied
`rust-bitcoin` will function correctly even if that work progresses.

- [0] https://github.com/rust-bitcoin/rust-bitcoin/pull/2929#discussion_r1659399813
- [1] https://github.com/rust-lang/rust/issues/65473
2024-08-05 05:36:21 +10:00
Tobin C. Harding 298b96c579
Add an extension trait for script validation
Add an extension trait for the validation logic in preparation for
moving the `Script` type to `primitives`.
2024-07-29 07:48:07 -05:00
Tobin C. Harding c1aa33ed89
Use impl syntax instead of generic
A single trait bound can be expressed using the `impl` style. This is a
breaking change because callers can no longer use turbofish. In this
case that probably does not matter because users are likely just passing
an integer in and letting the compiler infer the type.

Done in preparation for moving logic into an extension trait so that the
functions can be parsed by the `define_extension_trait` macro.

ref: https://doc.rust-lang.org/reference/types/impl-trait.html
2024-07-29 07:43:50 -05:00
merge-script 15b87606bf
Merge rust-bitcoin/rust-bitcoin#3100: Bump MSRV to 1.63
c72069e921 Bump MSRV to 1.63 (Martin Habovstiak)

Pull request description:

  The version 1.63 satisfies our requirements for MSRV and provides significant benefits so this commit bumps it. This commit also starts using some advantages of the new MSRV, namely namespaced features, weak dependencies and the ability to use trait bounds in `const` context.

  This however does not yet migrade the `rand-std` feature because that requires a release of `secp256k1` with the same kind of change - bumping MSRV to 1.63 and removing `rand-std` in favor of weak dependency. (Accompanying PR to secp256k1: https://github.com/rust-bitcoin/rust-secp256k1/pull/709 )

  Suggested plan:

  * merge both PRs
  * at some point release `hashes` and `secp256k`
  * remove `rand-std` from `bitcoin`
  * release the rest of the crates

ACKs for top commit:
  apoelstra:
    ACK c72069e921
  tcharding:
    ACK c72069e921

Tree-SHA512: 0b301ef8145f01967318d3ed1c738d33e6cf9e44f835f3762122b460a536f926916dbd6ea39d6f80b4f95402cd845e924401e75427dbb0731ca5b12b4fa6915e
2024-07-28 21:11:28 +00:00
Fmt Bot 08fc780033 2024-07-28 automated rustfmt nightly 2024-07-28 01:12:04 +00:00
merge-script 5f79ff0966
Merge rust-bitcoin/rust-bitcoin#3098: Make `ScriptBuf::p2wpkh_script_code` stand alone
feef34fdea Make ScriptBuf::p2wpkh_script_code stand alone (Tobin C. Harding)

Pull request description:

  We would like to move the `Script` type to `primitives` without moving any key stuff, including pubkey hashes. We may later, before releasing `primitives`, move the `WPubkeyHash` at which time this patch can be reverted or re-implemented on `ScriptBuf`.

  The `ScriptBuf::p2wpkh_script_code` function does not take `self` as a parameter but it does return `Self` - this can trivially be made into a standalone function.

  Make `ScriptBuf::p2wpkh_script_code` a standalone function.

ACKs for top commit:
  Kixunil:
    ACK feef34fdea
  apoelstra:
    ACK feef34fdea

Tree-SHA512: 9de43bb274480b85d328ddd4cb6d79b501a525837307ca399dea1c3d39e9a7c0d8719dbb0e5d852629351d2b1fe09ce0244df82c53ff9ef2342be85a71887329
2024-07-27 21:08:34 +00:00
Martin Habovstiak c72069e921 Bump MSRV to 1.63
The version 1.63 satisfies our requirements for MSRV and provides
significant benefits so this commit bumps it. This commit also starts
using some advantages of the new MSRV, namely namespaced features, weak
dependencies and the ability to use trait bounds in `const` context.

This however does not yet migrade the `rand-std` feature because that
requires a release of `secp256k1` with the same kind of change - bumping
MSRV to 1.63 and removing `rand-std` in favor of weak dependency.
2024-07-27 07:24:32 +02:00
merge-script d5149c1f54
Merge rust-bitcoin/rust-bitcoin#3065: Move `validation` module to `consensus_validation`
29b213daca Move validation module to consensus_validation (Tobin C. Harding)

Pull request description:

  The `consensus` module is currently doing two things, validation and encoding. These two things are orthogonal.

  Move the `consensus::validation` module to `consensus_validation`. Remove the function re-exports from `consensus`.

  This was originally discussed here: https://github.com/rust-bitcoin/rust-bitcoin/issues/2779

ACKs for top commit:
  Kixunil:
    ACK 29b213daca
  apoelstra:
    ACK 29b213daca

Tree-SHA512: 3bd0e43c220b0d89a47e9df0e0c92b776ccc65f5f60d57f413db834acc8e86269379bc9fdd688f8c4f0138db22f8eb8983770afa2d7d53d51acf063f2302121c
2024-07-26 11:26:36 +00:00
Tobin C. Harding feef34fdea
Make ScriptBuf::p2wpkh_script_code stand alone
We would like to move the `Script` type to `primitives` without moving
any key stuff, including pubkey hashes. We may later, before releasing
`primitives`, move the `WPubkeyHash` at which time this patch can be
reverted or re-implemented on `ScriptBuf`.

The `ScriptBuf::p2wpkh_script_code` function does not take `self` as a
parameter but it does return `Self` - this can trivially be made into a
standalone function.

Make `ScriptBuf::p2wpkh_script_code` a standalone function.
2024-07-23 11:24:31 -05:00
merge-script 1b83763cdc
Merge rust-bitcoin/rust-bitcoin#3083: Fix rustdocs in `blockdata`
3b15ef6d27 Fix rustdocs in `blockdata` (Jamil Lambert, PhD)

Pull request description:

  Following up on the [comment](https://github.com/rust-bitcoin/rust-bitcoin/pull/2646#discussion_r1548848611) in #2646 the rustdocs formatting was fixed in `blockdata`.

ACKs for top commit:
  Kixunil:
    ACK 3b15ef6d27
  tcharding:
    ACK 3b15ef6d27

Tree-SHA512: 509aa2b8ae559f5a7f8230c016c0866f468cc147773238e226b9a975784d7a424c41a5d966ddcf9b3f8f8d4fe197a4f272b5777c61f3cc53051803abb520b95e
2024-07-23 13:29:27 +00:00
Fmt Bot 61d46fffa8 2024-07-21 automated rustfmt nightly 2024-07-21 01:11:38 +00:00
merge-script e1478b1802
Merge rust-bitcoin/rust-bitcoin#3069: Remove re-export of `ParseIntError`
ab581a90f8 Remove re-export of ParseIntError (Tobin C. Harding)

Pull request description:

  In d242125 I claimed that `ParseIntError` was somehow special, I no longer thing this is the case. As we pin down the re-export policy (for errors and other types) it is hard if we have one non-typical re-export.

  We have https://github.com/rust-bitcoin/rust-bitcoin/issues/3068 to discuss the policy, for now just remove the unusual re-export.

ACKs for top commit:
  Kixunil:
    ACK ab581a90f8
  shinghim:
    ACK ab581a90f8
  apoelstra:
    ACK ab581a90f8

Tree-SHA512: 5ac4123aeb27c8cee78e5760f21e70be8035d526ba7e14e72759cba27f98b51cc2cba9b2bf0eeb99e0f6b7210ec4a750986bb6c5dc0725ed892730fdec8a7e06
2024-07-19 15:36:21 +00:00
merge-script ff5d437d42
Merge rust-bitcoin/rust-bitcoin#3067: Move `params` to the `network` module
54c30556a2 Move params to network module (Tobin C. Harding)
045a661ebe Create network directory (Tobin C. Harding)

Pull request description:

  Discussed in #2779. Patch one moves `network.rs` to `network/mod.rs`, and patch 2 moves the `params` module over there.

ACKs for top commit:
  apoelstra:
    ACK 54c30556a2 Yeah, this seems like a good place for it
  Kixunil:
    ACK 54c30556a2

Tree-SHA512: 134813419db21323d303d465b12fcbf37fd61dc1baf3305e156d324eafd822379e63dede02877ee99dce41540193a29e6e13acd13f9121f3e2fe11096524aa5e
2024-07-19 14:10:26 +00:00
Tobin C. Harding 29b213daca
Move validation module to consensus_validation
The `consensus` module is currently doing two things, validation and
encoding. These two things are orthogonal.

Move the `consensus::validation` module to `consensus_validation`.

Remove the function re-exports from `consensus`.
2024-07-19 14:28:31 +10:00
merge-script 128684e0da
Merge rust-bitcoin/rust-bitcoin#3058: Improve `define_extension_trait`
386ad93253 Manually format function parameters (Tobin C. Harding)
871f4398b9 Add optional comma to function parameter list (Tobin C. Harding)

Pull request description:

  During #2955 I was lazy and did not think through why the macro didn't handle function parameters on individual lines, I just manually re-formatted all function calls onto a single LOC. This was a bit slack of me.

  - Patch 1: Fix the macro.
  - Patch 2: Revert the manual formatting.

ACKs for top commit:
  jamillambert:
    ACK 386ad93253
  Kixunil:
    ACK 386ad93253
  apoelstra:
    ACK 386ad93253

Tree-SHA512: 577154668a4cd0bad225a5b306193a5cd3d38d275dd5df22b4a29737e0d2c910c695da33c0ed77265f6c5d876c162316e444f8eca80f9c30788d110d989493e3
2024-07-18 21:48:19 +00:00
merge-script 8804fa63b4
Merge rust-bitcoin/rust-bitcoin#3064: Remove public error re-export
beea3c1e5d Remove public error re-export (Tobin C. Harding)

Pull request description:

  We do not have a policy to re-export things from other modules just because they are in the public API - I don't see any other reason to re-export this error, users should go to the `validation` module directly to get the error type.

  Raising this trivial change as a separate PR so that we can really pin down our re-export policy. Please review the policy implications as well as the code change.

  Note please that this change was introduced in 7d695f6b4 by me, and buried in a PR that did not mention the change. This was wrong, as in the code change was wrong and also the patching method was wrong.

ACKs for top commit:
  Kixunil:
    ACK beea3c1e5d

Tree-SHA512: 5fc072f3fb8a727f30751211c6bc85dc268d413ee62937c714bdf9f47405dfdbc93cfff3df76c201493c39f49d5d315907fc9e7e4fa0d927652c01038815fdc5
2024-07-18 15:48:47 +00:00
Jamil Lambert, PhD 3b15ef6d27 Fix rustdocs in `blockdata`
Following up on the comment in #2646 the rustdocs formatting was fixed.
2024-07-18 11:04:35 +01:00
Tobin C. Harding ab581a90f8
Remove re-export of ParseIntError
In d242125 I claimed that `ParseIntError` was somehow special, I no
longer thing this is the case. As we pin down the re-export policy (for
errors and other types) it is hard if we have one non-typical re-export.

We have https://github.com/rust-bitcoin/rust-bitcoin/issues/3068 to
discuss the policy, for now just remove the unusual re-export.
2024-07-17 08:01:32 +10:00
Tobin C. Harding 54c30556a2
Move params to network module
The `Params` struct is currently defined in the `consensus` module which
has become a collection of orthogonal consensus-ish things. We would
like to put things in more descriptive places.

The `Params` struct defines constants that are network specific so it
makes sense to put it in the `network` module. As soft proof of this
argument note in this patch how often the `Params` type is imported
along with the `Network` type.

API break:

The type is no longer available at `bitcoin::consensus::Params` but
rather is re-exported at `bitcoin::network::Params`.
2024-07-17 07:39:34 +10:00
Tobin C. Harding 045a661ebe
Create network directory
In preparation for moving the `Params` struct to the `network` module
add a directory and move `network.rs` to `network/mod.rs`.
2024-07-17 07:19:27 +10:00
Tobin C. Harding beea3c1e5d
Remove public error re-export
We do not have a policy to re-export things from other modules just
because they are in the public API - I don't see any other reason to
re-export this error, users should go to the `validation` module
directly to get the error type.
2024-07-17 06:52:15 +10:00
Tobin C. Harding 386ad93253
Manually format function parameters
Now that the `define_extension_trait` can handle function parameters on
individual lines revert the manual formatting that was introduced in
PR #2955.

Refactor only, no logic changes.
2024-07-17 06:15:37 +10:00
Tobin C. Harding 871f4398b9
Add optional comma to function parameter list
The `define_extension_trait` macro currently does not allow for a
trailing comma in the function paramater list, this occurs when the
function paramaters are put on individual lines (eg by `rustfmt`).

Extend the macro to support function paramaters being on individual
lines. This should have been done originally instead of my manual
override of formatting - bad Tobin no biscuit.
2024-07-17 06:15:32 +10:00
merge-script 8eb5d8fad0
Merge rust-bitcoin/rust-bitcoin#3019: Fix error messages
2169b75bba Use lower case error messages (Jamil Lambert, PhD)

Pull request description:

  Error messages should be lower case, except for proper nouns and variable names.  These have all been changed.

  ~~They should also state what went wrong.  Some expect error messages were positive, giving the correct behaviour or correct input.  These have been changed so that they are now negative, i.e. saying what went wrong.~~

  EDIT: After further discussion it was decided not to change the expect messages.

ACKs for top commit:
  Kixunil:
    ACK 2169b75bba
  tcharding:
    ACK 2169b75bba

Tree-SHA512: 92442c869e0141532425f6fca5195fd319b65026f68c4230a65ad70253565d98931b2b44ee202975c307280525c505147e272297dc81207312e40c43d007021c
2024-07-16 15:30:26 +00:00
merge-script 6d483585df
Merge rust-bitcoin/rust-bitcoin#2991: Move locktimes and `Sequence` to `primitives`
64c31cfb97 Move locktimes and Sequence to primitives (Tobin C. Harding)

Pull request description:

  The `absolute` and `relative` locktimes as well as the `Sequence` are all primitive bitcoin types.

  Move the `Sequence`, and `locktime` stuff over to `primitives`.

  There is nothing surprising here, the consensus encoding stuff stays in `bitcoin` and we re-export everything from `blockdata`.

  Note please `Sequence` is no longer publicly available at `bitcoin::transaction::Sequence` but it is available at `bitcoin::Sequence`.

ACKs for top commit:
  Kixunil:
    ACK 64c31cfb97
  apoelstra:
    ACK 64c31cfb97

Tree-SHA512: 968aa595bfb53e8fcfa860dae797ec5381ed49c67326a8ef9494086ec65d737502dffe4b24143e159042d07c59c5109d50103029082f87e1c3c26671e975f1b3
2024-07-15 21:13:41 +00:00
Jamil Lambert, PhD 2169b75bba Use lower case error messages
Error messages should start with a lower case character unless it is a
proper noun.

This has been changed everywhere.
2024-07-15 09:25:08 +01:00
Shing Him Ng 02e7933fe4 Rename key field in Key to key_data 2024-07-14 18:12:24 -05:00
Tobin C. Harding 64c31cfb97
Move locktimes and Sequence to primitives
The `absolute` and `relative` locktimes as well as the `Sequence` are
all primitive bitcoin types.

Move the `Sequence`, and `locktime` stuff over to `primitives`.

There is nothing surprising here, the consensus encoding stuff stays in
`bitcoin` and we re-export everything from `blockdata`.
2024-07-15 08:53:51 +10:00
merge-script 9477ddc57b
Merge rust-bitcoin/rust-bitcoin#3022: Update Key documentation
164b72e07b Update Key documentation (Shing Him Ng)

Pull request description:

  The documentation for `Key` was a bit confusing since `<key> := <keylen> <keytype> <keydata>` was right above the `key` field, when in reality the `key` field represents the key data. Moving the documentation that describes a `Key` as a whole to the struct itself and specifying that `key` represents key data will hopefully clear things up a bit

ACKs for top commit:
  Kixunil:
    ACK 164b72e07b
  tcharding:
    ACK 164b72e07b

Tree-SHA512: 33c2b24d3006a0ed85a5d96351e0a01c1365c8ea01472233b024de54941319cdbefa0126f8b9538385e8f33ba7e2e3895f0dc5b6a36a1c501c8b97ebbede6502
2024-07-14 22:43:17 +00:00
merge-script 11f28e2728
Merge rust-bitcoin/rust-bitcoin#2955: Add scriptPubkey extension traits to script types
bcf6d2839e Introduce scriptPubkey extension traits (Tobin C. Harding)
ee333defa4 Remove path from ScriptBuf (Tobin C. Harding)

Pull request description:

  Done in preparation for moving the script types to `primitives`.

  Add three public traits, one each for the three `script` types: `Builder`, `ScriptBuf`, and `Script`.

ACKs for top commit:
  Kixunil:
    ACK bcf6d2839e
  apoelstra:
    ACK bcf6d2839e

Tree-SHA512: 0ad11e474ddf1183d0119e36454cb4fd18d49a68655d274df800c6ef20afa7f8d0fdecd415c02595ea67a011e3a842b7ccc23c2d58f92ed9acbdc7f277fbd217
2024-07-14 19:53:26 +00:00
merge-script 752f54797a
Merge rust-bitcoin/rust-bitcoin#3040: Automated nightly rustfmt (2024-07-14)
d57ca72ed0 2024-07-14 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 d57ca72ed0

Tree-SHA512: 3f9d1718c485cdcaa0c03fab3e86e5a0f5534ec3164f3d25c7b4d9b1db7374edf534bb2436da615c1f6432dbbc692b37ca400b309b732170c8cf01ee4482d18f
2024-07-14 16:32:36 +00:00
Fmt Bot d57ca72ed0 2024-07-14 automated rustfmt nightly 2024-07-14 01:11:56 +00:00
Shing Him Ng e2b0fd33be Specify required_height in variable name when comparing to other height 2024-07-12 22:26:56 -05:00
Tobin C. Harding bcf6d2839e
Introduce scriptPubkey extension traits
Done in preparation for moving the script types to `primitives`.

The script types have a bunch of functionality to support scriptPubkeys,
and scriptPubkeys are an address thing.

Create a module under `address` and in it create a bunch of extension
traits to hold all scriptPubkey functionality.

Includes adding an ugly-as-hell macro to create the traits.
2024-07-13 08:43:06 +10:00
Tobin C. Harding ee333defa4
Remove path from ScriptBuf
The `ScriptBuf` type is perfectly descriptive without the use of the
additional `script::` path.

Refactor only, no logic changes.
2024-07-13 08:35:54 +10:00
Shing Him Ng 164b72e07b Update Key documentation 2024-07-12 15:59:01 -05:00
merge-script b14625f0d5
Merge rust-bitcoin/rust-bitcoin#2646: Some additional inspectors on Script and Witness
ac4db6369d witness: Add Witness::witness_script inspector (Steven Roose)
6cc6c8621a witness: Add Witness::taproot_annex (Steven Roose)
b0848022eb witness: Add Witness::taproot_control_block (Steven Roose)
ef336e1387 witness: Improve Witness::tapscript (Steven Roose)
e48a2e4225 script: Add Script::redeem_script inspector (Steven Roose)

Pull request description:

  Bundled these because they are very similar. Got a bunch of larger changes coming up based on these. I've been using these for a while for TXHASH work.

ACKs for top commit:
  apoelstra:
    ACK ac4db6369d but will need to wait for next release. I think we should merge these as-is although they will be much clearer after we do script tagging.
  tcharding:
    ACK ac4db6369d

Tree-SHA512: e1590d1bdc8b91aeba137453f0cdaa7e1ae6df3c8e9e1e0f087ed9be1a6beaf2286818379247d26c5dd27d07c12c10433db1c9b9a71667ab4d8d37c7deff1373
2024-07-12 18:09:10 +00:00
merge-script 6c8f759676
Merge rust-bitcoin/rust-bitcoin#2996: Add alloc feature to `base58`, `addresses`, and `primitives`
dc96475f58 Add/fix alloc features (Tobin C. Harding)

Pull request description:

  Eventually we would like all our crates other than `bitcoin` to be able to be used without an allocator. Currently, and during crate smashing, this is not that useful because so much of the code comes from `bitcoin` and relies on the availability of an allocator.

  As an initial step, add the `alloc` feature to `addresses` , `base58`, and `primitives`.

  In order to to keep `--no-default-features` builds working make the crates empty if the `alloc` feature is not enabled. This is a suboptimal solution because the error messages users will get when they forget to enable `alloc` will be confusing (eg something like primitives does not contain Transaction). However our CI script (`run_task.sh`) expects `--no-default-features` to build cleanly (as do I).

ACKs for top commit:
  apoelstra:
    ACK dc96475f58
  Kixunil:
    ACK dc96475f58

Tree-SHA512: 28006ad638e72d3c712becaf94f6aaddc559fb2f7e7ad0d0810348fe979fb61e32f53e5b20894e472c5ac9e2b7f80cba6a3f0e12b766b817f412a927957ae3a2
2024-07-11 22:31:42 +00:00
Tobin C. Harding 40bee24de7
Run the formatter
I don't want to wait for the bot, just run the formatter now.

No manual changes.
2024-07-11 11:21:53 +10:00
Tobin C. Harding dc96475f58
Add/fix alloc features
Eventually we would like all our crates other than `bitcoin` to be able
to be used without an allocator. Currently, and during crate smashing,
this is not that useful because so much of the code comes from `bitcoin`
and relies on the availability of an allocator.

As an initial step, add the `alloc` feature to `addresses` , `base58`,
and `primitives`.

In order to to keep `--no-default-features` builds working make the
crates empty if the `alloc` feature is not enabled. This is a suboptimal
solution because the error messages users will get when they forget to
enable `alloc` will be confusing (eg something like primitives does not
contain Transaction). However our CI script (`run_task.sh`) expects
`--no-default-features` to build cleanly (as do I).
2024-07-11 10:14:50 +10:00
merge-script 5ad78ccc6b
Merge rust-bitcoin/rust-bitcoin#2987: Add `TxIdentifier` trait
a738754f67 Add TxIdentifier trait (Tobin C. Harding)

Pull request description:

  Add a new trait `TxIdentifier` that abstracts over the `Txid` and `Wtxid` types. We make `AsRef` a super trait so that the new trait needs no methods.

  Seal the trait so consumers of the library cannot implement it.

  Use the new trait in:

  - the `bip152` module to tighten up the `with_siphash_keys` function
  - as a trait bound on the `Leaf` associated type in the `MerkleNode` trait

ACKs for top commit:
  apoelstra:
    ACK a738754f67
  Kixunil:
    ACK a738754f67

Tree-SHA512: a7bda26a4a5107f96b24ea3c163286a7ab21a817bdec3434b3ab27d78e99c0548a7362a2271d362b89038c80d9251767c0d62e1df702ef57d9edaf141ab55cd6
2024-07-10 18:28:31 +00:00
merge-script 66b0b52870
Merge rust-bitcoin/rust-bitcoin#2988: Add additional `HashEngine` types
51010777bf hashes: Strongly type the hash160::HashEngine (Tobin C. Harding)
d5dd54a489 hashes: Strongly type the sha256d::HashEngine (Tobin C. Harding)
a7422a779c hashes: Add const hash engine constructors (Tobin C. Harding)

Pull request description:

  Currently we are using a type alias for a few of the hash engines.

  Type alias' allow for potential mixing of types, a struct can better serve our users with not much additional complexity or maintenance burden.

  - As preparation add const constructors where possible to hash engines (excl. `HmacEngine`).
  - Add a `sha256d::HashEngine` struct
  - Add a `hash160::HashEngine` struct

  If this goes in we can improve the `sha256t::HashEngine` in a similar manner.

ACKs for top commit:
  Kixunil:
    ACK 51010777bf
  apoelstra:
    ACK 51010777bf but will hold off on merging until tcharding indicates whether he wants to address the midstate thing

Tree-SHA512: 810db3a8cd66e4d135b04a65d5b4c926cf2e5e8ac531619bbd884db69df17b29b64daeb6fb31b8b1fb32bffbf81cf84e55cd46945c743451c73f1b7f63489f63
2024-07-10 17:46:33 +00:00
merge-script bcfc9dcb20
Merge rust-bitcoin/rust-bitcoin#2989: Move opcodes to `primitives`
9a586987d1 Move opcodes to primitives (Tobin C. Harding)

Pull request description:

  Move the `opcodes` module to the new `primitives` crate. This is pretty straight forward, some things to note:

  - Are we ok with the public wildcard re-export from `blockdata`? I think so because the whole `blockdata` module should, IMO, be deleted after everything in it is moved to `primitives`.

  - `decode_pushnum` becomes public.

ACKs for top commit:
  Kixunil:
    ACK 9a586987d1
  apoelstra:
    ACK 9a586987d1

Tree-SHA512: ee9fa0ae4265f54ff7784dc873abc12572852c32ff24456e34cd6a8a004f9e1f932e01c80d3448107fca76507db4bdaa3dfff6b5a80de0707d59a033e582fb9e
2024-07-10 16:32:52 +00:00
merge-script 00ca5da78b
Merge rust-bitcoin/rust-bitcoin#2990: Use super for imports in script module
afd19ebd61 Use super for imports in script module (Tobin C. Harding)

Pull request description:

  In the `script` module we currently import `script` types using the fully qualified path, as recently discussed code is easier to maintain if we use `super` when `super != crate`.

  Internal change only, no external changes.

ACKs for top commit:
  Kixunil:
    ACK afd19ebd61
  apoelstra:
    ACK afd19ebd61

Tree-SHA512: 5d8546de3d8d9014054fb53020ec0d742eb9698d6d70cd0b2e722b5e43792f4d1ad480d1c61d67b10ddda6a5ef42839118f0de0332251bd64cf31f0a566fd40b
2024-07-10 13:40:29 +00:00
merge-script c40fda2f78
Merge rust-bitcoin/rust-bitcoin#2978: Fixed typo in encode.rs
74ca0195e7 Fixed typo in encode.rs (douglaz)

Pull request description:

ACKs for top commit:
  tcharding:
    ACK 74ca0195e7
  Kixunil:
    ACK 74ca0195e7
  apoelstra:
    ACK 74ca0195e7

Tree-SHA512: 20b52a14c5d7c084de545b0e72c23396378c2be3a3e4c225550433901970521801e225804e56ebb3e7736de7dc31dce2d06ea09e7863a617c3daff46eefb297c
2024-07-09 13:28:18 +00:00
Tobin C. Harding 9a586987d1
Move opcodes to primitives
Move the `opcodes` module to the new `primitives` crate. This is pretty
straight forward, some things to note:

- Are we ok with the public wildcard re-export from `blockdata`? I think
so because the whole `blockdata` module should, IMO, be deleted after
everything in it is moved to `primitives`.

- `decode_pushnum` becomes public.

Includes addition of a `patch` section for `primitives` in the
`bitcoin/embedded` crate.
2024-07-09 15:26:33 +10:00
Tobin C. Harding afd19ebd61
Use super for imports in script module
In the `script` module we currently import `script` types using the
fully qualified path, as recently discussed code is easier to maintain
if we use `super` when `super != crate`.

Internal change only, no external changes.
2024-07-09 15:13:08 +10:00
Tobin C. Harding 51010777bf
hashes: Strongly type the hash160::HashEngine
Currently we are using a type alias for the `hash160::HashEngine`.

Type alias' allow for potential mixing of types, a `hash160::HashEngine`
struct can better serve our users with not much additional complexity or
maintenance burden.

As we did for the `sha256d::HashEngine`, add a new wrapper type
`hash160::HashEngine` that replaces the current type alias.
2024-07-09 13:30:20 +10:00
Tobin C. Harding d5dd54a489
hashes: Strongly type the sha256d::HashEngine
Currently we are using a type alias for the `sha256d::HashEngine`.

Type alias' allow for potential mixing of types, a `sha256d::HashEngine`
struct can better serve our users with not much additional complexity or
maintenance burden.
2024-07-09 13:21:11 +10:00
Tobin C. Harding a738754f67
Add TxIdentifier trait
Add a new trait `TxIdentifier` that abstracts over the `Txid` and
`Wtxid` types. We make `AsRef` a super trait so that the new trait needs
no methods.

Seal the trait so consumers of the library cannot implement it.

Use the new trait in:

- the `bip152` module to tighten up the `with_siphash_keys` function
- as a trait bound on the `Leaf` associated type in the `MerkleNode` trait
2024-07-09 12:28:03 +10:00
merge-script c53d6b7d44
Merge rust-bitcoin/rust-bitcoin#2970: bip152: check if indexes do not overflow
837f466f72 bip152: check if indexes do not overflow (Bruno Garcia)

Pull request description:

  When deserializing a `HeaderAndShortIds` we could check if the number of txs does not overflow 16 bits. If so, throw an error.

ACKs for top commit:
  apoelstra:
    ACK 837f466f72
  Kixunil:
    ACK 837f466f72

Tree-SHA512: 21797689758ae22666289cde123e3e9ae1bdb1ab2f85a1cd0f07ee8fa2a441e7b1b928f30b8fb1f65aef0c526c899eb96b83ed4fff074e70b31e0afad2c35930
2024-07-08 21:57:43 +00:00
merge-script b392510ec1
Merge rust-bitcoin/rust-bitcoin#2889: Move `serde_round_trip` macro to internals
7fa53440dc Move serde_round_trip macro to internals (Tobin C. Harding)

Pull request description:

  We currently duplicate the serde_round_trip macro in `units` and `bitcoin`, this is unnecessary since it is a private test macro we can just throw it in `internals`.

  While we are at it lets improve the macro by testing a binary encoding also, elect to use the `bincode` crate because we already have it in our dependency graph.

  Add `test-serde` feature to `internals` to feature gate the macro and its usage (preventing the transient dependency on `bincode` and `serde_json`).

ACKs for top commit:
  Kixunil:
    ACK 7fa53440dc
  apoelstra:
    ACK 7fa53440dc

Tree-SHA512: f40c78bf2539940b7836ed413d5fe96ce4e9ce59bad7b3f86d831971320d1c2effcd23d0da5c785d6c372a2c6962bf720080ec4351248fbbdc0f2cfb4ffd602c
2024-07-08 20:50:23 +00:00
Jamil Lambert, PhD 58a43b309e Add missing ref keyword
This change ensures that the value is borrowed rather than moved.
2024-07-08 11:15:12 +01:00
douglaz 74ca0195e7
Fixed typo in encode.rs 2024-07-07 23:27:54 +00:00
Fmt Bot 91382977fb 2024-07-07 automated rustfmt nightly 2024-07-07 01:10:59 +00:00
merge-script 59a3b2b683
Merge rust-bitcoin/rust-bitcoin#2855: bitcoin: Update crate level docs
4bb9240992 bitcoin: Add comment to manifest (Tobin C. Harding)
c6c70a721e bitcoin: Update feature docs (Tobin C. Harding)
7712e5d891 bitcoin: Use 100 colum width in crate level docs (Tobin C. Harding)

Pull request description:

  Update stale crate level docs in `bitcoin`. Done as two separate patches so the last one is trivial to review, whitespace only.

ACKs for top commit:
  Kixunil:
    ACK 4bb9240992
  apoelstra:
    ACK 4bb9240992

Tree-SHA512: b9d5474f7e7a0576f535df428ea20084acbcb74d0576e7f2934c547dd2c54f4a939d73ec547b3b254105a45c2372113c65ce136be1eabd63701259a3a6de3737
2024-07-06 13:02:56 +00:00
Tobin C. Harding 7fa53440dc
Move serde_round_trip macro to internals
We currently duplicate the serde_round_trip macro in `units` and
`bitcoin`, this is unnecessary since it is a private test macro we can
just throw it in `internals`.

While we are at it lets improve the macro by testing a binary encoding
also, elect to use the `bincode` crate because we already have it in
our dependency graph.

Add `test-serde` feature to `internals` to feature gate the macro and
its usage (preventing the transient dependency on `bincode` and
`serde_json`).
2024-07-06 14:51:30 +10:00
Bruno Garcia 837f466f72 bip152: check if indexes do not overflow 2024-07-05 17:44:54 -03:00
Tobin C. Harding 4bb9240992
bitcoin: Add comment to manifest
Add a comment to the manifest features section to try to help the docs
not go stale again.
2024-07-05 07:19:41 +10:00
Tobin C. Harding c6c70a721e
bitcoin: Update feature docs
The `bitcoin` crate documents its features in the crate level rustdocs,
currently they are stale.

Update and improve the feature docs section of crate level docs.
2024-07-05 07:19:40 +10:00
Tobin C. Harding 6d3137ed87
bip158: Hash data instead of copying first
Currently we copy data into a new buffer before passing it into the
hasher, we can just hash the data directly.

Internal change only, no external change.

Fix: #2917
2024-07-04 09:30:36 +10:00
merge-script db72ea8b32
Merge rust-bitcoin/rust-bitcoin#2949: OP_RETURN standardness check
15f6bacec9 api: Run just check-api (Ryan Breen)
9684d496bb Add is_standard_op_return (Ryan Breen)

Pull request description:

  This is the suggestion for #2292 to check OP_RETURN length

ACKs for top commit:
  apoelstra:
    ACK 15f6bacec9

Tree-SHA512: e346b5eff7cc40b98a08948c83cb5c064184541d819c37a977e432ec09df7f9e1a074f16a4df598142784bd875f1379e2b0848fe898923e4e12829f85b4c4520
2024-07-02 19:17:54 +00:00
Ryan Breen 9684d496bb Add is_standard_op_return 2024-07-02 08:38:29 -04:00
Jamil Lambert, PhD e8a30bfca7 taproot: Lowercase error messages
By convention error messages should not be capitalised or use full
stops.

Fix the `taproot` module error messages.
2024-07-01 17:42:43 +01:00
Jamil Lambert, PhD 717da4bf69 Capitalize Huffman
Huffman is a proper noun and should be capitalized in docs and strings.

Capitalize all occurances of Huffman in docs and strings.
2024-07-01 17:42:43 +01:00
Jamil Lambert, PhD 175f69abeb Capitalize Merkle
Merkle is a proper noun and should be capitalized in docs and strings.

Capitalize all occurances of Merkle in docs and strings.
2024-07-01 17:42:43 +01:00
Jamil Lambert, PhD be5b93ea4f Do not capitalize tree
Change tree to lower case except when title case is being used.
2024-07-01 17:42:43 +01:00
Jamil Lambert, PhD b48ca050f9 Remove tap tree
tap tree should be either Taproot tree in normal language or
[`TapTree`] when referring to the struct.

Change all occurances of tap tree or taptree.
2024-07-01 17:42:42 +01:00
Jamil Lambert, PhD c8e6c13608 Capitalize Taproot
Taproot is a proper noun and should be capitalized in docs and strings.

Make all occurrences of Taproot in comments or strings capitalized.
2024-07-01 17:42:36 +01:00
merge-script 9b089d42c7
Merge rust-bitcoin/rust-bitcoin#2890: Move `serde` string macros to internals
865ba3fc39 Move serde string macros to internals (Tobin C. Harding)
4a2b13fcde internals: Feature gate whole serde module (Tobin C. Harding)

Pull request description:

  The macros are internal things and can live in `internals`. This will help with future crate smashing.

ACKs for top commit:
  apoelstra:
    ACK 865ba3fc39
  Kixunil:
    ACK 865ba3fc39

Tree-SHA512: 7b3f029206c690ecf2894e0ad099d391312f7f8ec65ac9b5d4d9f25e6827f92075dcc851d0940a0faf1e27e7d0a305b575c8cc790939b3f222d7a2920d4d24fe
2024-07-01 01:09:00 +00:00
merge-script 45e311cab9
Merge rust-bitcoin/rust-bitcoin#2930: Improve docs on private `Witness` fields
c717f7f424 Improve docs on private Witness fields (Tobin C. Harding)

Pull request description:

  The `Witness` type is a reasonable complex data structure, make an effort to clarify its structure in the docs on the private fields.

  Private docs only.

  (Original idea pulled out of #2133.)

ACKs for top commit:
  Kixunil:
    ACK c717f7f424
  apoelstra:
    ACK c717f7f424 much clearer, thanks!

Tree-SHA512: 9d54b7eeefec97e584fb5f275049dbac0473c949fae8ab05c6961d6fc424c17a058af7037c2220ef1446af294d78c68bfee741cfeca1b18ecc402935d8069dab
2024-06-30 22:48:18 +00:00
merge-script 96dffb2152
Merge rust-bitcoin/rust-bitcoin#2939: Automated nightly rustfmt (2024-06-30)
19b093080b 2024-06-30 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 19b093080b

Tree-SHA512: 50d905ab4823e5e746751c0aacd145fc5640c9cb250d99bcd44800c72a890562c0014a9eee21602198388dee7bd9354ff764bab5616aac82bf7660669f8c2ee1
2024-06-30 12:09:40 +00:00
merge-script d36141b5a7
Merge rust-bitcoin/rust-bitcoin#2892: Remove wildcard imports
d099b9c195 Remove wildcard from prelude import (Jamil Lambert, PhD)

Pull request description:

  This patch replaces  `prelude::*` wildcard imports with the types actually used.  In a couple of cases `DisplayHex` was previously imported by the wildcard but was only used in the test module, an additional import was added to the test module instead of at the top where it causes an unused import warning.

  Close: #2875

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

Tree-SHA512: d59dfac0961d2649d509039a11c1b5574d81d05fef567a624cf15be2f587de796ea960ba5a08bef788199331c2f790fb06f7b393182538c7d8b1891ded119efc
2024-06-30 04:04:08 +00:00
Fmt Bot 19b093080b 2024-06-30 automated rustfmt nightly 2024-06-30 01:10:26 +00:00
Tobin C. Harding c717f7f424
Improve docs on private Witness fields
The `Witness` type is a reasonable complex data structure, make an
effort to clarify its structure in the docs on the private fields.

Private docs only.
2024-06-30 06:04:33 +10:00
merge-script 35202ba51b
Merge rust-bitcoin/rust-bitcoin#2932: Remove `bech32` dependency from `blockdata`
010141ecc9 api: Run just check-api (Tobin C. Harding)
cf800a1b07 Remove bech32 dependency from blockdata (Tobin C. Harding)

Pull request description:

  We have a single usage of the `bech32` crate inside the `blockdata` module, to convert a `WitnessVersion` to a `Fe32`. We then have a single call site where we use the conversion in the `address` module.

  This code was written without thinking to hard about the introduced dependency on `bech32`, in hindsite it shouldn't have been added.

  In preparation for splitting a bunch of code in `blockdata` out into the `primitives` crate remove the `bech32` stuff from the `witness_version` module.

ACKs for top commit:
  Kixunil:
    ACK 010141ecc9
  apoelstra:
    ACK 010141ecc9

Tree-SHA512: 2d368ebf64ab7197b421e0dec48623f3fb03243081a988ff9ed2070135c8741efe24520c2aab496d54c52595808f10ee39816eaab8e3e4a7e64955cd25285670
2024-06-29 12:51:45 +00:00
merge-script ae90d1930b
Merge rust-bitcoin/rust-bitcoin#2909: bip32: add From<&'a [u32]> for DerivationPath
a7731b2f33 api: Run just check-api (Marko Bencun)
47cba7a655 bip32: add from_32_slice method to DerivationPath (Marko Bencun)

Pull request description:

  ChildNumber already has a `From<u32>` impl, but converting `&[u32]` to a `DerivationPath` was still difficult.

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

Tree-SHA512: 2db94ee035e686102b8201f637422bb96bd79858aeffdb007594d722902d31a20f27e61b88fae8c854c80f785d9e7837b0158a046639ff8cc2d20d8883391842
2024-06-29 00:23:45 +00:00
merge-script 7ca7128b19
Merge rust-bitcoin/rust-bitcoin#2899: Pass sigs and associated types by value
dc10a49876 api: Run just check-api (Tobin C. Harding)
5e8f204581 Pass sigs and associated types by value (Tobin C. Harding)

Pull request description:

  We should pass `Copy` types by value not by reference.

  Currently this is not done in secp, but lets do it here in bitcoin.

  Pass by value:

  - `SerializedSignature`
  - bitcoin sigs
  - secp sigs
  - secp `Message`

  This is a continuation of the work to split up #2404 into manageable PRs.

ACKs for top commit:
  apoelstra:
    ACK dc10a49876
  Kixunil:
    ACK dc10a49876

Tree-SHA512: 8736eba067c74edb951c92357f5b3d0fc99c4fa6dc3beea579c10b3150873b74e8ec46c2c01f18818b37fca6e77c6b6edddeb6340edde6a9d8c28a4e69164c8c
2024-06-28 23:48:03 +00:00
merge-script 6e1fe5e1c1
Merge rust-bitcoin/rust-bitcoin#2886: taproot: Split errors up
6a7f780018 api: Run just check-api (Tobin C. Harding)
0c9223ac05 Manually format write_err statement (Tobin C. Harding)
43d7c750cc taproot: Add error types (Tobin C. Harding)
afe41c8a39 taproot: Split errors up (Tobin C. Harding)

Pull request description:

  Currently there are a couple of errors in the `taproot` module that are too general, resulting in functions that return a general error type when a specific one would do.

  Split two errors out and use them for for enum variants and function returns as possible.

  Done as part of #2883

ACKs for top commit:
  Kixunil:
    ACK 6a7f780018
  apoelstra:
    ACK 6a7f780018

Tree-SHA512: bf5ed50dd8f913280d007f03124c7918c4b6cd642e67726bc3ffff23d9897f764a4391e167115668c3a1e951197485eba280fdbb8a0ce1bb7efb051388d13997
2024-06-28 19:50:37 +00:00
Jamil Lambert, PhD d099b9c195 Remove wildcard from prelude import
Wildcards have been replaced with what is actually used.

In a couple of cases an additional use statement was added to the test
module to import `DisplayHex` which is only used in test, but
previously imported with the wildcard at the top.
2024-06-28 08:02:43 +01:00
Tobin C. Harding cf800a1b07
Remove bech32 dependency from blockdata
We have a single usage of the `bech32` crate inside the `blockdata`
module, to convert a `WitnessVersion` to a `Fe32`. We then have a single
call site where we use the conversion in the `address` module.

This code was written without thinking to hard about the introduced
dependency on `bech32`, in hindsite it shouldn't have been added.

In preparation for splitting a bunch of code in `blockdata` out into the
`primitives` crate remove the `bech32` stuff from the `witness_version`
module.
2024-06-28 08:30:45 +10:00
merge-script 326a6dce55
Merge rust-bitcoin/rust-bitcoin#2895: Re-export UnprefixedHexError in the bitcoin crate root
10440b36a2 api: Run just check-api (Shing Him Ng)
452a7cc091 Re-export public functions, enums, and structs from units::parse in the bitcoin crate root (Shing Him Ng)

Pull request description:

  Re-export UnprefixedHexError in the bitcoin crate root

  Fixes #2874

ACKs for top commit:
  tcharding:
    ACK 10440b36a2

Tree-SHA512: 78a0676aa6d6fe63d810eeeebd3bf053d679d966d0aebf752760bfb440b2d4e831b0ff6b54b0306b390126b3f96a70c0846b4a1ec20aca96994d4a7b75e438e3
2024-06-27 20:00:10 +00:00
merge-script 848256c6a9
Merge rust-bitcoin/rust-bitcoin#2921: Make 'use core::fmt' calls consistent
8ee1744b9b Make 'use core::fmt' calls consistent (Shing Him Ng)

Pull request description:

  I started taking a look at #2869 and looked for everything that was implementing the `Display` trait:

  ```rust
  impl fmt::Display for _
  ```

  but found some places where the imports weren't consistent:
  ```rust
  impl Display for _
  ```

  There were only a few instances of the latter, so I went ahead and cleaned those up before starting #2869

  I started pulling this thread when I saw the same thing was happening for `fmt::Debug` and `fmt::Formatter` so I updated the rest of the `use core::fmt::*` statements with a few exceptions:

  - No updates to `use core::fmt::*` if it was being called from within a function since I felt like the function scope was small enough to not cause confusion
  - No updates to `use core::fmt::{self, Write as _};`

ACKs for top commit:
  Kixunil:
    ACK 8ee1744b9b
  tcharding:
    ACK 8ee1744b9b

Tree-SHA512: 33eb6ea0c4e808ef78bc87de6547144b756bde206c50d80488f740e97cd8d11f1abcb8936c487d7bfd29be5e21c7f40ff88f82acdaaec9aacb4b6362ffc4c680
2024-06-27 15:40:06 +00:00
merge-script 0f3a9969fd
Merge rust-bitcoin/rust-bitcoin#2915: Clean up manifests
bc25ed35d5 Order serde feature list alphabetically (Tobin C. Harding)
5bd3387c15 Move package metadata to be underneath package section (Tobin C. Harding)
a2a9f193fe Put workspace crates in alphabetical order (Tobin C. Harding)
05931cc0fa Run the formatter (Tobin C. Harding)

Pull request description:

  We are getting an increasing number of crates in the repo, clean up the manifests a bit in an endevour to help keep things manageable.

  All  patches are trivial and the PR makes no logic changes.

ACKs for top commit:
  Kixunil:
    ACK bc25ed35d5
  apoelstra:
    ACK bc25ed35d5

Tree-SHA512: a9850449a6f71ac5d53f501e36175e900bf4986f44c7636d3b1b55df80804b92bb10d8da7798f6bb866722aa2354ad2880ab5c0f5c4633f198c137d2ca42b7c9
2024-06-27 14:30:18 +00:00
Marko Bencun 47cba7a655
bip32: add from_32_slice method to DerivationPath
ChildNumber has a `From<u32>` impl, but converting `&[u32]` to a
`DerivationPath` was still difficult.
2024-06-27 15:27:57 +02:00
Shing Him Ng 452a7cc091 Re-export public functions, enums, and structs from units::parse in the bitcoin crate root 2024-06-26 12:46:31 -05:00
Shing Him Ng 8ee1744b9b Make 'use core::fmt' calls consistent 2024-06-26 09:41:06 -05:00
Jamil Lambert 1147e66896 Remove unnecessary braces
This causes rust-analyzer to flag a warning.

Remove unnecessary braces to get rid of rust-analyzer warning.
2024-06-26 14:33:06 +01:00
Tobin C. Harding 0c9223ac05
Manually format write_err statement
The formatter doesn't touch this line but its not uniform with the
surrounding code.
2024-06-26 15:27:05 +10:00
Tobin C. Harding 43d7c750cc
taproot: Add error types
Add two more error types so that the `TaprootError` has all its variants
strongly typed.
2024-06-26 15:25:55 +10:00
Tobin C. Harding afe41c8a39
taproot: Split errors up
Currently there are a couple of errors in the `taproot` module that are
too general, resulting in functions that return a general error type
when a specific one would do.

Split two errors out and use them for for enum variants and function
returns as possible.
2024-06-26 15:23:05 +10:00
Andrew Poelstra 40d1335f08
Merge rust-bitcoin/rust-bitcoin#2897: psbt: implement `const` for `PsbtSighashType::ALL`
2bde5d002e api: Run just check-api (Jose Storopoli)
d1f84329e4 psbt: implement const for PsbtSighashType::ALL (Jose Storopoli)

Pull request description:

  Closes #2751.

  I only did the `ALL` which is by far the most common case.

ACKs for top commit:
  tcharding:
    ACK 2bde5d002e
  apoelstra:
    ACK 2bde5d002e

Tree-SHA512: 693575de758657a3e172d86ba5114ec0bf3b12b82df598e38c6a7916c99c20cfb5c4e74442108b51ae4e7bb1f1e940fd4a7269145e3f9838f727675c7711c890
2024-06-25 17:33:06 +00:00
Tobin C. Harding bc25ed35d5
Order serde feature list alphabetically
Do minor refactor to put the list of enables in alphabetic order.

Done in preparation for adding the `primitives` crate.
2024-06-25 10:02:30 +10:00
Tobin C. Harding 5bd3387c15
Move package metadata to be underneath package section
The package metatadata never changes and is not necessary to look at
basically ever, put it down the bottom of the manifest out of the way.

Helps to keep features and dependencies closer together.

Refactor only, no logic changes.
2024-06-25 10:02:27 +10:00
Tobin C. Harding 05931cc0fa
Run the formatter 2024-06-25 10:02:03 +10:00
Andrew Poelstra 91265977f8
hashes: stop exposing engine/from_engine and general hashing methods in hash_newtype
We manually implement these methods (and the GeneralHash trait) on newtypes
around sha256t::Hash, because tagged hashes require a bit more work. In
the next commit (API diff) you will see that this affects two hashes,
which are the only things that appear green in the diff.

Users who want to implement their own engine/from_engine types now need
to do it on their own. We do this for the non-Taproot sighash types in
`bitcoin` (though only privately) to demonstrate that it's possible.
2024-06-24 13:58:05 +00:00
Andrew Poelstra 8c4899f2cc
bitcoin: remove all direct use of hashing/engines in unit tests
This is a continuation of the previous commit, but separated to make
review a little easier. This one replaces test vectors that were
previously computed by hashing garbage into Txids and various other hash
types with new test vectors which are directly-computed garbage
converted to hashes with from_byte_array.

In one case (src/hash_types.rs) this results in changing a bunch of
fixed test vectors. This is okay; this test is supposed to check the
direction of string serialization, which is unaffected by this commit
(or any commit in this PR). The existing test vectors, because they hash
the empty string, result in different bytes depending on the underlying
hash algo (sha256, sha256d, sha256t, etc). The new ones just use the
same fixed test vector for all of them.

This commit also updates a doctest in crypto/sighash.rs which
demonstrates how to manually feed sighash data into a hash engine and
correctly handle the sighash single bug. Because you can no longer
directly get a sighash object from an engine, this particular example
should maybe be rewritten to just encode to a Vec rather than a hash
engine, explaining that maybe you'd do this when implementing a HWW, to
verify the exact data being hashed. Or something.

Unrelatedly, you can check that there are no API changes in this commit
or the last several. The next commit will remove GeneralHash impls and
that's when you'll see changes.
2024-06-24 13:58:03 +00:00
Andrew Poelstra b8d85a1df0
bitcoin: remove all use of engine/from_engine on opaque hash types
In the next commits we are going to stop exposing the ability to hash
arbitrary data into wrapped hash types like Txid etc. In preparation for
this, stop using these methods internally.

This makes our internal code a little bit uglier and less DRY. An
alternative approach would be to implement the from_engine and engine
methods, but privately (and maybe having a macro to provide this). But I
think this approach is more straightforward.

The one exception is for the Taproot hashes, which are tagged hashes and
currently do not have their own engine type. I will address these in a
later PR because this one is already too big.
2024-06-24 13:57:03 +00:00
Andrew Poelstra 73dcc79763
hashes: split Hash trait into two 2024-06-24 13:28:54 +00:00
Jose Storopoli d1f84329e4
psbt: implement const for PsbtSighashType::ALL 2024-06-24 08:55:01 +00:00
Andrew Poelstra b904de375a
Merge rust-bitcoin/rust-bitcoin#2877: hashes: remove `all_zeros` and constify constructors
4652ce20ed API changes for "delete `all_zeros`" (Andrew Poelstra)
8869f35a69 hashes: drop the `all_zeros` method on arbitrary hashes (Andrew Poelstra)
9f8797f486 API changes for constification of hash constructors (Andrew Poelstra)
154e91af8c hashes: constify a bunch of constructors (Andrew Poelstra)
c155cbf8b2 hashes: use workaround to get constfns on tagged hashes with MSRV (Andrew Poelstra)

Pull request description:

  I think these changes are both uncontroversial but they have fairly large diffs so I am PRing them together before making more invasive changes.

ACKs for top commit:
  tcharding:
    ACK 4652ce20ed

Tree-SHA512: 4560fa397deab50448598894b9364f9d8f8b48169901a84db6a44168cdba795ab69b48ad2cac61caebcee5e227a03271335b405cf5514265290a4d1f2fdf52a2
2024-06-24 04:15:47 +00:00
Tobin C. Harding 7712e5d891
bitcoin: Use 100 colum width in crate level docs
We have various different column widths being used in a single rustdoc
block, since we favour 100 for comments around here use it.

No text changes, whitespace only.
2024-06-24 11:19:54 +10:00
Tobin C. Harding 5e8f204581
Pass sigs and associated types by value
We should pass `Copy` types by value not by reference.

Currently this is not done in secp, but lets do it here in bitcoin.

Pass by value:

- `SerializedSignature`
- bitcoin sigs
- secp sigs
- secp `Message`
2024-06-24 10:02:55 +10:00
Andrew Poelstra ae8b0b1610
Merge rust-bitcoin/rust-bitcoin#2896: Move `PushBytes::read_scriptint` outside of the `private` module
aebf216619 Use 100 column width for rustdoc (Tobin C. Harding)
c71ae9ac16 Move PushBytes::read_scriptint (Tobin C. Harding)

Pull request description:

  The `push_bytes` module has a `private` module that exists solely to protect the invariant on the `PushBytes` inner byte slice. There is a `PushBytes` impl block outside the private module for functions that can not and do not violate the length invariant.

  Recently we move the `read_scriptint` method to be on the `PushBytes` but we put it inside the `private` module, since the method only reads off of the slice it cannot invalidate the invariant and does not need to be inside the `private` module.

  Move the `read_scriptint` method outside of the `private` module to keep that module as small as possible, helping with its stated aim of being the only place that requires auditing.

  Patch 2 is whitespace only.

ACKs for top commit:
  Kixunil:
    ACK aebf216619
  apoelstra:
    ACK aebf216619

Tree-SHA512: f41eb691e7118a74767a2582a637a176a46e4a8d15259f1c1f3cef67bc57dd8dce4974407c5a5e31acd0b4665f722b20acad4e381747c9d496f18158a0ef9def
2024-06-23 23:57:41 +00:00
Andrew Poelstra 09740853a9
Merge rust-bitcoin/rust-bitcoin#2887: Remove `InvalidInternalKey` variant from `TaprootBuilderError`
72655607b6 api: Run just check-api (Tobin C. Harding)
e8250cd96a Remove InvalidInternalKey variant from TaprootBuilderError (Tobin C. Harding)

Pull request description:

  This variant is unused, remove it.

  Done as part of #2883.

ACKs for top commit:
  Kixunil:
    ACK 72655607b6
  apoelstra:
    ACK 72655607b6

Tree-SHA512: 5cd27cacebcf078afdf1ceba4e3d51e78f20ee4883000b766efb7a246fd7a166240038a2e7d27249a22049c3258673a393ff2fd62cb4b27a2cade04b28ef2ac9
2024-06-23 00:18:01 +00:00
Andrew Poelstra ed514b422d
Merge rust-bitcoin/rust-bitcoin#2880: Pass hash types by value
433fd6bf7e api: Run just check-api (Tobin C. Harding)
8fd583b069 Pass hash types by value (Tobin C. Harding)

Pull request description:

  We should pass `Copy` types by value not by reference. Pass the hash types by value.

  Second step in the pass-copy-types-by-value work, pulled out of #2404.

ACKs for top commit:
  apoelstra:
    ACK 433fd6bf7e
  Kixunil:
    ACK 433fd6bf7e

Tree-SHA512: 999d12f60550cacc4ae19b4cbf505b25c1eed803820f22b1a706e9f95da1b7e7b422f393f4115d579927c0c476cd504036a39b3cdc06a1d6befbcff5513f7433
2024-06-22 19:42:24 +00:00
Andrew Poelstra 0554c2825f
Merge rust-bitcoin/rust-bitcoin#2878: Implement constants for `ChildNumber` enum
39df0a9fbe update api (Divyansh Gupta)
3a5f2932a4 create constants for ChildNumber enum (Divyansh Gupta)

Pull request description:

  this aims to fix #2750

ACKs for top commit:
  tcharding:
    ACK 39df0a9fbe

Tree-SHA512: e1c38568facd2b9aa55b1b1ec0d5d5f68ff38ca3fe68962bc316c060a062299935aa51bcfc1c255a7f5c9ad97435cab22e2c160d3fd3f52a46f6b5cbb7d5743f
2024-06-22 18:54:32 +00:00
Andrew Poelstra 8869f35a69
hashes: drop the `all_zeros` method on arbitrary hashes
Manually implement it for Wtxid, Txid and BlockHash, where the all-zero
"hash" has a consensus meaning. But in general we should not be
implementing this method unless we have a good reason to do so. It can
be emulated or implemeted in terms of from_byte_array.

The use of Wtxid::all_zeros is obscure and specific enough that I am
tempted to drop it. But for txid and blockhash, the 0 hash appears in
actual blockdata and we should keep it.

All other uses of all_zeros were either in test code or in places where
the specific hash was not important and [u8; 32] was a more appropriate
type.
2024-06-22 15:09:28 +00:00
Tobin C. Harding aebf216619
Use 100 column width for rustdoc
We use 100 column width for rustdoc in this project, while not a super
hard rule the docs on `read_scriptint` are long, using the 100 column
width reduces the line count a reasonable amount.

No text changes, only whitespace.
2024-06-22 08:21:48 +10:00
Tobin C. Harding c71ae9ac16
Move PushBytes::read_scriptint
The `push_bytes` module has a `private` module that exists solely to
protect the invariant on the `PushBytes` inner byte slice. There is a
`PushBytes` impl block outside the private module for functions that can
not and do not violate the length invariant.

Recently we move the `read_scriptint` method to be on the `PushBytes`
but we put it inside the `private` module, since the method only reads
off of the slice it cannot invalidate the invariant and does not need
to be inside the `private` module.

Move the `read_scriptint` method outside of the `private` module to keep
that module as small as possible, helping with its stated aim of being
the only place that requires auditing.
2024-06-22 08:21:47 +10:00
Andrew Poelstra 817e54fb83
Merge rust-bitcoin/rust-bitcoin#2885: Remove usage of blockdata from paths
a42bcdc22e Remove usage of blockdata from paths (Tobin C. Harding)

Pull request description:

  the `blockdata` directory is code organisation thing, all the types/modules are re-exported from other places. In preparation for, and to make easier, the `primitives` crate smashing work - remove all explicit usage of `blockdata`.

  Note that the few instances remain as they seem required e.g.,

    `pub(in crate::blockdata::script)`

  Refactor only, no logic changes.

  Done as part of #2883

ACKs for top commit:
  apoelstra:
    ACK a42bcdc22e lgtm! I consider this "trivial" and will one-ACK merge it

Tree-SHA512: 310605e5203cf04aaeb91fe5512677b8f1438b183916686ba2cdc41ffdc18af7a0676206724e8a14c50ce6ed8faa9d48c69a2d5149eb1f56ae9c5f276fc5200f
2024-06-20 23:25:21 +00:00
Andrew Poelstra 6908d45417
Merge rust-bitcoin/rust-bitcoin#2858: clarify the meaning of `Height` & `Time` based locktime.
16e4d22693 clarify the meaning of Height & Time based locktime. (Divyansh Gupta)

Pull request description:

  this pr aims to fix : #2697

ACKs for top commit:
  apoelstra:
    ACK 16e4d22693
  tcharding:
    ACK 16e4d22693

Tree-SHA512: 55757d7e593cb284aff7040cf3298931c7f3d8e9e36d7328bd748a39be743e5c4202c55505add0219b2766d35d1660affc5ed4a7b9480b3a3bfb89982fe3970a
2024-06-20 14:27:50 +00:00
Divyansh Gupta 3a5f2932a4 create constants for ChildNumber enum
These constants are ->
   * `ONE_NORMAL` & `ZERO_NORMAL`
   * `ZERO_HARDENED` & `ONE_HARDENED`
2024-06-20 10:19:11 +05:30
Tobin C. Harding 865ba3fc39
Move serde string macros to internals
The macros are internal things and can live in `internals`. This will
help with future crate smashing.
2024-06-20 14:25:43 +10:00
Tobin C. Harding e8250cd96a
Remove InvalidInternalKey variant from TaprootBuilderError
This variant is unused, remove it.

Done as part of #2883.
2024-06-20 13:03:59 +10:00
Tobin C. Harding a42bcdc22e
Remove usage of blockdata from paths
the `blockdata` directory is code organisation thing, all the
types/modules are re-exported from other places. In preparation for, and
to make easier, the `primitives` crate smashing work - remove all
explicit usage of `blockdata`.

Note that the few instances remain as they seem required e.g.,

  `pub(in crate::blockdata::script)`

Refactor only, no logic changes.
2024-06-20 12:00:22 +10:00
Tobin C. Harding 8fd583b069
Pass hash types by value
We should pass `Copy` types by value not by reference. Pass the hash
types by value.
2024-06-20 09:09:58 +10:00
Divyansh Gupta 16e4d22693 clarify the meaning of Height & Time based locktime. 2024-06-19 20:14:04 +05:30
Andrew Poelstra 90b6d6748b
merkle_tree: remove some now-redundant code from block.rs 2024-06-18 16:11:37 +00:00
Andrew Poelstra f7ce9bbee8
merkle_node: rewrite algorithm
Drop recursion, reduce memory usage to be logarithmic in size of tree
rather than linear, and put it all in one function rather than three.

Also make the method an trait method on MerkleNode which makes it a
easier on type inference, by writing e.g. TxMerkleNode::calculate_root.
2024-06-18 16:11:32 +00:00
Andrew Poelstra 8d5cb014ce
merkle_tree: introduce MerkleNode trait to better-type merkle tree calculation 2024-06-17 19:10:26 +00:00
Andrew Poelstra 5d8aa94069
Move merkle_tree hash types
Currently we are defining the two merkle tree hash types in the `block`
module, a better home for them is the `merkle_tree` module.

This is an API breaking change because the types were public in the
`block` module, however the change should/could be unnoticeable to users
if they use the crate level re-export - which is maintained.
2024-06-17 19:10:23 +00:00
Andrew Poelstra 0ae6f49cea
Merge rust-bitcoin/rust-bitcoin#2872: Update PushBytes::read_scriptint(x) to x.read_scriptint()
e7f33a2a12 Update PushBytes::read_scriptint(x) to x.read_scriptint() (Shing Him Ng)

Pull request description:

  Fixes #2849

  There were a few other usages of PushBytes::read_scriptint(_) in the tests such as [this](406e3486ab/bitcoin/src/blockdata/script/tests.rs (L315)), but they couldn't be updated as cleanly as the changes in this PR. I wasn't sure if the intention of this issue was to fix those as well, but I can update this PR if needed

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

Tree-SHA512: 4620f4972c40b0bf7333dbe302d1dabc5dbcb39749c734cc297a019d36983757f59659d76ae40b4a6121e51d0bde1e2b7883a0c77536be18927d1cfef53ba579
2024-06-17 16:24:01 +00:00
Tobin C. Harding e87a54f617
Enforce script size limit when hashing scripts
There are two limits that the Bitcoin network enforces in regard to
hashing scripts

- For P2SH the redeem script must be less than 520 bytes
- For P2WSH the witness script must be less than 10,000 bytes

Currently we are only enforcing the p2sh limit when creating an address
with `Address::p2sh`.

There are various ways to create addresses from script hashes and if
users manually hash a script then use the `ScriptHash` (or
`WScritpHash`) our APIs assume the script that was hashed is valid. This
means there is the potential for users to get burned by creating
addresses that cannot be spent, something we would like to avoid.

- Add fallible constructors to `ScriptHash` and `WScriptHash`
- Add `TryFrom` impls as well to both types
- Remove the `From` impls
2024-06-17 10:32:03 +10:00
Tobin C. Harding 4686d48ec4
Rename p2wsh script to witness_script
The script in a p2wsh is typically referred to as the witness script not
the redeem script - rename the local test variable to follow suit.

Refactor only, no logic changes.
2024-06-17 10:25:24 +10:00
Tobin C. Harding 9cdb514434
Remove odd script hash test
This test does an odd combination of function calls, its not obvious
what it is supposed to be testing. The `to_p2wsh.is_p2wsh` is already
tested above. The leading `to_p2sh` does not prove anything, one can put
currently pass any script to `to_p2wsh` so this tests nothing.

In preparation for patching the script hashing functionality first
remove this odd test.
2024-06-17 10:25:24 +10:00
Shing Him Ng e7f33a2a12 Update PushBytes::read_scriptint(x) to x.read_scriptint() 2024-06-16 17:11:33 -05:00
Fmt Bot 4745b55cae 2024-06-16 automated rustfmt nightly 2024-06-16 01:09:27 +00:00
Andrew Poelstra 45fe754ae3
Merge rust-bitcoin/rust-bitcoin#2865: Refactor test module in `merkle_tree/block.rs`
3f4eb07769 Add a comment to regression test (Jamil Lambert, PhD)
fc2876ba10 Move use statements to top of module (Jamil Lambert, PhD)
778a44dd64 Refactor merkle block test (Jamil Lambert, PhD)
c4c1252a9e Change encode path (Jamil Lambert, PhD)

Pull request description:

  Refactored the `extract_matches_from_merkleblock()` test function following https://github.com/rust-bitcoin/rust-bitcoin/pull/2859#issuecomment-2161710169.

  Moved use statements to the top of the test module and changed it to use one level of path instead of importing the function names.  e.g. `encode::serialize()` instead of `serialize()`.

  Added the missing comment to the `regression_2606()` test.  I was not sure where the hex value came from that was used to test that the deserialization fails.  The comment was generated by copilot and may need to be edited, it does fit with the error given by deserialize: `OversizedVectorAllocation { requested: 12811880876963004416, max: 4000000 }`.

ACKs for top commit:
  tcharding:
    ACK 3f4eb07769
  apoelstra:
    ACK 3f4eb07769 the `prelude::*` is fine since it was already there since #298, but FYI I would not have accepted it today

Tree-SHA512: 203a30eee51ea91051cb10d5d7dd55b560d9d4d785120143c9fb29ea26ec77696124adc9c5bcb8cd736a7d293b897e665958bec5f66626a5c1c95c98b6029e0d
2024-06-15 03:12:23 +00:00
Andrew Poelstra 4defdb08fa
Merge rust-bitcoin/rust-bitcoin#2868: Pass keys by value
9f01871c11 api: Run just check-api (Tobin C. Harding)
7929b51640 Pass keys by value (Tobin C. Harding)

Pull request description:

  We should pass `Copy` types by value not by reference. Pass the key types by value.

  This is patch 1 from #2404

ACKs for top commit:
  apoelstra:
    ACK 9f01871c11 this will annoy some people but I think we should do it

Tree-SHA512: 18afab537edf4ade4dc1c1e5992e50060b8935531f1e3cbe1d3b94b2fcb87aafa39947f342e0e762835bda3b4091dd35b3b74ea79f4dbb3b21660ffd21d1f82e
2024-06-14 23:56:46 +00:00
Andrew Poelstra 72ce271b6b
Merge rust-bitcoin/rust-bitcoin#2852: Add inherent functions to hashes
18b2788a5a api: Run just check-api (Tobin C. Harding)
6b7d02e5ae Add inherent functions to hashes (Tobin C. Harding)

Pull request description:

  Currently we have a trait `Hash` that is required for `Hmac`, `Hkdf`, and other use cases. However, it is unegonomic for users who just want to do a simple hash to have to import the trait.

  Add inherent functions to all hash types including those created with the new wrapper type macros.

  This patch introduces some duplicate code but we are trying to make progress in the hashes API re-write. We can come back and de-dublicate later.

  Includes making `to_byte_array`,`from_byte_array`, `as_byte_array`, and `all_zeros` const where easily possible.

ACKs for top commit:
  apoelstra:
    ACK 18b2788a5a

Tree-SHA512: 6b7a8d8a8501e981416d767040e5bd9fa8d1134be2ca133b5c53aa55f65c8456dccb63b642e30d0d571ca838c6f9eaeff6527d92a9b4212819a49ce619c4e093
2024-06-14 16:30:52 +00:00
Jamil Lambert, PhD 3f4eb07769 Add a comment to regression test
The comment at the top was generated by AI
2024-06-14 10:33:39 +01:00
Jamil Lambert, PhD fc2876ba10 Move use statements to top of module
Moved all of the use statements to the top of the tests module.

Change to have one level of path instead of importing the function name.
2024-06-14 10:33:39 +01:00
Jamil Lambert, PhD 778a44dd64 Refactor merkle block test
Refactored the unit test as suggested in
https://github.com/rust-bitcoin/rust-bitcoin/pull/2859#issuecomment-2161710169
2024-06-14 10:33:39 +01:00
Jamil Lambert, PhD c4c1252a9e Change encode path
Change the path for `consensus::encode` to use one level of path instead of importing the function name
2024-06-14 10:33:20 +01:00
Tobin C. Harding 7929b51640
Pass keys by value
We should pass `Copy` types by value not by reference. Pass the key
types by value.
2024-06-14 14:16:28 +10:00
Tobin C. Harding 6b7d02e5ae
Add inherent functions to hashes
Currently we have a trait `Hash` that is required for `Hmac`, `Hkdf`,
and other use cases. However, it is unegonomic for users who just want
to do a simple hash to have to import the trait.

Add inherent functions to all hash types including those created with
the new wrapper type macros.

This patch introduces some duplicate code but we are trying to make
progress in the hashes API re-write. We can come back and de-dublicate
later.

Includes making `to_byte_array`,`from_byte_array`, `as_byte_array`, and
`all_zeros` const where easily possible.
2024-06-14 10:17:00 +10:00
Andrew Poelstra 59d06f7073
Merge rust-bitcoin/rust-bitcoin#2859: Moved private doctest to unit test
8d256b4e79 Moved doctest to unit test (Jamil Lambert, PhD)

Pull request description:

  Moved the doctest from the private module to a unit test to fix: #2840

ACKs for top commit:
  apoelstra:
    ACK 8d256b4e79
  tcharding:
    ACK 8d256b4e79

Tree-SHA512: 233961288579381cb5c51235331c78c9980046f0317a2062cb108a2e604adde322e2dd834e724d1fe05f54f92721fe6c9f5344dcf930f99aa3756a698ddf9732
2024-06-13 13:20:32 +00:00
Jamil Lambert, PhD 8d256b4e79 Moved doctest to unit test
Moved the doctest from the private module to a unit test, since it does not appear in doc.rs.
2024-06-12 16:00:28 +01:00
Andrew Poelstra c4f2f2454f
Merge rust-bitcoin/rust-bitcoin#2816: make difficulty_float general to all network
fcf27a62a2 update api (Divyansh Gupta)
531aba0cf1 make `difficulty_float` general to all network (Divyansh Gupta)

Pull request description:

  Fix #2783

ACKs for top commit:
  tcharding:
    ACK fcf27a62a2
  apoelstra:
    ACK fcf27a62a2

Tree-SHA512: aec9648b057677b89f4f397e1fa703ed6496436bd6e1e8052d5b7f52ef52c95b286babd425d97fe7d4f903cd0a3d68ae589d8fb255fc68f423714918cd485873
2024-06-12 13:34:44 +00:00
Divyansh Gupta 531aba0cf1 make `difficulty_float` general to all network 2024-06-12 09:22:40 +05:30
Andrew Poelstra 76b0060c4d
Merge rust-bitcoin/rust-bitcoin#2856: bitcoin: Remove "std" feature from examples
091d614aad bitcoin: Remove "std" feature from examples (Tobin C. Harding)

Pull request description:

  The "rand-std" feature enables "std" but we use it in examples still. FTR I added this a while ago thinking the explicitness was clearer but in hindsight I think that was wrong and that it makes usage of our features _less_ clear.

  No logic changes.

  (Pulled out of #2756.)

ACKs for top commit:
  storopoli:
    ACK 091d614aad
  apoelstra:
    ACK 091d614aad

Tree-SHA512: d72eec37e3a434a1f850cb4257529fc18540cb5075bc7d3bd494cba59b08404c6c86223361a3c3a3de8d50a1168b656ff1123d28f7d2dcdf05c404caff716b1a
2024-06-12 03:52:08 +00:00
Andrew Poelstra cf870bbd7b
Merge rust-bitcoin/rust-bitcoin#2833: Update bitcoinconsensus version to 0.106.0+26
2db88a62fd Update bitcoinconsensus version (Jamil Lambert, PhD)

Pull request description:

  Updated bitcoinconsensus version to 0.106.0+26.0 in bitcoin/Cargo.toml

  The new version supports taproot and has a new parameter for `spent_outputs` in the `verify()` and `verify_with_flags()` functions.

  The validation module was changed to keep the existing functionality by adding `None` as the `spent_outputs` and the flag `VERIFY_ALL_PRE_TAPROOT`.

  This method does not add taproot features to the verify functions.

ACKs for top commit:
  tcharding:
    ACK 2db88a62fd
  apoelstra:
    ACK 2db88a62fd agreed, this is a good step forward

Tree-SHA512: b6cef395e065cfe859a7896ee2deb2f2d255051566751c10d06092064f6523338ca912aad81b789d6ca94e6f6164f2eef874ad6086c6ebe1384ce520d6eba366
2024-06-11 21:57:36 +00:00
Andrew Poelstra cd768303dc
Merge rust-bitcoin/rust-bitcoin#2857: Remove repetition from sha256t_hash_newtype macro
8aa893ebd0 Remove repetition from sha256t_hash_newtype macro (Tobin C. Harding)

Pull request description:

  The `sha256t_hash_newtype` macro is hard to reason about because we allow repetition so which tag goes with which type is slightly obscure.

  Remove repetition and call the macro three times.

  Internal change in `bitcoin`, API change in `hashes`.

  Fix #2811

ACKs for top commit:
  apoelstra:
    ACK 8aa893ebd0 nice, small diff

Tree-SHA512: b38e7c307ac7288b4a5c1c3170ad6aa54c62bd3198922ec8bb091867b230bb9149f7dc996766fc8fa20a1af18b318c475b3e83e2689d322b7f4af0d5cb588e50
2024-06-11 19:46:52 +00:00
Jamil Lambert, PhD 2db88a62fd Update bitcoinconsensus version
Updated bitcoinconsensus version to 0.106.0+26.0.

The new version supports taproot and has a new parameter for spent outputs in the `verify()` and `verify_with_flags()` functions.

The validation module was changed to keep the existing functionality by adding `None` as the `spent_outputs` and the flag `VERIFY_ALL_PRE_TAPROOT`.
2024-06-11 14:31:32 +01:00
Andrew Poelstra aedb09745a
Merge rust-bitcoin/rust-bitcoin#2839: Add API for extracting the inner payload of `RawNetworkMessage`
ce585dc529 api: Run just check-api (Liu-Cheng Xu)
61565957ad Add API for extracting the inner payload of RawNetworkMessage (Liu-Cheng Xu)

Pull request description:

  I'd like to take out the `payload` of `RawNetworkMessage` and then send it to the actual network message processor, but find there is no way to do it. This commit adds such an API to expose all the inner parts (UPD: so that I don't have to do an unnecessary clone to obtain the owned value of `payload`).

ACKs for top commit:
  apoelstra:
    ACK ce585dc529
  tcharding:
    ACK ce585dc529

Tree-SHA512: 89c5f1361a8c2d0ecf928325e9a37b26d39cf32c3a023b78742555a5a1e59e1579522e942ff6f48b07b2d3b81b48c5e8182fa6e88b57fc9c33ce13e313ba2982
2024-06-11 04:03:21 +00:00
Tobin C. Harding 8aa893ebd0
Remove repetition from sha256t_hash_newtype macro
The `sha256t_hash_newtype` macro is hard to reason about because we
allow repetition so which tag goes with which type is slightly obscure.

Remove repetition and call the macro three times.

Internal change in `bitcoin`, API change in `hashes`.
2024-06-11 13:59:55 +10:00
Tobin C. Harding 091d614aad
bitcoin: Remove "std" feature from examples
The "rand-std" feature enables "std" but we use it in examples still.
FTR I added this a while ago thinking the explicitness was clearer but
in hindsight I think that was wrong and that it makes usage of our
features _less_ clear.

No logic changes.
2024-06-11 13:51:00 +10:00
Andrew Poelstra f934132b3b
Merge rust-bitcoin/rust-bitcoin#2846: generate Network <-> Magic From and TryFrom with a macro
76826313a1 generate Network <-> Magic From and TryFrom with a macro (Antoni Spaanderman)

Pull request description:

  Removes possible errors when a network is added to the enum (expressed with the comment `// Note: new network entries must explicitly be matched in 'try_from' below.`)

ACKs for top commit:
  Kixunil:
    ACK 76826313a1
  apoelstra:
    ACK 76826313a1

Tree-SHA512: 37aaf4b9021204c24e3dc405e666f3dea8c4f8e478b26892dd962a49c988904ba02c3dee7cec1ad78d4e4bb9ba9565ec4574d0e169dd215d26b010f1c4dd3d0b
2024-06-10 13:59:52 +00:00
Antoni Spaanderman 76826313a1
generate Network <-> Magic From and TryFrom with a macro 2024-06-09 00:23:28 +02:00
Antoni Spaanderman 0949be931a
fix ServiceFlags::remove 2024-06-09 00:09:00 +02:00
Liu-Cheng Xu 61565957ad Add API for extracting the inner payload of RawNetworkMessage
I'd like to take out the `payload` of RawNetworkMessage and
then send it to the actual network message processor, but
finds there is no way to do it. This commit adds such an API
to expose the owned value of inner `payload`.
2024-06-07 08:59:31 +08:00
Jamil Lambert, PhD 5e7a638b4d fix crypto rustdocs
Fixed the rustdocs for some of the functions to be in third person, and small gramatical changes.
2024-06-06 16:54:02 +01:00
Jamil Lambert, PhD bac30d3e6e fix rustdocs in bip152
Added backticks on links and changed to third person on function rustdocs
2024-06-06 16:37:12 +01:00
Jamil Lambert, PhD 4a9f74b55c fix missing fullstops in bitcoin rustdoc
Added missing fullstops to the rustdoc titles for everything on the main page of the bitcoin crate
2024-06-06 16:37:12 +01:00
Andrew Poelstra 160f6de4b6
Merge rust-bitcoin/rust-bitcoin#2747: bitcoin: Add PSBT multiple inputs examples
34a5da5f16 bitcoin: Add Taproot PSBT multiple inputs examples (Jose Storopoli)
b8dc0617c9 bitcoin: Add ECDSA PSBT multiple inputs examples (Jose Storopoli)

Pull request description:

  Adds examples on how to create,
  update, sign, and finalize PSBTs version 0
  that deals with multiple inputs.

  Examples are SegWit V0 and Taproot.

ACKs for top commit:
  tcharding:
    ACK 34a5da5f16
  apoelstra:
    ACK 34a5da5f16 nice!

Tree-SHA512: de5717920923e7143e395cbcf143892527e0e794931974eb579db19c17fe0914e630849a0c0581c608909b2cfacfed35df5298605aaa3c9bbd4833985677cf42
2024-06-06 12:52:15 +00:00
Jose Storopoli 34a5da5f16
bitcoin: Add Taproot PSBT multiple inputs examples 2024-06-05 13:11:28 +00:00
Jose Storopoli b8dc0617c9
bitcoin: Add ECDSA PSBT multiple inputs examples 2024-06-05 13:11:25 +00:00
Tobin C. Harding 3298c0c4b5
pow: Unit test from_hex_internal
Add a unit test that fails if put before the "pow: Fix off-by-one error"
patch. Tests that we can correctly parse a 32 character long hex string
into a `U256`.
2024-06-05 09:44:23 +10:00
Tobin C. Harding 47e4bff0ee
pow: Fix off-by-one error
Length check has an off-by-one error in it, we want the check it include
hex strings of length 32 (eg, 128 bytes).
2024-06-05 08:39:47 +10:00
Fmt Bot 07ef78ea96 2024-06-02 automated rustfmt nightly 2024-06-02 01:07:10 +00:00
Andrew Poelstra ee68e80315
Merge rust-bitcoin/rust-bitcoin#2535: Move `read_scriptint` to `PushBytes` & create `read_int` function
d6ef16af30 update api (Divyansh Gupta)
a336ec0dda refactor(script): move `read_scriptint` to `PushBytes` & create `read_int` function (Divyansh Gupta)

Pull request description:

  * Moved `read_scriptint` method to `Push_Bytes` struct
  * Created `Instruction::read_int` method which acts as a wrappper around this  function.

  Done as part of #1547

ACKs for top commit:
  apoelstra:
    ACK d6ef16af30
  tcharding:
    ACK d6ef16af30

Tree-SHA512: e33df8adcb1c23351da303f6bad1ea4a8eae30e65943d230ae886183a01f970aecd0c8c8fd3a6c337cfe6dde1b7590778d88c308415e393f137065ef7da4b29c
2024-06-01 22:38:44 +00:00
Tobin C. Harding 60ab3d26e5
CI: Remove shebang from non-executable scripts
Some of our CI shell scripts are meant only to be sourced and not
run directly however they include an initial shebang line, implying that
they should be run.

Remove the shebang line from `crates.sh` and the various `test_vars.sh`
scripts. Add a `shellcheck` directive to inhibit the no-shebang warning.

Fix: #2764
2024-05-31 10:10:00 +10:00
Andrew Poelstra aabaf6f2a3
Merge rust-bitcoin/rust-bitcoin#2815: Add `const` modifier to `Magic::from_bytes`
d2be969a51 Add `const fn Magic::from_bytes` patch for API files (Velnbur)
b7458256af Add `const` modifier to `Magic::from_bytes` (Velnbur)

Pull request description:

  Resolves: rust-bitcoin/rust-bitcoin#2814

ACKs for top commit:
  apoelstra:
    ACK d2be969a51

Tree-SHA512: 4e8f24b665a2919bcf135333be097114d72f473684b14a8fdd4e8d82bf57e89b4166352f75f744105f76eddc9ffabcb07971a669a7c93dfff6928a3fe519a38f
2024-05-30 16:34:53 +00:00
Velnbur b7458256af
Add `const` modifier to `Magic::from_bytes`
Resolves: rust-bitcoin/rust-bitcoin#2814
2024-05-30 12:58:29 +03:00
Tobin C. Harding 853026071f
bitcoin: Use new BlockHeight and BlockInterval types
We just added to now types that are thin wrappers around `u32`s for
block heights and intervals.

Add `Encodable` and `Decodable` impls and use the new types. While we
are at it re-export the types from the crate root so users don't have to
dig into the `units` crate.
2024-05-30 16:49:30 +10:00
Andrew Poelstra 3c7ac53e89
Merge rust-bitcoin/rust-bitcoin#2715: psbt: Use macro to hash instead of relying on `Hash` trait
9e4b092fce psbt: Use macro instead of function (Tobin C. Harding)

Pull request description:

  We have a private function that makes use of the `Hash` trait to generically hash map entries. This usage makes patching the `hashes` module difficult. We can achieve the same thing by using a macro and passing in the concrete type.

  This is an internal change, no effect on logic or public API.

ACKs for top commit:
  apoelstra:
    ACK 9e4b092fce

Tree-SHA512: 8b788fa91d21bbae556c746c2e55e6e9395e022bedf13193555ef7482109b6ef5032b233c5f37543a31ebda49d9b4761c161ca0db501472047eb661a48e944b7
2024-05-28 16:54:13 +00:00
Andrew Poelstra 65a5dfcd6b
Merge rust-bitcoin/rust-bitcoin#2585: Improve array macros
6ba7758b30 Improve array macros (Tobin C. Harding)

Pull request description:

  Currently we have two macros used when creating array wrapper types, one is in `internals` and the other in `bitcoin::internal_macros`. It is not immediately obvious what is what and why there are two.

  Improve the macros by:

  - Move the inherent functions to `impl_array_newtype`
  - Use `*_byte_array` for the names instead of `*_bytes`
  - Re-name the other macro to match what it now does

ACKs for top commit:
  apoelstra:
    ACK 6ba7758b30

Tree-SHA512: 36ed0fae0d28f24d29287062eb05bbc1e9e8b565f4ff41fd893503a25404ed8e185a34d75e398a8a660923ffda3b832b6157011598d5a75a5c4aafdffc74af2a
2024-05-28 16:25:59 +00:00
Andrew Poelstra b31ac0fcb7
Merge rust-bitcoin/rust-bitcoin#2768: Deprecate `to_vec` in favour of `to_bytes`
eda61ddfef Deprecate to_vec in favour of to_bytes (Tobin C. Harding)

Pull request description:

  Currently we have to method names for the same thing "copy this object into a vector". The library is easier to use if we are uniform and just use one.

  Elect to use `to_bytes`, for context see discussion in PR #2585.

ACKs for top commit:
  apoelstra:
    ACK eda61ddfef Nice. IMO we should start deprecating stuff for two releases rather than one, so that people have a year to update.

Tree-SHA512: 0aadd1258a07bfa53806f19a3c41af8d3b1132aa42e7a2015a59c58c4309d7a9b50b86d076c181ce5870ba5acd989feec32669352ecf857ae6fd982873482c34
2024-05-28 15:19:35 +00:00
Andrew Poelstra 6e407e44e4
Merge rust-bitcoin/rust-bitcoin#2809: doc: fix "lazy line continuations" in markdown
1282b7f34b examples: drop a couple allocations (Andrew Poelstra)
45e0241267 doc: fix "lazy line continuations" in markdown (Andrew Poelstra)

Pull request description:

  Rust nightly as of 2024-05-27 has a new lint which detects list items which are continued by a non-indented line. Markdown treats these as single list items, which they sometimes are, but sometimes we intended them to be on a separate line.

  Also changes the docs for `UntweakedKeypair::tap_tweak` because the existing ones were overly technical and out-of-date.

  Also fixes a minor "no need to create a vec then dereference it" lint in the examples.

ACKs for top commit:
  storopoli:
    ACK 1282b7f34b
  tcharding:
    ACK 1282b7f34b

Tree-SHA512: 989c83b6bbbfbf8ddd2ade63b5f590f76810f4ec56fab432b580a40e3cc1468a0ea657dcc7ad0d4a31d49eb1390219616fec5a76b5680d5fddc3a06d81db30d7
2024-05-28 13:34:58 +00:00
Divyansh Gupta a336ec0dda refactor(script): move `read_scriptint` to `PushBytes` & create `read_int` function
* Moved read_scriptint method to Push_Bytes struct
 * Created Instruction::read_int method
fix #1547
2024-05-28 15:36:17 +05:30
Andrew Poelstra 1741229526
Merge rust-bitcoin/rust-bitcoin#2808: Add an `AddressData` type
b5ef7db3c0 api: Run just check-api (Tobin C. Harding)
1b40550ce8 Add an AddressData type (Tobin C. Harding)

Pull request description:

  In the 0.32.0 release we removed the `address::Payload` struct because it was deemed an implementation detail. As a byproduct of doing so we made it impossible for users to match on an enum and get the address payload (or data).

  - Add a public `AddressData` enum that holds an address' encoded data.
  - Add a conversion function to `Address` that returns the data enum.

  This patch is additive and is expected to be backported and release as a `0.32` point release.

ACKs for top commit:
  apoelstra:
    ACK b5ef7db3c0 I still feel a little partial to calling the struct "DecodedAddress" and the method "decode"...but this is good, and I do not want to bikeshed

Tree-SHA512: d97836bb2d7fc0f6e9fbba2afb30eeefefc88e7105d4765a146dd444c8397dd4d1ef4fd3e3eb925589294d46bfc8a66d33797a05dbc2131923534364424c135c
2024-05-27 16:29:06 +00:00
Andrew Poelstra 1282b7f34b
examples: drop a couple allocations
Detected by clippy.
2024-05-27 12:54:22 +00:00
Andrew Poelstra 45e0241267
doc: fix "lazy line continuations" in markdown
Rust nightly as of 2024-05-27 has a new lint which detects list items
which are continued by a non-indented line. Markdown treats these as
single list items, which they sometimes are, but sometimes we intended
them to be on a separate line.

Also changes the docs for `UntweakedKeypair::tap_tweak` because the
existing ones were overly technical and out-of-date.
2024-05-27 12:50:26 +00:00
Tobin C. Harding 1b40550ce8
Add an AddressData type
In the 0.32.0 release we removed the `address::Payload` struct because
it was deemed an implementation detail. As a byproduct of doing so we
made it impossible for users to match on an enum and get the address
payload (or data).

- Add a public `AddressData` enum that holds an address' encoded data.
- Add a conversion function to `Address` that returns the data enum.

This patch is additive and is expected to be backported and release as a
`0.32` point release.
2024-05-27 14:46:25 +10:00
Andrew Poelstra 4fde89f77c
Merge rust-bitcoin/rust-bitcoin#2795: Make `Address:p2sh_from_hash` public
3615410d21 api: Run just check-api (Tobin C. Harding)
a3d2d1a184 Make Address:p2sh_from_hash public (Tobin C. Harding)

Pull request description:

  We previously made this function Private and added a comment that doing so was somehow better to remove the footgun of hashing the wrong length script. However in hindsight this was a bad idea and users want the functionality.

  Make the `Address:p2sh_from_hash` public and document it as we do for `Address::p2sh`.

  This is an additive change and is expected to be backported to `v0.32`, as part of the fix to #2784. Please note it introduces the footgun that is described in the function rustdoc. This will be improved as a separate patch and added to the current release.

ACKs for top commit:
  apoelstra:
    ACK 3615410d21

Tree-SHA512: 535bb7894eeef8ecb5afb7bf6e5c483cd42c6a4282d1c116e5bf86cd1364a8327bbec1efb8634a578f07ad2832c1e5daf7fe7e844574b88b1ad355a443627bef
2024-05-25 21:12:12 +00:00
Andrew Poelstra e96961f333
Merge rust-bitcoin/rust-bitcoin#2798: Standardize rustdoc subheadings
11bb1ff6ff Standardize function doc Safety, Returns and Parameters (jamil.lambert)
df83016c98 Standardize function doc Errors (jamil.lambert)
d219ceb68e Standardize function doc Examples (jamil.lambert)
233a9133d8 Standardize function doc Panics (jamil.lambert)

Pull request description:

  The subheadings in the rustdocs have been standardized according to [./CONTRIBUTING.md](https://github.com/rust-bitcoin/rust-bitcoin/blob/master/CONTRIBUTING.md):
  ```rust
  impl FooBar {
      /// Constructs a `FooBar` from a [`Baz`].
      ///
      /// # Errors
      ///
      /// Returns an error if `Baz` is not ...
      ///
      /// # Panics
      ///
      /// If the `Baz`, converted to a `usize`, is out of bounds.
      pub fn from_baz(baz: Baz) -> Result<Self, Error> {
          ...
      }
  }
  ```

ACKs for top commit:
  apoelstra:
    ACK 11bb1ff6ff
  tcharding:
    ACK 11bb1ff6ff

Tree-SHA512: 163af3cd1cfb47cea3e55eddeaeb6843ff7ec89c57354e3247d6bae85e756b183e8045c2555cfcf87e8c23c1388ff9d7592cfb6a951a37a9ec41d27263e5a2e4
2024-05-25 14:55:16 +00:00
Andrew Poelstra 8d5399f881
Merge rust-bitcoin/rust-bitcoin#2765: Flesh out hex unit parsing API
cf3e1eb198 api: Run just check-api (Tobin C. Harding)
98bf213c52 bitcoin: Remove error module (Tobin C. Harding)
a5b93cb159 Flesh out hex unit parsing API (Tobin C. Harding)

Pull request description:

  Add to `units::parse` the complete suit of hex unit parsing functions:

  - remove prefix
  - assert without prefix
  - parse with or without prefix
  - parse with prefix
  - parse without prefix
  - parse prefix unchecked

  Refactor `bitcoin` to use the exact function we need, removing code duplication.

  This is a breaking change to `units`, it does however keep the current re-exports from the public, now empty, `bitcoin::error` module.

ACKs for top commit:
  apoelstra:
    ACK cf3e1eb198

Tree-SHA512: 1778108d4364e290e8956cfea6f23fcdd82c835844d034a00b4cf5cab5552e3efbe853dfbf8a3e0a4bd53a8e3da9d6f7c7408d332d18cd7090aec16fc1f02fe7
2024-05-25 13:32:52 +00:00
Tobin C. Harding a3d2d1a184
Make Address:p2sh_from_hash public
We previously made this function Private and added a comment that doing
so was somehow better to remove the footgun of hashing the wrong length
script. However in hindsight this was a bad idea and users want the
functionality.

Make the `Address:p2sh_from_hash` public and document it as we do for
`Address::p2sh`.
2024-05-25 07:54:11 +10:00
Andrew Poelstra d994aba063
Merge rust-bitcoin/rust-bitcoin#2586: Hard code genesis script bytes instead of hex
726ff25c46 Hard code genesis script bytes instead of hex (Tobin C. Harding)
6e5592db77 Use test_hex_unwrap in bench code (Tobin C. Harding)

Pull request description:

  Currently we have a dependency on `hex_lit` and it is used in exactly one place outside of test code, if we instead use a hardcoded array instead we can move the `hex_lit` dependency to `dev-dependencies`.

  Hard code the genesis block script bytes as an array of hex digits, link to the blockstream explorer for those interested and comment the bytes liberally since it took me a while to work out what they were.

  Move the `hex_lit` dependency and update the lock files.

ACKs for top commit:
  apoelstra:
    ACK 726ff25c46

Tree-SHA512: 96110332fc24dd5b251150b32737fa198113244c3b51b35453c8c1fcc8386c5a2f68dddb30d78cf2f9e1762550099fdb4109dc550f4c144625795ce60b86e574
2024-05-24 20:43:37 +00:00
Andrew Poelstra 543b387d72
Merge rust-bitcoin/rust-bitcoin#2796: Enable getting the witness program from an address
7f29313d36 Update API (Tobin C. Harding)
4f29adf163 Enable getting the witness program from an address (Tobin C. Harding)

Pull request description:

  We have getters for the pubkey hash and script hash but we forgot one for the witness program - add it.

  Done as part of fixing #2784, this is an additive change and is expected to be backported to `v0.32`

ACKs for top commit:
  apoelstra:
    ACK 7f29313d36

Tree-SHA512: 365aba572eaacb789f5424c233be067500ceff18dc27e28fc3be123c49d27333e95bbf4527469a9caf8cc2fe54f8e13a0fc83bc3fc7c3356aea876c9dd2fa5f0
2024-05-24 20:11:17 +00:00
Andrew Poelstra 613f1fb126
Merge rust-bitcoin/rust-bitcoin#2792: Header change from arguments to parameters
9bb75703a1 Header change from arguments to parameters (jamil.lambert)

Pull request description:

  In a few cases a function header documents the parameters of the following function under the heading "Arguments", this has been changed to "Parameters".

  Since the description is at the level of the function definition and not where it is being called parameters seems the more accurate term.

ACKs for top commit:
  apoelstra:
    ACK 9bb75703a1
  tcharding:
    ACK 9bb75703a1

Tree-SHA512: aa24af3fd6e086c09f5e2605fa58289969fc7188f63d7f53c0e325315644f9704d51d4cf526ebfc51b2cf9216155fc3d48cc6bca759dc14bae15e4770de5116e
2024-05-24 13:14:25 +00:00
jamil.lambert 11bb1ff6ff Standardize function doc Safety, Returns and Parameters
Changed the function docs to have the same format of
///
/// # Safety
///
/// description
2024-05-24 09:59:42 +01:00
jamil.lambert df83016c98 Standardize function doc Errors
Changed the function docs to have the same format of
///
/// # Errors
///
/// description
2024-05-24 09:59:42 +01:00
jamil.lambert d219ceb68e Standardize function doc Examples
Changed the function docs to have the same format of
///
/// # Examples
///
/// description
2024-05-24 09:59:42 +01:00
jamil.lambert 233a9133d8 Standardize function doc Panics
Changed the function docs to have the same format of
///
/// # Panics
///
/// description
2024-05-24 09:59:29 +01:00
Tobin C. Harding 98bf213c52
bitcoin: Remove error module
The `error` module is empty except for public re-exports. We are still
in the "break everything and get the API right" stage so this module
adds no value - remove it.
2024-05-24 14:32:47 +10:00
Tobin C. Harding a5b93cb159
Flesh out hex unit parsing API
Add to `units::parse` the complete suit of hex unit parsing functions:

- remove prefix
- assert without prefix
- parse with or without prefix
- parse with prefix
- parse without prefix
- parse prefix unchecked

Refactor `bitcoin` to use the exact function we need, removing code
duplication.

This is a breaking change to `units`, it does however keep the current
re-exports from the public, now empty, `bitcoin::error` module.
2024-05-24 14:32:47 +10:00
Andrew Poelstra 1142d16192
Merge rust-bitcoin/rust-bitcoin#2785: Whitelist cfg attrs and bump nightly version
30a482504b bump nightly-version (Andrew Poelstra)
5ad7c245e3 cargo: whitelist all cfgs used in this repo (Andrew Poelstra)
814786b0a6 crypto: enable and fix accidentally disabled unit test (Andrew Poelstra)

Pull request description:

  https://github.com/rust-lang/rust/issues/124800 has been fixed and we can update our nightly version by whitelisting all cfgs that are used.

  There was one place where we had an old `cfg(feature = "no-std")` despite having removed the feature. By removing that cfg check we re-enabled a previously disabled test.

ACKs for top commit:
  tcharding:
    ACK 30a482504b

Tree-SHA512: d25bed819091db74b9d47cb2c23caa3ceb0d7be323b37831326e2ec1608cb1577d41aad2e1cdf59d66df69397537bc3e17a3c2872935d5a4f46f4dc55b5e613c
2024-05-23 16:52:22 +00:00
Tobin C. Harding 4f29adf163
Enable getting the witness program from an address
We have getters for the pubkey hash and script hash but we forgot one
for the witness program - add it.
2024-05-23 13:02:12 +10:00
Tobin C. Harding 726ff25c46
Hard code genesis script bytes instead of hex
Currently we have a dependency on `hex_lit` and it is used in exactly
one place outside of test code, if we instead use a hardcoded array
instead we can move the `hex_lit` dependency to `dev-dependencies`.

Hard code the genesis block script bytes as an array of hex digits, link
to the blockstream explorer for those interested and comment the bytes
liberally since it took me a while to work out what they were.

Move the `hex_lit` dependency and update the lock files.
2024-05-23 09:19:24 +10:00
Tobin C. Harding 6e5592db77
Use test_hex_unwrap in bench code
We would like to move the dependency on `hex_lit` to be a
dev-dependency but currently are using it in bench code. The bench
code is enabled if any downstream crate tries to build with
`--cfg=bench` and during such a build our dev-dependencies are not
available.

We also have the `test_hex_unwrap` macro in the `hex` crate and since
the bench code is more or less test code (and the macro call is not
being benchmarked) we can use that macro instead.
2024-05-23 09:19:24 +10:00
Andrew Poelstra d0c1eb138c
Merge rust-bitcoin/rust-bitcoin#2754: Document CompactTarget order/equality
c8caee2b5e Document CompactTarget order/equality (Tobin C. Harding)

Pull request description:

  Add documentation to the `CompactTarget` type explaining the nuance surrounding order/equality.

  Close: #2110

ACKs for top commit:
  apoelstra:
    ACK c8caee2b5e

Tree-SHA512: c724b31ee620ff08d3c8b547250bc7067f875ef6cf4ce9efa082d5a9cfbd8b92620f86034e58caf573c479ce7aaa89bb7e9fa93dc356524663d3ecf583df3507
2024-05-22 19:49:14 +00:00
Andrew Poelstra 5ad7c245e3
cargo: whitelist all cfgs used in this repo 2024-05-22 13:32:24 +00:00
jamil.lambert 9bb75703a1 Header change from arguments to parameters
In a few cases a function header documents the parameters of the following function under the heading"Arguments", this has been changed to "Parameters"
2024-05-22 13:12:44 +01:00
Tobin C. Harding c8caee2b5e
Document CompactTarget order/equality
Add documentation to the `CompactTarget` type explaining the nuance
surrounding order/equality.

Close: #2110
2024-05-22 08:53:25 +10:00
Andrew Poelstra 814786b0a6
crypto: enable and fix accidentally disabled unit test 2024-05-21 17:17:48 +00:00
Tobin C. Harding 9e4b092fce
psbt: Use macro instead of function
We have a private function that makes use of the `Hash` trait to
generically hash map entries. This usage makes patching the `hashes`
module difficult. We can achieve the same thing by using a macro and
passing in the concrete type.

This is an internal change, no effect on logic or public API.
2024-05-21 08:57:21 +10:00
Tobin C. Harding f6129317bd
Run the formatter
Run `just fmt`, no other changes.
2024-05-20 08:58:48 +10:00
Tobin C. Harding fa4d3d4417
Add whitespace
The formatter lines up comments if they are on consecutive lines even
if the second is supposed to be at the start of the collum and the
first is after code. Putting a line of whitespace between the two
lines stops this from happening.

Add whitespace to stop the formatter doing silly changes.

Whitespace only.
2024-05-20 08:56:58 +10:00
Tobin C. Harding c934d03fcf
p2p: Cleanup test imports
Clean up the test imports in the `p2p` module:

- Use `use super::*` as is conventional.
- Use `sha256d::Hash` as is conventional.

Refactor, no logic changes.
2024-05-17 10:57:54 +10:00
Andrew Poelstra 47527abd53
Merge rust-bitcoin/rust-bitcoin#2776: Fix rustdoc header format
6d0d0fe51f Fix rustdoc header format (jamil.lambert)

Pull request description:

  By convention rustdoc headers should not include a colon.

  Removed colon from rustdoc headers.

ACKs for top commit:
  apoelstra:
    ACK 6d0d0fe51f

Tree-SHA512: 36d5822e80cc86139ce07a1c86681998e1d27549421b9b50589fe4a9a5c860ed47f145d5af9501957f199d0f77df069c2b295d43ed4a15e9b6d98c0edc12abd0
2024-05-16 18:10:39 +00:00
Andrew Poelstra 2fe579bd3f
Merge rust-bitcoin/rust-bitcoin#2772: Removed //! spare line at end of headers
802af8e417 Removed //! spare line at end of headers (jamil.lambert)

Pull request description:

  Some of the headers had a //! at the end but most didn't.  They have all been removed in bitcoin/src/ to make the files consistent

ACKs for top commit:
  apoelstra:
    ACK 802af8e417

Tree-SHA512: a1eb0dda76af68cb96352f6b31231fa5391d49e11df924065e76871f82231ec0d5751190663f142240e5d757975937387243d1fdac3684d9bdbd7e2362dbd0a7
2024-05-16 13:48:15 +00:00
jamil.lambert 6d0d0fe51f Fix rustdoc header format
By convention rustdoc headers should not include a colon.

Removed colon from rustdoc headers.
2024-05-16 10:35:30 +01:00
jamil.lambert 802af8e417 Removed //! spare line at end of headers 2024-05-16 09:59:55 +01:00
Tobin C. Harding f3c80ea820
Use concrete type for all_zeros call
Currently we use the `Hash` trait in a bunch of places to call
`all_zeros`. We are attempting to improve the `hashes` API and this
usage is both unnecessary and also hindering that effort.

Use the concrete type (e.g. `BlockHash`) instead of calling through the
trait method.

Refactor only, no logic changes.
2024-05-16 09:01:37 +10:00
Andrew Poelstra 44a6402875
Merge rust-bitcoin/rust-bitcoin#2740: Add difficulty adjustment calculation
47dc4a3180 feat(pow): add difficulty adjustment calculation (Rob N)

Pull request description:

  Hi, I hit a roadblock with the current `pow` API. As far as I can tell, the only workaround to calculate the next work required similar to `bitcoin/src/pow.cpp` is to use a general big integer library, convert the `Target` to bytes, do the math, and convert back to `Target` from bytes. I have also been working with [Floresta](780ea8d0b0) and their [solution](780ea8d0b0/crates/floresta-chain/src/pruned_utreexo/consensus.rs (L187)) was to fork off and exposed the `U256` struct publicly on their branch. I think these home brewed difficulty adjustment solutions will continually pop up, so I created a `from_next_work_required` method to return a `Target`. My work veers significantly from #2180, as I only provided a single method to do so, without further guidance on when exactly this retarget occurs.

  I am happy to add tests once I get further direction from maintainers if this as a likelihood of being accepted or not. Thanks.

ACKs for top commit:
  tcharding:
    ACK 47dc4a3180
  apoelstra:
    ACK 47dc4a3180 used range-diff

Tree-SHA512: 6d627ce698361afed61c8f2a12a1a96371a7a93118e08a91dae250de4f23d65c615d2654d37d2699c88b7c22f6e4bc2a1195f963c15512d7c0d041498f02dc41
2024-05-15 13:42:25 +00:00
Rob N 47dc4a3180
feat(pow): add difficulty adjustment calculation 2024-05-14 16:49:53 -10:00
Andrew Poelstra 845ae37dbe
Merge rust-bitcoin/rust-bitcoin#2729: bitcoin: Set version number
46e0ce59a3 bitcoin: Set version number (Tobin C. Harding)

Pull request description:

  During the recent release cycle we left `bitcoin` on the last rc version.

  Set the version number to `v0.33.0-unreleased` to make it obvious what it is.

  Close: #2724

ACKs for top commit:
  apoelstra:
    ACK 46e0ce59a3
  sanket1729:
    ACK 46e0ce59a3

Tree-SHA512: 8a1fa062cf0240c5a7e1c05f0378097464423c29827f14068d01ac562d1be571bec2d267a5a12d0828c5a2809ef743f03ef29ccea9a31a5c9e3eefce66b3d30d
2024-05-15 01:50:24 +00:00
Tobin C. Harding eda61ddfef
Deprecate to_vec in favour of to_bytes
Currently we have to method names for the same thing "copy this object
into a vector". The library is easier to use if we are uniform and just
use one.

Elect to use `to_bytes`, for context see discussion in PR #2585.
2024-05-14 10:47:02 +10:00
Tobin C. Harding 6ba7758b30
Improve array macros
Currently we have two macros used when creating array wrapper types,
one is in `internals` and the other in `bitcoin::internal_macros`. It
is not immediately obvious what is what and why there are two.

Improve the macros by:

- Move the inherent functions to `impl_array_newtype`
- Use `*_byte_array` for the names instead of `*_bytes` for functions
  that return arrays
- Add `as_bytes` to return a slice
- Add `to_bytes` to return a vector
- Re-name the other macro to match what it now does
2024-05-14 10:42:40 +10:00
Andrew Poelstra 2ec5a4b03a
Merge rust-bitcoin/rust-bitcoin#2760: bip32: derive_xpriv should not return a Result
d353be4546 bip32: derive_xpriv should not return a Result (Jose Storopoli)

Pull request description:

  We discussed in #2752 that `derive_priv` never fails.

  This PR addresses that issue.

ACKs for top commit:
  apoelstra:
    ACK d353be4546
  tcharding:
    ACK d353be4546
  sanket1729:
    ACK d353be4546

Tree-SHA512: 3a3d09027c6079581636b51a506fac2b325e592d182167c0a3d8676b41fb2bef59a85a404ad12b2e14d73e58fd4b6d8f5923a3dc76a4b9724033097fc08b36ac
2024-05-13 22:35:49 +00:00
Jose Storopoli d353be4546
bip32: derive_xpriv should not return a Result 2024-05-13 20:43:49 +00:00