Commit Graph

69 Commits

Author SHA1 Message Date
Jamil Lambert, PhD 2fbbc825c9
Allow uninlined format args
There is a new lint error on nightly-2025-04-25 "variables can be used
directly in the `format!` string".

Exclude the lint to allow the existing syntax in `format!` strings.
2025-05-06 09:49:02 +01:00
Fmt Bot 6737c3a0e5 2025-04-27 automated rustfmt nightly 2025-04-27 01:36:56 +00:00
Tobin C. Harding d6296cd3d1
Remove usage of hex::test_hex_unwrap
We have the `hex_lit` dependency for converting a hex string literal
to an array.

Currently we have a `test_hex_unwrap` macro in the `hex v0.3.0` release
but not on either `master` or the upcoming `v1.0.0-alpha.0` release.
This is making PRs around releasing and depending on the release more
noisy than required.

Use `hex_lit::hex` where possible (often needing an additional call to
`to_vec()`) and where not possible use `Vec::from_hex`.
2025-04-11 06:49:06 +10:00
merge-script 59524adafd
Merge rust-bitcoin/rust-bitcoin#4295: Automated nightly rustfmt (2025-03-30)
b8910e201e 2025-03-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 b8910e201ea4374bb0508aa50c6779d080ef6484; successfully ran local tests

Tree-SHA512: 9bd89439304322d30e04aae8f9803f9e07830b616cb49339ac4b1e0ee1bfe440865d9ebc7f41eea1bcd35cb751060215eec20d258d88e9f20dd3f905b9ab690f
2025-03-30 19:37:31 +00:00
Fmt Bot b8910e201e 2025-03-30 automated rustfmt nightly 2025-03-30 01:27:51 +00:00
VolodymyrBg 6ebdf61e76 Fix grammatical typos
Fix grammar and typos in documentation and README
2025-03-27 20:49:19 +02:00
Eval EXEC 9a572dabde
refactor: use path dependencies for workspace members in bitcoin/Cargo.toml
Signed-off-by: Eval EXEC <execvy@gmail.com>
2025-03-27 12:55:16 +08:00
merge-script 4525fd3cad
Merge rust-bitcoin/rust-bitcoin#4263: docs: fix LICENSE link
d0bead6f94 docs: fix LICENCE link (jike)

Pull request description:

  ![image](https://github.com/user-attachments/assets/9c08a57e-e958-487f-ba9d-978bd6fde913)

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

Tree-SHA512: 148ea7c35ca8872e314e12889cab325af6965f533abea062c49d03809d57de3b476a97d39e2ae4e0c8479da263b7959c9cf2409050e3888af33b308c022391b1
2025-03-24 19:10:56 +00:00
jike d0bead6f94 docs: fix LICENCE link 2025-03-23 11:41:07 +00:00
Martin Habovstiak 5dd0c9253d Remove a bunch of `try_into().expect()`
Previously we've used `try_into().expect()` because const generics were
unavailable. Then they became available but we didn't realize we could
already convert a bunch of code to not use panicking conversions. But we
can (and could for a while).

This adds an extension trait for arrays to provide basic non-panicking
operations returning arrays, so they can be composed with other
functions accepting arrays without any conversions. It also refactors a
bunch of code to use the non-panicking constructs but it's certainly not
all of it. That could be done later. This just aims at removing the
ugliest offenders and demonstrate the usefulness of this approach.

Aside from this, to avoid a bunch of duplicated work, this refactors
BIP32 key parsing to use a common method where xpub and xpriv are
encoded the same. Not doing this already led to a mistake where xpriv
implemented some additional checks that were missing in xpub. Thus this
change also indirectly fixes that bug.
2025-03-20 20:19:50 +01:00
Peter Todd 1bb3d6a371
Minor: fix typo 2025-03-05 18:17:50 +00:00
Fmt Bot 8bdd67a368 2025-01-12 automated rustfmt nightly 2025-01-12 01:23:13 +00:00
Shing Him Ng f94c7185fd Remove usage of impl_from_infallible in crates
Rust macros, while at times useful, are a maintenance nightmare. And
we have been bitten by calling macros from other crates multiple times
in the past.

In a push to just use less macros remove the usage of the
`impl_from_infallible` macro in the bitcoin, units, and internals crates
and just write the code.
2025-01-04 23:46:12 -06:00
Tobin C. Harding 85e04315d5
Remove test_ prefix from unit tests
There is a loose convention in Rust to not use `test_` prefix. The
reason being that `cargo test` outputs 'test <test name>' using the
prefix makes the output stutter.

This patch smells a bit like code-churn but having the prefix in some
places and not others is confusing to new contributors and is leading me
to explain this many times now. Lets just fix it.

Remove the prefix unless doing so breaks the code.
2025-01-02 10:06:50 +11:00
calciumbe bfac237287
base58: fix typo 2024-12-23 20:40:31 +08:00
Tobin C. Harding b5f553d866
hashes: Bump version to 0.16.0
We need to do a quick release because it turns out I was wrong in
thinking that making `hex` an optional dependency is not a breaking
change.

```
the package `bitcoin` depends on `bitcoin_hashes`, with features: `hex`
but `bitcoin_hashes` does not have these features. It has a required
dependency with that name, but only optional dependencies can be used as
features.
```

Add a changelog, bump the version, depend on the new version repo wide,
and update the lock files - like its our job.
2024-12-16 12:41:17 +11:00
Tobin C. Harding 5b3e4ab95b
base58ck: Bump version to 0.2.0
In preparation for release add a changelog entry, bump the version, and
update the lock files.
2024-12-10 13:47:29 +11:00
Fmt Bot 5ecf7f2d67 2024-11-03 automated rustfmt nightly 2024-11-03 01:21:14 +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
merge-script fe8c6455a4
Merge rust-bitcoin/rust-bitcoin#3533: base58: Close all errors
c92290278e base58: Close all errors (Tobin C. Harding)

Pull request description:

  Currently we have a bunch of public errors in the `base58` crate. Only two are returned by public functions `decode()` and `decode_check()` (`Error` and `InvalidCharacterError` respectively).

  - Close the two public errors by adding private inner errors.
  - Add getters on the public errors to get the error data.
  - Make all other errors private.
  - Call `impl_from_infallible` for _all_ error types.

  Done as part of #3261

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

Tree-SHA512: e2ecef89691b41dfcc8ea3ef02c3719c45c72dbb252c76eadd97d03e32518ac7e00a2623d753de947d607ac3edf785f1ffdef8178a4f17ac3e7fd26ee01031ab
2024-10-31 18:25:36 +00:00
Leo Nash 7f289a9fdf Bump hex-conservative to 0.3.0 2024-10-31 03:36:22 +00:00
Tobin C. Harding c92290278e
base58: Close all errors
Currently we have a bunch of public errors in the `base58` crate. Only
two are returned by public functions `decode()` and
`decode_check()` (`Error` and `InvalidCharacterError` respectively).

- Close the two public errors by adding private inner errors.
- Add getters on the public errors to get the error data.
- Make all other errors private.
- Call `impl_from_infallible` for _all_ error types.

Done as part of #3261
2024-10-31 13:59:57 +11:00
Tobin C. Harding e68da281ff
Warn on future deprecations
We use `TBD` in our `deprecated` string and it was discovered that there
is an exception on this string so as not to warn because it is used
internally by the Rust language. However there is a special lint to
enable warnings, lets use it.

Add `#![warn(deprecated_in_future)]` to the coding conventions section
of all crates except `fuzz`.
2024-10-15 07:56:06 +11:00
Fmt Bot f1733309e0 2024-10-13 automated rustfmt nightly 2024-10-13 01:20:28 +00:00
Tobin C. Harding 3b7ba4f977
Remove the SliceIndex implementation from hash types
If folk really want to index into a hash they can us `as_byte_array`
then index that.

Includes a bump to the version number of `hashes` to `v0.15.0` - this
is because otherwise `secp` won't build since we are breaking an API
that is used in the current release of secp.

Fix: #3115
2024-10-02 10:18:45 +10:00
merge-script 6338f7c973
Merge rust-bitcoin/rust-bitcoin#3375: Release tracking PR: `bitcoin-internals 0.4.0`
18110a51f2 Bump version of internals to 0.4.0 (Tobin C. Harding)

Pull request description:

  In preparation for releasing `internals v0.4.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 `internals`.

ACKs for top commit:
  apoelstra:
    ACK 18110a51f2 successfully ran local tests; lots of nice stuff here

Tree-SHA512: a4d3d5279b7d7fa993cbc3b7b34fc6dc4024dd54c0bfa1ecd0f0d5f09b984871f156c3695092a1f6c44b7571f8b2051699040f5f77636d44d4cae6c972ab597f
2024-09-23 18:32:23 +00:00
Jamil Lambert, PhD fd89ddf401
Remove or fix unused variables and methods in docs
Examples in documentation are not linted in the same way as other code,
but should still contain correctly written code.

Throughout all of the crates except internals (another commit) unused
variables have been prefixed with `_`, unused imports have been removed,
and a warn attribute added to all of the `lib.rs` files.
2024-09-18 16:37:47 +01:00
Tobin C. Harding 18110a51f2
Bump version of internals to 0.4.0
In preparation for releasing `internals v0.4.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 `internals`.
2024-09-18 12:22:59 +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
Fmt Bot fa71b0e044 2024-09-01 automated rustfmt nightly 2024-09-01 01:22:04 +00:00
Chris Hyunhum Cho 441aac0a08
fix: vec! macro enabled only for test module 2024-08-26 04:44:01 -07:00
Chris Hyunhum Cho a050618fd8
feat: remove zeroed vector by pushing front 2024-08-23 07:46:47 -07:00
Tobin C. Harding 4b66a479b0
base58: Use u32 instead of usize
The `carry` variable is used as a value not as an array index so we
should use a `u32` - this is inline with other usage in the crate.
2024-08-07 05:33:31 +10:00
Tobin C. Harding 3f8cf1b335
base58: Use from and document cast
Done in an effort to reduce the cognitive load of reading the loop.

The base68 decode and encode algorithm uses a `u32` intentionally for
multiplication and a cast to `u8` intentionally when carrying.

Use `From` where possible and document the cast.
2024-08-06 05:49:30 +10:00
Tobin C. Harding 121b435a9b
base58: Use from to cast u8
`d58` is the iterator value from `Bytes` (iter returned by
`String::bytes`). As such we can infallibly convert it using `from`.

Internal change only, no external changes.
2024-08-05 06:22:41 +10: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
Fmt Bot d57ca72ed0 2024-07-14 automated rustfmt nightly 2024-07-14 01:11:56 +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
Martin Habovstiak d05723c401 Optimize base58 on small inputs
Most base58 strings in Bitcoin are somewhat short. There was previously
an "optimization" putting part of the input on stack which was removed
in #2759 because it actually made the code slower. This appears to be
mostly because of branches caused by using `iter::Chain`.

Manually splitting the iterations into two helped bring the performance
close to what #2759 achieved but that still wasn't worth it. But given
that we know the input length in many cases (it's just a slice) we can
determine whether it'll fit a buffer upfront and then just call
different functions which don't have the branches in loops. To avoid
having two functions this uses generics instead. Further, we increase
the buffer length to 128 and use `ArrayVec` from `internals` which
internally avoids initializing the buffer thanks to `MaybeUninit`

In total this increases performance by around 4% on my machine.
2024-07-11 06:40:47 +02: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
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 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
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 5ad7c245e3
cargo: whitelist all cfgs used in this repo 2024-05-22 13:32:24 +00:00
Andrew Poelstra 05293c1ab5
Merge rust-bitcoin/rust-bitcoin#2762: ci: shellcheck checks
021bea89bb ci: shellcheck checks (Jose Storopoli)

Pull request description:

  Closes #2739.

  I am proposing that we use this GitHub Shellcheck action:
  [`ludeeus/action-shellcheck`](https://github.com/ludeeus/action-shellcheck)
  since it has most stars (and eyes on it).

  I also did all fixes that I could find with

  ```bash
  shellcheck **/*.sh
  ```

  If I've missed any please let me know.

ACKs for top commit:
  apoelstra:
    ACK 021bea89bb
  tcharding:
    ACK 021bea89bb

Tree-SHA512: 67e37da9ae3ea0c5551af57b928016a2d9e76761af5558b3057ac47e773189629dd20eea9e659b4323c8568fb48dcdbe9ebd5c730f2c6266fb0db52886c9835f
2024-05-13 13:10:44 +00:00
Fmt Bot 56b41cdf59 2024-05-12 automated rustfmt nightly 2024-05-12 01:05:51 +00:00
Jose Storopoli 021bea89bb
ci: shellcheck checks 2024-05-11 18:08:53 +00:00
Riccardo Casatta 4646690521
fix clippy lint by using resize instead of push 2024-05-10 17:39:19 +02:00
Riccardo Casatta deeb160b86
remove SmallVec 2024-05-10 11:33:29 +02:00
Riccardo Casatta e4b707ba83 add bench for base58::encode_check 2024-05-10 11:26:45 +02:00