Commit Graph

127 Commits

Author SHA1 Message Date
Tobin C. Harding 38c329c1b7
Add additional catagories
Add `no-std` category to the soon-to-be-released leaf crates.
Also add `cryptography` to the `bitcoin_hashes` crate.

Close: #3731
2024-12-12 15:14:26 +11:00
merge-script 33f6d028ab
Merge rust-bitcoin/rust-bitcoin#3722: clippy: Set avoid-breaking-exported-api to false
adaf4ac086 Set avoid-breaking-exported-api to false (Tobin C. Harding)

Pull request description:

  These lints are valuable, lets get at em.

ACKs for top commit:
  apoelstra:
    ACK adaf4ac086553674803fadfde776d6dd013a7964; successfully ran local tests; will probably be a problem repeatedly for the next few days until we get through all currently-open PRs

Tree-SHA512: 56617a2f4aeafceef72008232cee817d45b62c040d7f1938631291c5d73627851cfbefc4b4000cd380ecb5c7e1379d1022f6cc90a4b68c819c78fb883bee0b3a
2024-12-11 15:41:06 +00:00
merge-script 540c712dc7
Merge rust-bitcoin/rust-bitcoin#3712: primitives: Add `must_use`
549be547ac primitives: Add must_use (Tobin C. Harding)

Pull request description:

  Enable lint `clippy::return_self_not_must_use` and add attribute `must_use` as required.

  Also run the linter with `clippy::must_use_candidate` enabled and manually check every warning site.

  Done as part of #3185

ACKs for top commit:
  apoelstra:
    ACK 549be547accdb13037bf3ef60310ca30d045dce0; successfully ran local tests; nice! will one-ACK merge
  sanket1729:
    ACK 549be547ac

Tree-SHA512: b22a6849fd0f4a7b65e1a9816efd47d411dcf2a5d5d46ae75b2b4d2389d3c9f46ab271314b112de9cd6fdc52cac7b53a632642e9bd90092d7065a8646e1362ec
2024-12-11 12:55:48 +00:00
Tobin C. Harding adaf4ac086
Set avoid-breaking-exported-api to false
These lints are valuable, lets get at em.

Changes are API breaking but because the changes make functions consume
self for types that are `Copy` downstream should not notice the breaks.
2024-12-11 10:11:50 +11:00
Tobin C. Harding 549be547ac
primitives: Add must_use
Enable lint `clippy::return_self_not_must_use` and add attribute
`must_use` as required.

Also run the linter with `clippy::must_use_candidate` enabled and
manually check every warning site.

While we are at it change the current `must_use` usages to have no
message. We can always add a message later if needed.
2024-12-10 11:02:06 +11:00
Tobin C. Harding 6ae35be0db
primitives: Reduce alloc requirements
Recently we reduced the `alloc` requirements in `units` but we did not
propagate these changes up to `primitives`.

Remove a bunch of `alloc` feature gating from `primitives`.
2024-12-09 13:57:26 +11:00
Tobin C. Harding 77085a1fa1
units: Remove serde from amounts
The `Amount` and `SignedAmount` were not supposed to implement `serde`
traits by design because doing so implicitly uses sats. We provide two
modules `as_sat` and `as_btc` to allow users to explicitly serialize in
their preferred format.

In commit: `d57ec019d5 Use Amount type for TxOut value field` derives
were added for `serde` and we did not notice it during review.
2024-11-28 12:55:43 +11:00
Fmt Bot 500cd10802 2024-11-17 automated rustfmt nightly 2024-11-17 01:23:55 +00:00
merge-script d32422cdb7
Merge rust-bitcoin/rust-bitcoin#3611: Hashes: Make `hex` dependency optional
ec06028f63 hashes: Make hex dependency optional (Tobin C. Harding)
9dce0b4b8c Remove hex string trait bounds from GeneralHash (Tobin C. Harding)
766f498b33 Pull serde stuff out of impl_bytelike_traits macro (Tobin C. Harding)

Pull request description:

  This is done in 3 parts:

  1. Pull the `serde` stuff out of `impl_bytelike_traits` to fix the bug described here: https://github.com/rust-bitcoin/rust-bitcoin/issues/2654#issuecomment-2470716693
  2. Prepare the `hashes` trait by removing string/hex trait bounds from `GeneralHash` and also pull the hex/string stuff out of `impl_bytelike_traits`
  3. Make hex optional, including adding custom debug logic when `hex` feature is not enabled

  Patch 3 is tested in `hashes/embedded`, by the new `debug` unit test, and there is a `Midstate` unit test as well that covers the `Debug` impl.

  Close: #2654 - BOOM!

ACKs for top commit:
  apoelstra:
    ACK ec06028f63ba591a14c3a15cdfd410bb5ff1c09b; successfully ran local tests; nice!

Tree-SHA512: 85eb10d36a4581af6cd700f7ff876585bcc114c60e9864906e65659f3b3ee550fe6d9f40ca4230d870a9e23f0720723e11443ec329f16e40259a259b9be57466
2024-11-15 18:31:42 +00:00
Tobin C. Harding 53d3ab18b9
Bump version of bitcoin-primitives to 0.101.0
In preparation for releasing `primitives v0.101.0` bump the version
number, add a changelog entry, update the lock files, and depend on the
new version in all crates that depend on `primitives`.
2024-11-15 10:58:46 +11:00
Tobin C. Harding 175171d339
Make primitives re-exports uniform
Remove the whitespace, it should never have been there and put the
attributes in the same order.

Internal change only.
2024-11-15 10:58:46 +11:00
Tobin C. Harding 3e9267071f
primitives: Update crate level docs re allocator
We slightly improved the situation but much of the functionality is
still behind the `alloc` feature.
2024-11-15 10:58:45 +11:00
Tobin C. Harding 7819e50055
Move Block to primitives
On the way re-design the API by doing:

- Introduce `Checked` and `Unchecked` tags
- Rename the `txdata` field to `transactions`
- Make the `Block` fields private
- Add getters for `header` and `transactions` fields
- Move the various `compute_` methods to be free standing functions
- Make the `check_` functions private
- Introduce extension traits
2024-11-15 07:16:21 +11:00
Tobin C. Harding ec06028f63
hashes: Make hex dependency optional
The only reason we need `hex-conservative` is to parse strings and
format them as hex. For users that do not require this functionality we
can make the `hex-conservative` crate an optional dependency.

The `serde` feature requires `Display` so we enable `hex` from the
`serde` feature.

If `hex` feature is not enabled we still need to be able to debug so
provide `fmt::Debug` functionality by way of macros.

Close: #2654
2024-11-14 09:36:55 +11:00
merge-script 3d17ec962f
Merge rust-bitcoin/rust-bitcoin#3576: transaction: Add plural field getters
be553217f1 transaction: Add plural field getters (Tobin C. Harding)

Pull request description:

  The `Transaction` type was created way back when, and the field names were named using singular (`input` and `output`). In hindsite plural probably should have been used since its more idiomatic Rust but the fields have been around so long now that re-naming them is going annoy a whole bunch of people.

  As a compromise add getters that use plural, immutable and mutable versions, for both the `input` and `output` fields.

  Close: #822

ACKs for top commit:
  apoelstra:
    ACK be553217f19069dd9ca28c3ba5953059df9caa1b; successfully ran local tests; though will let this sit a couple days before merging
  sanket1729:
    ACK be553217f1

Tree-SHA512: 4df9db179a69c9eea2940008c9eca9f9b9b9d9f27e2a174db39bfb3d5c32a9d06b26e5349e5baf5af78600ae128d1b534559baf7335aec6df1238de96a508764
2024-11-13 17:42:55 +00:00
Tobin C. Harding 9dce0b4b8c
Remove hex string trait bounds from GeneralHash
For the `hashes` crate we would like to make `hex` an optional
dependency. In preparation for doing so do the following:

- Remove the trait bounds from `GeneralHash`
- Split the hex/string stuff out of `impl_bytelike_traits` into a
  separate macro.
2024-11-13 14:01:13 +11:00
Tobin C. Harding 766f498b33
Pull serde stuff out of impl_bytelike_traits macro
The `impl_bytelike_traits` macro is public and it is used in the
`hash_newtype` macro, also public.

Currently if a user calls the `hash_newtype` macro in a crate that
depends on `hashes` without the `serde` feature enabled and with no
`serde` dependency everything works. However if the user then adds a
dependency that happens to enable the `serde` feature in `hashes` their
build will blow up because `serde` code will start getting called from
the original crate's call to `hash_newtype`.

Pull the serde stuff out of `hash_newtype` and provide a macro to
implement it `impl_serde_for_newtype`.
2024-11-13 12:28:47 +11:00
Tobin C. Harding 195615c14d
Fix bug in witness stack getters
In #2646 we introduced a bug in the taproot witness stack getter
functions, of which we have three:

- `tapscript`
- `taproot_control_block`
- `taproot_annex`

Each returns `Some` if a possible bytes slice is found (with no other
guarantees).

Use `taproot_annex` combined with getters from `primitives` to implement
the other two getters. This simplifies the code and fixes the bug.

Add an additional getter to `primitives` `Witness::third_from_last`.

Fix: #3598
2024-11-13 10:55:51 +11:00
Tobin C. Harding 727c519efa
Re-export amount from primitives
We are trying to make it so that what ever crate a user uses they see
the same module/type tree (if the module or type exists).

E.g., one can do either of these.

If they use `bitcoin`:

```
use bitcoin::{
    amount, block, fee_rate, weight, merkle_tree, opcodes,
    pow, script, sequence, transaction, witness,
};
```

Or if they use `primitives`:

```
use bitcoin_primitives::{amount, block, fee_rate, weight};
```

The above imports were tested and `amount` was found to be missing.
2024-11-11 14:21:47 +11:00
Jamil Lambert, PhD 1649b68589
Standardize wording to `constructs a new`
There is a range of different wordings used in the docs of constructor
type functions.

Change all to start with `Constructs a new` or `Constructs an empty`.
2024-11-05 13:02:26 +00:00
Jamil Lambert, PhD 27f94d5540
Replace `creates` with `constructs`
In functions that act like constructors there is a mixture of the usage
of `creates` and `constructs`.

Replace all occurrences of `creates` with `constructs` in the first line
of docs of constructor like functions.
2024-11-05 12:47:28 +00:00
Tobin C. Harding be553217f1
transaction: Add plural field getters
The `Transaction` type was created way back when, and the field names
were named using singular (`input` and `output`). In hindsite plural
probably should have been used since its more idiomatic Rust but the
fields have been around so long now that re-naming them is going annoy a
whole bunch of people.

As a compromise add getters that use plural, immutable and mutable
versions, for both the `input` and `output` fields.

Close: #822
2024-11-04 15:07:54 +11:00
Tobin C. Harding 6555143478
bitcoin: Re-format crate level re-exports
Is there any advantage trying to lay out the re-exports to give users an
idea of the crate structure?

We have the explicit aim that users who depend on `bitcoin` do not ever
need to reach directly into `primitives` (or `units`) however it is kind
of nice to know where things come from, saves jumping to multiple files
looking for them (for those of us that jump to files manually).

I do not know how all the re-exports interact with other folks IDEs, I
personally open files manually and just remember where stuff is.
2024-11-04 08:49:03 +11:00
merge-script 794fb75497
Merge rust-bitcoin/rust-bitcoin#3562: Re-export `block::Header` as `BlockHeader`
85942c355d Re-export block::Header as BlockHeader (Tobin C. Harding)

Pull request description:

  For users who want to just grab stuff from the crate root it makes total sense for there to be a `BlockHeader`.

  Another nice thing, in the HMTL docs it makes BlockHeader be in the struct list right along with `Block`, `BlockHash`, and `BlockHeight`.

  Close: #3548

ACKs for top commit:
  apoelstra:
    ACK 85942c355dfdcf9ddf9a46202f4db56794dcc85d; successfully ran local tests
  jamillambert:
    ACK 85942c355d

Tree-SHA512: 6fbaf7936062323d31940179ffcbc62951b21f53955a42dca2e28476bda0cebeb041db0e1b4f1ceeac32e43d94fe5476ef055595ae88dc6cfc266d32082bdf4d
2024-11-03 17:02:38 +00:00
Fmt Bot 5ecf7f2d67 2024-11-03 automated rustfmt nightly 2024-11-03 01:21:14 +00:00
Tobin C. Harding 32bc68d4dc
primitives: Add rustdoc links back in
During move of code to `primitives` we removed a few links to types that
were not yet moved, we can now put these back in.

Feature all rustdoc imports on `alloc` and `doc`.

Close: #2997
2024-11-02 08:26:39 +11:00
Tobin C. Harding 85942c355d
Re-export block::Header as BlockHeader
For users who want to just grab stuff from the crate root it makes total
sense for there to be a `BlockHeader`.

Another nice thing, in the HMTL docs it makes BlockHeader be in the
struct list right along with `Block`, `BlockHash`, and `BlockHeight`.
2024-11-02 07:38:10 +11:00
merge-script c46171899a
Merge rust-bitcoin/rust-bitcoin#3551: primitives: Add missing re-exports
2b7cb04265 primitives: Add missing re-exports (Tobin C. Harding)

Pull request description:

  Add re-exports of types from `taproot` and `merkle_tree`.

ACKs for top commit:
  jamillambert:
    ACK 2b7cb04265
  apoelstra:
    ACK 2b7cb04265cdb2d62c1bcc645e19d8bafa132b4b; successfully ran local tests

Tree-SHA512: e837c8e7bfda3e8c5510a15ba19b2b0b433e9e87c961ab9ab81d134288b70bc98364007e8e610e7066732e16f72ea990a782cade9ead6b71ddc9b843753fa0ee
2024-11-01 15:23:39 +00:00
Tobin C. Harding 6aa8c2b023
Remove needless_borrows_for_generic_args
This has been fixed and we use nightly to lint so we have access to the
merged fix.

Removing the attribute uncovers a bunch of real lint warnings, fix
them while we are at it.
2024-11-01 14:30:45 +11:00
merge-script 4c8347a7ac
Merge rust-bitcoin/rust-bitcoin#3544: Favour `to_vec` over `to_bytes`
a51768af3f key: Deprecate to_bytes (Tobin C. Harding)
3af3239ad0 script: Re-order functions (Tobin C. Harding)
db40297f87 script: deprecate to_bytes (Tobin C. Harding)
c5cd0db493 Revert the change to to_bytes (Tobin C. Harding)
dc2ca785d2 Add to_vec and deprecate to_bytes for array types (Tobin C. Harding)
a6b7ab32a8 Move impl_array_newtype to internal_macros (Tobin C. Harding)

Pull request description:

  Use `to_vec` and deprecate `to_bytes`, the opposite of what we did in #2585.

  For functions that return a `Vec` by first allocating use function name `to_vec`. This explicitly excludes:

  - Functions that return an array (`CompressedPublicKey::to_bytes`)
  - Functions that consume self and return a `Vec` without allocating (`ScriptBuf::into_bytes`)

  See #3025 for discussion and consensus.

  Close: #3025

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

Tree-SHA512: ee932c13ad2e09c2b76a7833b23c859df175aa307f56e673921f3ae8b5d865518c6f999749e3b627594457b3ca33301b777177ada3520cf006acc0f14e5dacf8
2024-11-01 00:55:15 +00:00
merge-script 8bc2f39fca
Merge rust-bitcoin/rust-bitcoin#3547: Remove more wildcard re-exports
0bf1910980 Remove wildcard from script self re-exports (Tobin C. Harding)
397a4b9382 Remove wildcard in push_bytes module (Tobin C. Harding)

Pull request description:

  We thought #3436 was done (well I thought it was), turns out I was wrong.

ACKs for top commit:
  jamillambert:
    ACK 0bf1910980
  apoelstra:
    ACK 0bf1910980a13005496244ec4d4adf0553afbc73; successfully ran local tests

Tree-SHA512: 131a4aa4a907099790d14cfc2d19305943a2270cf6852c7dd92e35ea69188c9a40797fb22fd2ed8b2fefc2d6380b884401b5e32f521711f0f7b2da610d0e332f
2024-10-31 23:51:50 +00:00
merge-script 8af8bc7886
Merge rust-bitcoin/rust-bitcoin#3543: Bump hex-conservative to 0.3.0
7f289a9fdf Bump hex-conservative to 0.3.0 (Leo Nash)

Pull request description:

ACKs for top commit:
  tcharding:
    ACK 7f289a9fdf
  apoelstra:
    ACK 7f289a9fdf86604cc1ecfb31c6df0ea5bb175465; successfully ran local tests

Tree-SHA512: bf8543ef7dc9b7ec0d11659c0a53213be50b9bbae0e6ba6970a19d32b3d89025315fcae332c23d68582ef69ea5f8e6673192ff74316a1e3dc47521312bbc469e
2024-10-31 21:05:02 +00:00
Tobin C. Harding 2b7cb04265
primitives: Add missing re-exports
Add re-exports of types from `taproot` and `merkle_tree`.
2024-11-01 07:31:07 +11:00
Tobin C. Harding 3af3239ad0
script: Re-order functions
We want our code to be easy to read and our APIs discoverable, for those
of us who read source files the layout matters.

Put the constructors and getters at the top of the impl block.

Code move only, no logic changes.
2024-11-01 07:09:59 +11:00
Tobin C. Harding db40297f87
script: deprecate to_bytes
Deprecate the `Script::to_bytes` function in favour of `to_vec` as we
are doing elsewhere.

Note that `ScriptBuf` has `into_bytes` because it does not copy.
Potentially this should be deprecated in favour of `into_vec`?

Note that in regards to the `to_` prefix this naming as valid according
to convention because the `Script` type is borrowed and `to_vec` copies
the underlying bytes.
2024-11-01 07:09:53 +11:00
Tobin C. Harding c5cd0db493
Revert the change to to_bytes
During this release cycle we deprecated `to_vec` in favour of
`to_bytes`, we have since reversed our position on the name.

Remove the deprecation of `to_bytes` from the three types that had it
and use `to_vec`.
2024-11-01 07:09:11 +11:00
Tobin C. Harding 0bf1910980
Remove wildcard from script self re-exports
In the `script` module remove the wildcards and re-export stuff from
`self` explicitly in both `primitives` and `bitcoin`.

Internal change only, everything is re-exported.
2024-10-31 15:52:54 +11:00
Leo Nash 7f289a9fdf Bump hex-conservative to 0.3.0 2024-10-31 03:36:22 +00:00
Tobin C. Harding bafe11d7e4
Correctly feature gate impl_to_hex_from_lower_hex
Currently we feature gate code within the `impl_to_hex_from_lower_hex`
 macro on "alloc" but `bitcoin` does not have the "alloc" feature so
 this code is never built in. This can be seen by the lack of a
 `to_hex` function on `LeafVersion`.

Remove the feature gate from the macro and put it on the individual
call sites as needed.
2024-10-31 13:43:47 +11:00
Tobin C. Harding 57769f5f28
Fix ugly rustfmt
Fix some ugly formatting introduced by the fmt bot recently.

Whitespace only, no logic changes.
2024-10-31 13:38:27 +11:00
Tobin C. Harding f8f846bb9e
Move Transaction type to primitives
Needs no explanation - lets go!
2024-10-30 12:28:53 +11:00
Tobin C. Harding e84346644e
Run the formatter
Run `just fmt` - no other changes.
2024-10-30 11:30:24 +11:00
merge-script 1f578fc929
Merge rust-bitcoin/rust-bitcoin#3518: Automated nightly rustfmt (2024-10-27)
39f46a16bc 2024-10-27 automated rustfmt nightly (Fmt Bot)

Pull request description:

  Automated nightly `rustfmt` changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action

ACKs for top commit:
  tcharding:
    ACK 39f46a16bc
  apoelstra:
    ACK 39f46a16bc0da356f495166ccd5829627af3749b; successfully ran local tests

Tree-SHA512: 6c27714b18ad6957104246145a2d4243f8e43e378d63f3d946ba05ecaf859432f2fe363fe3e7a29a33c41297216fd1176c165ac55deb109f636813c637ff6c43
2024-10-28 21:34:59 +00:00
merge-script 6c54a1d2f2
Merge rust-bitcoin/rust-bitcoin#3497: Explicitly re-export stuff from crates down the stack
66da2266e2 Explicitly re-export stuff from crates down the stack (Tobin C. Harding)

Pull request description:

  Up until recently we were using wildcard re-exports for types moved to `units` and `primitives`. We have decided against doing so in favour of explicit re-exports.

  Audit `units` and `primitives` using `git grep 'pub enum'` (and `struct`) and explicitly re-export all types.

  Remove all wildcards except for the re-exports from `opcodes`, there are too many opcodes, explicitly re-exporting them does not aid clarity.

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

Tree-SHA512: 74717f8b127e975e3d131aab884bdfe78e699d88b7ee1db7731ad117437d37684285264001cf6b2182eb1e565171167695e00c4b6aef28a3e26b69d9cebfbb74
2024-10-28 19:20:23 +00:00
Tobin C. Harding 3e2c43b19e
Elide more lifetimes
clippy found some more lifetimes to elide.
2024-10-28 15:22:13 +11:00
Fmt Bot 39f46a16bc 2024-10-27 automated rustfmt nightly 2024-10-27 01:21:24 +00:00
Tobin C. Harding 66da2266e2
Explicitly re-export stuff from crates down the stack
Up until recently we were using wildcard re-exports for types moved to
`units` and `primitives`. We have decided against doing so in favour of
explicit re-exports.

Audit `units` and `primitives` using `git grep 'pub enum'` (and
`struct`) and explicitly re-export all types.

Remove all wildcards except for the re-exports from `opcodes`, there are
too many opcodes, explicitly re-exporting them does not aid clarity.
2024-10-27 06:45:58 +11:00
Tobin C. Harding 003dc9cf4d
Move TxOut to primitives
The `TxOut` has all public fields; move the `TxOut` to `primitives`.
2024-10-24 09:04:12 +11:00
Tobin C. Harding 4d37d7efc6
Move TxIn to primitives
The `TxIn` has all public fields; move the `TxIn` to `primitives`.
2024-10-24 09:04:12 +11:00
Tobin C. Harding 1b521dce99
Move taproot hash types to primitives
Move the three `taproot` hash types and their associated tags over to
the `primitives` crate.
2024-10-22 13:50:44 +11:00