Commit Graph

4577 Commits

Author SHA1 Message Date
Fmt Bot ce3851d241 2024-08-18 automated rustfmt nightly 2024-08-18 01:12:19 +00:00
merge-script c00faa0458
Merge rust-bitcoin/rust-bitcoin#3176: Io improvements
56b19d0601 Add missing IO impls for `std` types (Martin Habovstiak)
5e30c9f190 Use macro to implement our traits for `std` types (Martin Habovstiak)
505ecd8a2e Move `std` impl from `lib.rs` to `bridge.rs` (Martin Habovstiak)
94768d3f70 Add `set_position` method to `Cursor` (Martin Habovstiak)
fc7e213f21 Add `bitcoin-io` -> `std` bridge (Martin Habovstiak)
54fdcb798b Add `std` -> `bitcoin-io` bridge (Martin Habovstiak)

Pull request description:

  This addresses significant API holes. Originally I wanted to add a commit that bumps the IO version but then I remembered we have #3162 which we most likely also want to merge and release.

  Closes #3174
  Closes #3175

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

Tree-SHA512: 9b0934da8dfd962c916c74032d734583175c6016f514861e24a29179c15925389a506ccf1b784a1bf99bc22909b5e7dcaece5fb689bd32f21ca0112ee798eca5
2024-08-17 16:54:52 +00:00
Tobin C. Harding bcbb0aea95
Merge rust-bitcoin/rust-bitcoin#3170: Automated daily update to rustc (to nightly-2024-08-14)
2ea815f84b Automated update to Github CI to rustc nightly-2024-08-14 (Update Nightly Rustc Bot)

Pull request description:

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

ACKs for top commit:
  tcharding:
    ACK 2ea815f84b

Tree-SHA512: d2c4bc4e985065176f2906c2e28899afb4a2a0d5f702b1100a610376a8024cd3fdfb322a29f833053972fe1738fe3321567ce9a89f0a40f662a6c5c168970f84
2024-08-17 07:50:43 +10:00
Martin Habovstiak 56b19d0601 Add missing IO impls for `std` types
Previously we've only implemented `bitcoin-io` traits for `BufReader`
and `BufWriter` with the reasoning that people should most likely use
those and implementing for other types is too much work. However since
then there were requests to implement them so we do in this commit.
2024-08-16 11:59:43 +02:00
Martin Habovstiak 5e30c9f190 Use macro to implement our traits for `std` types
We want to implement the traits for more types which would be tedious
without a macro and it'd risk forgetting to forward some method since
they may be speialized. This also adds previously-forgotten
specializations. It also relaxes the implicit `Sized` bound on
`BufReader` and `BufWriter` in Rust versions above 1.72.
2024-08-16 11:58:00 +02:00
Martin Habovstiak 505ecd8a2e Move `std` impl from `lib.rs` to `bridge.rs`
This reduces the number of compilation conditions.
2024-08-16 09:43:31 +02:00
Martin Habovstiak 94768d3f70 Add `set_position` method to `Cursor`
Without the ability to seek, the `Cursor` type is only useful for
wrapping owned buffers. In `std` the equivalent type also allows
seeking. We currently do not have the `Seek` trait so this simply adds a
method to set the position. Further, this adds a method to access inner
type so seeking from the end can be implemented (to compute the position
relative to the end).

Closes #3174
2024-08-15 21:57:21 +02:00
Martin Habovstiak fc7e213f21 Add `bitcoin-io` -> `std` bridge
This adds a reverse of the previous commit however it does not add
convenience methods since user should generally prefer the macro
instead. I had a clever idea to add a convenience conversion trait but
that is blocked by Rust stabilizing overlapping *marker* trait impls.
2024-08-15 21:57:10 +02:00
Martin Habovstiak 54fdcb798b Add `std` -> `bitcoin-io` bridge
When we've removed the blanket impl we forgot to replace it with a
bridge that would make the usage with `std` types easy. This change
implements the missing bridge forwarding all the methods and traits.
2024-08-15 21:26:38 +02: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
Update Nightly Rustc Bot 2ea815f84b Automated update to Github CI to rustc nightly-2024-08-14 2024-08-15 01:24:07 +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
Tobin C. Harding 3d85ee3a02
primitives: Fix alloc feature
We have an `alloc` feature but we are unconditionally using
`extern crate alloc`, this is broken - clearly we need to add a `no-std`
build for `primitives` in CI.

Feature gate the `alloc` crate.

While we are at it just pull types in from `alloc` in the `prelude` - I
have no idea why we do not do this in `bitcoin`?
2024-08-13 05:23:10 +10:00
merge-script 5d8f4b2492
Merge rust-bitcoin/rust-bitcoin#3156: impl IndexMut for PushBytes (already has Index) and fix/add docs
7c8601a696 implement IndexMut for PushBytes (Antoni Spaanderman)
71d760b3f2 Add and fix documentation on PushBytes's functions (Antoni Spaanderman)

Pull request description:

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

Tree-SHA512: a600dcda638cc727c2a31917e76c2e2f6da57b7044d571a345a919f1c471e0d30b82326492716eacfd9b3ce65c4484430bdd0f2d8ebbd220107cd9259a9faaa6
2024-08-12 13:30:01 +00:00
Tobin C. Harding f5a9f58fbf
Merge rust-bitcoin/rust-bitcoin#3159: Automated daily update to rustc (to nightly-2024-08-11)
dcce7b969b Automated update to Github CI to rustc nightly-2024-08-11 (Update Nightly Rustc Bot)

Pull request description:

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

ACKs for top commit:
  tcharding:
    ACK dcce7b969b

Tree-SHA512: bb87ffd521111e555692658aca0e8047638850de7d3c3f7191fe548619e48f2707a8a45df5f1c8a55ec0ae822850efa2fcf24b27898ba3054a63862b7d971b82
2024-08-12 20:01:33 +10:00
Update Nightly Rustc Bot dcce7b969b Automated update to Github CI to rustc nightly-2024-08-11 2024-08-12 01:37:45 +00: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 6dcb6f33fb
Merge rust-bitcoin/rust-bitcoin#3118: Automated weekly update to rustc stable (to 1.80.1)
78f091fb3f Automated update to Github CI to rustc stable-1.80.1 (Update Stable Rustc Bot)

Pull request description:

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

ACKs for top commit:
  tcharding:
    ACK 78f091fb3f

Tree-SHA512: c95cd7a0abf4b47474cdf4b52b7f18d672c62e7e2bb397659c12214688bd0ab7a67ec35935ada3b7ba6867ac48a8867c63976d5b87b5efd2b567207d1034ea3d
2024-08-10 08:01:09 +10:00
Update Stable Rustc Bot 78f091fb3f Automated update to Github CI to rustc stable-1.80.1 2024-08-09 00:50:11 +00:00
merge-script c22aea50ec
Merge rust-bitcoin/rust-bitcoin#3144: githooks: remove unnecessary shellcheck disables
a0febf7eed githooks: remove unnecessary shellcheck disables (Jose Storopoli)

Pull request description:

  We don't need to worry about nested quoting in SC2046.

  Thanks to Kixunil in https://github.com/rust-bitcoin/rust-secp256k1/pull/697 for pointing that out.

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

Tree-SHA512: 83cdcc55c7e7922c05f5e78305086595a96745f34ea68ee99ed1c08c97683bd45d3c62e8d8b4bcba6b0572c9c65178ff4e21abd7178e2e8b0c9e42f4b25508fb
2024-08-08 22:45:32 +00:00
merge-script 8ac0e60d84
Merge rust-bitcoin/rust-bitcoin#3140: primitives: Fix alloc feature
3b5bcd0983 primitives: Fix alloc feature (Tobin C. Harding)

Pull request description:

  We have an `alloc` feature but we are unconditionally using `extern crate alloc`, this is broken - clearly we need to add a `no-std` build for `primitives` in CI.

  Feature gate the `alloc` crate.

  While we are at it just pull types in from `alloc` in the `prelude` - I have no idea why we do not do this in `bitcoin`?

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

Tree-SHA512: f042dfb368dc0bde16237764a0dd09def7eeeb59291a5dbb1b5bd5f1dcd49b3adf66c12508c3be4f0ff48b52cd31cbb20edea68d9d55760e99c506ac5b114781
2024-08-08 21:18:09 +00: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
merge-script 74a5959479
Merge rust-bitcoin/rust-bitcoin#3139: Remove build cfg for versions less than MSRV
abe7b3f202 Remove build cfg for versions less than MSRV (Tobin C. Harding)

Pull request description:

  Recently we upgraded the MSRV but forgot to remove the Rust version specific `cfg`s.

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

Tree-SHA512: eabfdeb3217a5af8eae69e6f3589044f71b649c23b411525fb0401c2c3866dcd4c64f22ef927765f12584c223186ff850a60e71ee065476d39d5d557c5807e92
2024-08-08 15:24:05 +00:00
Jose Storopoli a0febf7eed
githooks: remove unnecessary shellcheck disables 2024-08-08 07:06:00 -03: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
merge-script 5dd20ddfb0
Merge rust-bitcoin/rust-bitcoin#3142: Automated daily update to rustc (to nightly-2024-08-07)
108047ce96 Automated update to Github CI to rustc nightly-2024-08-07 (Update Nightly Rustc Bot)

Pull request description:

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

ACKs for top commit:
  tcharding:
    ACK 108047ce96

Tree-SHA512: 70114c69b98ff4d769af3ca37097bbbffb6f0b4e429ba7fe4d8a13786e3a70ec5e68c92cd4c05781e5ad8a3096d2151befbb312d06f74cf5ea74d104b4ebf313
2024-08-08 13:34:33 +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
Update Nightly Rustc Bot 108047ce96 Automated update to Github CI to rustc nightly-2024-08-07 2024-08-08 01:34:58 +00:00
Tobin C. Harding 3b5bcd0983
primitives: Fix alloc feature
We have an `alloc` feature but we are unconditionally using
`extern crate alloc`, this is broken - clearly we need to add a `no-std`
build for `primitives` in CI.

Feature gate the `alloc` crate.

While we are at it just pull types in from `alloc` in the `prelude` - I
have no idea why we do not do this in `bitcoin`?
2024-08-08 10:57:38 +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