Commit Graph

3320 Commits

Author SHA1 Message Date
Matt Corallo add371d263 Remove `core2` dependency entirely 2023-11-09 16:46:44 +00:00
Matt Corallo b7dd16da99 [IO] Use our own io::Error type
In order to move towards our own I/O traits in the `rust-bitcoin`
ecosystem, we have to slowly replace our use of the `std` and
`core2` traits.

This is the final step in removing the explicit `core2` dependency
for I/O in no-std - replacing the `io::Error` type with our own.

Sadly the `std::io::Error` type requires `std::error::Error` as a
bound on the inner error, which is rather difficult to duplicate in
a way that allows for mapping to `std` and back.

To take a more general approach, we use bound on any `Debug`
instead.
2023-11-07 17:35:18 +00:00
Matt Corallo c95b59327a Explicitly use `std::io::Error` when implementing `std` traits
In the next commit, `std::io::Error` will be replaced with a
different type, and as a result `std::io::Error` must be referred
to explicitly.
2023-11-07 17:35:18 +00:00
Matt Corallo 9e1cd372cb Use `io::Error::get_ref()` over `std::error::Error::source()` 2023-11-07 17:35:18 +00:00
Matt Corallo 3caaadf9bb [IO] Replace the `io::Cursor` re-export with our own `Cursor` 2023-11-07 17:35:17 +00:00
Matt Corallo 141343edb4 [IO] Move to custom `Read` trait mirroring `std::io::Read`
In order to move towards our own I/O traits in the `rust-bitcoin`
ecosystem, we have to slowly replace our use of the `std` and
`core2` traits.

Here we take the second big step, replacing
`{std,core2}::io::Read` with our own `bitcoin_io::io::Read`. We
provide a blanket impl for our trait for all `std::io::Read`, if
the `std` feature is enabled, allowing users who use their own
streams or `std` streams to call `rust-bitcoin` methods directly.
2023-11-07 05:51:39 +00:00
Matt Corallo 7395093f94 Stop relying on `Take`'s `by_ref` method 2023-11-07 05:51:37 +00:00
Matt Corallo 2364e1a877 Stop relying on blanket Read impl for all &mut Read 2023-11-07 05:51:36 +00:00
Matt Corallo 6aa7ccf841 [IO] Replace `std::io::Sink` usage with our own trivial impl 2023-11-07 05:51:36 +00:00
Matt Corallo 7eb5d65bda [IO] Provide a macro which implements `io::Write` for types
With the new `bitcoin_io` library, implementing `io::Write`
manually is somewhat tricky - for `std` users we really want to
provide an `std::io::Write` implementation, however for `no-std`
users we want to implement against our internal trait.

Sadly we cannot provide a blanket implementation of
`std::io::Write` for all types whcih implement our `io::Write`
trait as its an out-of-crate impl.

Instead, we provide a macro which will either implement
`std::io::Write` or our `io::Write` depending on the feature flags
set on `bitcoin_io`.
2023-11-07 05:51:34 +00:00
Matt Corallo ac678bb435 [IO] Move to custom `Write` trait mirroring `std::io::Write`
In order to move towards our own I/O traits in the `rust-bitcoin`
ecosystem, we have to slowly replace our use of the `std` and
`core2` traits.

Here we take the first real step, replacing
`{std,core2}::io::Write` withour own `bitcoin_io::io::Write`. We
provide a blanket impl for our trait for all `std::io::Write`, if
the `std` feature is enabled, allowing users who use their own
streams or `std` streams to call `rust-bitcoin` methods directly.
2023-11-07 05:51:31 +00:00
Matt Corallo 5f2395ce56 Add missing `?Sized` bounds to `io::Write` parameters
Since we are no longer relying on the blanket `io::Write` impl for
`&mut io::Write`, we should now ensure that we do not require
`Sized` for our `io::Write` bounds, as its unnecessarily
restrictive and can no longer be worked around by simply adding an
`&mut`.
2023-11-07 05:50:51 +00:00
Matt Corallo 2348449d2a Stop relying on `std::io::Write`'s `&mut Write` blanket impl
`std::io::Write` is implemented for all `&mut std::io::Write`. This
makes it easy to have APIs that mix and match owned `Write`s with
mutable references to `Write`s.

However, in the next commit we add our own `Write` trait which we
intend to implement for all `std::io::Write`. Sadly, this is
mutually exclusive with a blanket implementation on our own
`&mut Write`, as that would conflict with an `std::io::Write`
blanket impl.

Thus, in order to use the `Write for all &mut Write` blanket impl
in rust-bitcoin, we'd have to bound all `Write`s by
`std::io::Write`, as we're unable to provide a blanket
`Write for &mut Write` impl.

Here we stop relying on that blanket impl in order to introduce the
new trait in the next commit.
2023-11-07 05:50:47 +00:00
Matt Corallo 5e0209569c Use `io::sink` rather than our custom `EmptyWrite` utility 2023-11-07 05:50:45 +00:00
Matt Corallo a0ade883b6 [IO] Move io module into selected re-exports
In the coming commits we'll move our `io` module to having its own
implementations of the usual I/O traits and structs. Here we first
move to re-exporting only exactly what we need, allowing us to
whittle the list down from a fixed set.
2023-11-07 05:50:42 +00:00
Matt Corallo 27c7c4e26a Add a `bitcoin_io` crate
In order to support standard (de)serialization of structs, the
`rust-bitcoin` ecosystem uses the standard `std::io::{Read,Write}`
traits. This works great for environments with `std`, however sadly
the `std::io` module has not yet been added to the `core` crate.

Thus, in `no-std`, the `rust-bitcoin` ecosystem has historically
used the `core2` crate to provide copies of the `std::io` module
without any major dependencies. Sadly, its one dependency,
`memchr`, recently broke our MSRV.

Worse, because we didn't want to take on any excess dependencies
for `std` builds, `rust-bitcoin` has had to have
mutually-exclusive `std` and `no-std` builds. This breaks general
assumptions about how features work in Rust, causing substantial
pain for applications far downstream of `rust-bitcoin` crates.

Here, we add a new `bitcoin_io` crate, making it an unconditional
dependency and using its `io` module in the in-repository crates
in place of `std::io` and `core2::io`. As it is not substantial
additional code, the `hashes` io implementations are no longer
feature-gated.

This doesn't actually accomplish anything on its own, only adding
the new crate which still depends on `core2`.
2023-11-07 05:50:42 +00:00
Andrew Poelstra 4fb91277f0
Merge rust-bitcoin/rust-bitcoin#2171: Remove code deprecated since `v0.31.0`
2c33744baa Remove code deprecated since v0.31.0 (Tobin C. Harding)

Pull request description:

  We only deprecate for a single release.

  Remove all code deprecated since `v0.31.0`.

ACKs for top commit:
  Kixunil:
    ACK 2c33744baa
  apoelstra:
    ACK 2c33744baa

Tree-SHA512: ff3d823fc723ab7c614d2ba9b218b069344ca1ee363d8795504f561b5f1fc4171753fb96f77586c3706b5ae618f621ce2452e52bca725407f645b80d24cdffa0
2023-11-04 15:26:45 +00:00
Tobin C. Harding 2c33744baa
Remove code deprecated since v0.31.0
We only deprecate for a single release.

Remove all code deprecated since `v0.31.0`.
2023-11-04 12:14:54 +11:00
Andrew Poelstra 9b2e1c591a
Merge rust-bitcoin/rust-bitcoin#2165: Use macro to define `sha512::Hash`
71454d438a Use hash_type macro for sha512::Hash (Tobin C. Harding)
d51c1857fd sha512: Move from_engine functions (Tobin C. Harding)

Pull request description:

  This PR does not introduce any logic changes.

  - Patch 1 is a code move.
  - Patch 2 uses the `hash_type!` macro to define the `sha512::Hash` type.

ACKs for top commit:
  Kixunil:
    ACK 71454d438a
  apoelstra:
    ACK 71454d438a

Tree-SHA512: c0148391fbea3602f0c52e5e08883faac6b5cb3f75ae62bfb53b1d2762e28871d349b3d3fb589f59d8bf2912dd63934f8f9a6fe6390afd378e5391eb2c91c237
2023-11-03 21:11:49 +00:00
Andrew Poelstra 1cf5bd2e93
Merge rust-bitcoin/rust-bitcoin#2166: Move `sha512_256` code
0bb537d45b Move sha512_256 code (Tobin C. Harding)

Pull request description:

  Make the `sha512_256` module use similar code layout to the other hash modules by putting the call to `hash_type` at the top followed by the `from_engine` function.

  Code move only, no other changes.

ACKs for top commit:
  Kixunil:
    ACK 0bb537d45b
  apoelstra:
    ACK 0bb537d45b

Tree-SHA512: 1b2471782b6aa39c6feb4ac3e7a899d13a12f621e1260365737f56511d7c4dd54bbe47695829a11cc4756ca4a5bf720f5d909632ff2598a6139e7bbc99f64e25
2023-11-03 20:16:11 +00:00
Tobin C. Harding 0bb537d45b
Move sha512_256 code
Make the `sha512_256` module use similar code layout to the other hash
modules by putting the call to `hash_type` at the top followed by the
`from_engine` function.

Code move only, no other changes.
2023-11-03 10:35:56 +11:00
Tobin C. Harding 71454d438a
Use hash_type macro for sha512::Hash
Currently we are defining the `sha512::Hash` type manually instead of
using the `hash_type` macro.

The generated code using the macro is identical to that without
it (although I didn't actually look at the generated code :)
2023-11-03 10:18:24 +11:00
Tobin C. Harding d51c1857fd
sha512: Move from_engine functions
Make a step towards making the `sha512` module have its code layed out
the same as the rest of the hash modules.

Code move only, no other changes.
2023-11-03 10:14:05 +11:00
Andrew Poelstra 071208ccdd
Merge rust-bitcoin/rust-bitcoin#2042: Split Prevouts errors out into specific error types
e21ee381bc Split Prevouts errors out into specific error types (Tobin C. Harding)

Pull request description:

  Done as part of the great error clean up.

  Currently we are returning a general `Error` from `Prevouts` functions, this is un-informative, we can do better by returning specific types that indicate the exact error path.

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

Tree-SHA512: 2a4900f9e31584ad2b6faafa17ea98742fff9206ee1bf77ed29624e0c7b05e655b3b6bf3710e2da26b0b2b8bd5eb36fdd81decbb1f55b41f153f0fbcc4a9165e
2023-11-01 14:20:24 +00:00
Andrew Poelstra df28e2f679
Merge rust-bitcoin/rust-bitcoin#2151: Do trivial docs fixes
d6298fe711 Use capital B for Bitcoin in rustdoc (Tobin C. Harding)
bcfabc3556 Fix typo, missing word (Tobin C. Harding)

Pull request description:

  In an effort to make review merge quicker push these two changes up as a separate PR.

  Totally trivial.

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

Tree-SHA512: 34635ecd87c918f106694a81f50e69dda233000ac616557744466eb58422a2742f35cadbb059f0f81449efd2f61a37ceb71840bf216009914ba2162834e13fc6
2023-10-31 14:30:58 +00:00
Andrew Poelstra 0b1fe094e4
Merge rust-bitcoin/rust-bitcoin#2146: Create uniform build script
fde6479c6a Create uniform build script (yancy)

Pull request description:

  Previously, each unique compiler cfg attribute that appeared in the codebase was hard coded and emitted to stdout at compile time.  This meant keeping the file up to date as different compiler cfg attributes changed.  It's inconsequential to emit a compiler version that's not used, so this change just emits all possibilities to reduce the maintenance burden of the build script.

  Note that there is a bit of diff noise in one of the `build.rs` since I simply did a copy of one to the other to make them uniform.

ACKs for top commit:
  Kixunil:
    ACK fde6479c6a
  tcharding:
    ACK fde6479c6a
  apoelstra:
    ACK fde6479c6a

Tree-SHA512: 401134c168a604a092b72c3980fae6d20adda761273ea47a887cf4c01838536241a45f310cbc2b5941311d533e1d10c848062198af70c0ed619a57973e842840
2023-10-31 14:04:19 +00:00
Tobin C. Harding e21ee381bc
Split Prevouts errors out into specific error types
Done as part of the great error clean up.

Currently we are returning a general `Error` from `Prevouts` functions,
this is un-informative, we can do better by returning specific types
that indicate the exact error path.
2023-10-31 14:21:24 +11:00
Tobin C. Harding d6298fe711
Use capital B for Bitcoin in rustdoc
As we do in another part of this file use capital 'B' for Bitcoin.
2023-10-31 08:37:11 +11:00
Tobin C. Harding bcfabc3556
Fix typo, missing word
Add a 'by' to fix the grammar in sentence.
2023-10-31 08:36:09 +11:00
yancy fde6479c6a Create uniform build script
Previously, each unique compiler cfg attribute that appeared in the
codebase was hard coded and emitted to stdout at compile time. This
meant keeping the file up to date as different compiler cfg attributes
changed. It's inconsequential to emit a compiler version that's not
used, so this change just emits all possibilities to reduce the
maintenance burden of the build script.
2023-10-30 14:40:41 +01:00
Andrew Poelstra 60318c4c71
Merge rust-bitcoin/rust-bitcoin#2140: bitcoin: Tracking PR for release `v0.31.0`
efedf862b0 bitcoin: Bump version number to v0.31.0 (Tobin C. Harding)

Pull request description:

  In preparation for release of v0.31.0 bump the version number.

  The changelog is already up to date because we have done two RC releases.

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

Tree-SHA512: 93b1427409d179e229892c57c48be45e93a022b432735d7f8002bc736a24bf94171823fee38ba819224260fc7e3df52853d10b59442df25a508e46df9860e5b5
2023-10-28 14:56:39 +00:00
Tobin C. Harding efedf862b0
bitcoin: Bump version number to v0.31.0
In preparation for release of v0.31.0 bump the version number.

The changelog is already up to date because we have done two RC
releases.
2023-10-28 08:32:30 +11:00
Andrew Poelstra 7246585588
Merge rust-bitcoin/rust-bitcoin#2096: Move psbt macro to the psbt test module
2ecab31f94 Remove stale comment and map_err (yancy)
b166442fb0 Replace hex_psbt macro with test helper function (yancy)
9e4a784b8b Move psbt macro to the psbt test module (yancy)

Pull request description:

  Remove `#[cfg(test)]` and the macro `psbt_with_values` from macros.rs and place it in the tests module for psbt.

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

Tree-SHA512: 06a55056e864befac8b33968bf4e469c3c7bc20e651ad5bb3b80aa76749169af1266e1d4101d3e9e9bbffe7c860e8b9fcd675a78ca7ae67dc09892c75fba0dd0
2023-10-27 13:17:07 +00:00
Andrew Poelstra a4f57881e4
Merge rust-bitcoin/rust-bitcoin#2143: Add a missing link to #2006 in 'bitcoin/CHANGELOG.md'
2a891e0be8 Add a missing link to #2006 in 'bitcoin/CHANGELOG.md' (lateminer)

Pull request description:

  In the changelog, there is a wrong link to #2006.
  Additionally, a link and description for #2020 are missing.
  This PR addresses these minor issues.

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

Tree-SHA512: c6dc1362af5bb2e5f11c2ed48371a0236ab512aeb0f6075674994c054baf606d9cf30390d7021f9c02c3b7cc59a70c60edb64799afb35cc5ac716a3582aa8cd0
2023-10-27 13:10:44 +00:00
lateminer 2a891e0be8
Add a missing link to #2006 in 'bitcoin/CHANGELOG.md' 2023-10-26 21:06:48 +02:00
Andrew Poelstra 4d12a07a09
Merge rust-bitcoin/rust-bitcoin#2142: Fix a small typo in 'contrib/test.sh'
5d43ad7607 Fix a small typo in 'contrib/test.sh' (Roman Zeyde)

Pull request description:

  `memcrh` -> `memchr`

ACKs for top commit:
  tcharding:
    ACK 5d43ad7607
  apoelstra:
    ACK 5d43ad7607

Tree-SHA512: 98bd9d5d9bec4bd350e32e412b2c704b82633b0aa850404a0fc32113181e12aeaf7d0efaf3bcf6116c15e70ad34168be54c32c1f69d812ab0fca78a74d0f2a7e
2023-10-25 22:21:32 +00:00
Roman Zeyde 5d43ad7607 Fix a small typo in 'contrib/test.sh' 2023-10-25 22:22:08 +03:00
Andrew Poelstra 1eb6e0c7d8
Merge rust-bitcoin/rust-bitcoin#2134: Add clippy exceptions for needless_question_mark lint
875545517d Add clippy exceptions for needless_question_mark lint (Steven Roose)

Pull request description:

  This lint forces you to write semantically different code that is in most cases inferior, just to save you 5 characters.

  The reason why the code is inferior is because it doesn't do error conversion so it would break when either of the two function signatures changes while in the original code using the `?` operator, nothing would break if the inner error can be converted into the outer error.

ACKs for top commit:
  apoelstra:
    ACK 875545517d
  tcharding:
    ACK 875545517d

Tree-SHA512: 8429e0fb7d759a3d19231e7bcaed61b0988172d931e758a9522d7c994854fd403408bb93b06778a5c09746cd38b6a96d3d2e0a862fb4516f2dbfffffe8735ce0
2023-10-24 01:17:32 +00:00
Andrew Poelstra 4c66132c0f
Merge rust-bitcoin/rust-bitcoin#2138: Remove several unnecessary clippy attributes
750ee2ba56 Remove unnecessary clippy attribute on is_sighash_single_bug (Steven Roose)
f522a0290c Remove unnecessary clippy attribute on relative::LockTime (Steven Roose)
b7f11d4493 Remove unnecessary clippy attribute on absolute::LockTime (Steven Roose)

Pull request description:

  Am I missing something and are they necessary in some other clippy configuration than the one I ran?

  It's surprising really that clippy doesn't have a lint to notice unnecessary clippy exception attributes..

ACKs for top commit:
  tcharding:
    ACK 750ee2ba56
  apoelstra:
    ACK 750ee2ba56

Tree-SHA512: 0bed6e014d110a531d0a4a0b003778a7ae9c59ac90e8bbcc518321e48141a77fcdfaddf54b752d2733154ad1945609a9a8dcf121d2a813e7a2ee098af26951f7
2023-10-23 18:34:44 +00:00
Steven Roose 875545517d
Add clippy exceptions for needless_question_mark lint 2023-10-23 16:45:52 +01:00
Steven Roose 750ee2ba56
Remove unnecessary clippy attribute on is_sighash_single_bug 2023-10-23 01:41:44 +01:00
Steven Roose f522a0290c
Remove unnecessary clippy attribute on relative::LockTime 2023-10-23 01:37:50 +01:00
Steven Roose b7f11d4493
Remove unnecessary clippy attribute on absolute::LockTime
I ran the clippy locally without it and it doesn't seem to be necessary
anymore.
2023-10-23 01:36:19 +01:00
Andrew Poelstra 49674beb09
Merge rust-bitcoin/rust-bitcoin#2135: ci: automated nightly rustfmt scheduled/manual PRs
d391ada5b8 ci: nightly rustfmt PR scheduled/manual (Einherjar)

Pull request description:

  ## Summary

  - Removes nightly `rustfmt` checks from CI and `CONTRIBUTING.md`. Superseds #2127
  - Adds automated nightly `rustfmt` PR creations manual and every Sunday 00:00 UTC. Closes #2128. Closes #1712.

  ## Details

  The new `.github/workflows/rustfmt.yml` action does the following:

  1. Checkouts the repo
  1. Install the nightly Rust toolchain with `rustfmt` component
  1. Run `cargo +nightly fmt` which format all the codebase with the nightly Rust toolchain writing the changes
  1. Add the current date in `YYYY-MM-DD` format as an GH action ENV var
  1. If changes are detected, create a PR with the following details:
      - Title: Automated nightly rustfmt (`DATE`)
      - Body: Automated nightly `rustfmt` changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action
      - Commit message: `DATE` automated rustfmt nightly
      - label: `rustfmt`

  I did a test run (with `workflow_dispatch` and some minor changes to trigger the PR) in my fork.
  Check how the PR looks in https://github.com/realeinherjar/rust-bitcoin/pull/5
  Of course, all of these things can be changed.
  They are all suggestions...

  ## Security Disclaimer

  We are only introducing a new action, which is quite battle-checked, [`peter-evans/create-pull-request`](https://github.com/peter-evans/create-pull-request) with ~2k stars and proper maintained.

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

Tree-SHA512: c8728d03467913005fc92fefd4150a8041a495b0ec08b3a3397a05f381a59ef904e8afe6182509fd295ad1b23875b43206a2f1238a253542da54420e4805ab6f
2023-10-22 19:18:11 +00:00
Andrew Poelstra e436b5b900
Merge rust-bitcoin/rust-bitcoin#2132: Replace helper macro with helper function
b163d9b59a Replace hex_script macro with a helper function (yancy)
7f26439e20 Add track_caller to test helper functions (yancy)
bf08ee4499 Replace helper macro with helper function (yancy)

Pull request description:

  Remove the macro hex_psbt and replace with a function.  Using track_caller to accurately report the test name and line number during a panic is used in place of a macro.

  This is a refactor commit to the test suit.

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

Tree-SHA512: 6955c966d1c37020515ae990e5e0ec154f591ce025321dee71264e4e53cbab38afdb681ca193e626efdb7be4b4e84763cd8baf41b2a1258d34c38acd58713254
2023-10-22 13:16:42 +00:00
Einherjar d391ada5b8
ci: nightly rustfmt PR scheduled/manual 2023-10-22 05:34:16 -03:00
yancy b163d9b59a Replace hex_script macro with a helper function
Remove the macro hex_script and replace with a function.  Using
track_caller to accuretly report the test name and line number
during a panic is used in place of a macro.
2023-10-20 10:20:23 +02:00
yancy 7f26439e20 Add track_caller to test helper functions
The test helper files can panic when calling hex_psbt().  hex_psbt()
will report the calling function, instead of the offending test.  Adding
track_caller to functions that call hex_psbt will report the line number
of the failing test.
2023-10-20 09:41:50 +02:00
yancy bf08ee4499 Replace helper macro with helper function
Remove the macro hex_psbt and replace with a function.  Using
track_caller to accuretly report the test name and line number
during a panic is used in place of a macro.
2023-10-20 09:25:00 +02:00
Andrew Poelstra fe07c13bcc
Merge rust-bitcoin/rust-bitcoin#2131: encode: Implement encoding traits on Vec<BlockHeader>
10c1f7b9c6 encode: Implement encoding traits on Vec<BlockHeader> (Steven Roose)

Pull request description:

ACKs for top commit:
  clarkmoody:
    ACK 10c1f7b9c6
  apoelstra:
    ACK 10c1f7b9c6
  vincenzopalazzo:
    ACK 10c1f7b9c6

Tree-SHA512: 32182f4b18a2e4aee20efc4c649827be4e2f61991fae48d7e1360e2c8224bcd98ef89391b50ec2d4e12a720daf7350ca0beb23094153313b668a54cee9cda278
2023-10-19 15:38:54 +00:00