Commit Graph

45 Commits

Author SHA1 Message Date
Steven Roose 875545517d
Add clippy exceptions for needless_question_mark lint 2023-10-23 16:45:52 +01:00
Tobin C. Harding 2512dbafc2
Remove impl_std_error macro
We would like the codebase to be optimized for readability not ease of
development, as such code that is write-once-read-many should not use
macros.

Currently we use the `impl_std_error` macro to implement
`std::error::Error` for struct error types. This makes the code harder
to read at a glance because one has to think what the macro does.

Remove the `impl_std_error` macro and write the code explicitly.
2023-10-04 15:15:34 +11:00
Tobin C. Harding bb8bd16302
internals: Remove hex module
Remove the now unused `hex` module from internals, this functionality is
now provided by the `hex-conservative` crate.
2023-07-21 10:59:47 +10:00
Andrew Poelstra c7eb9e61ec
Merge rust-bitcoin/rust-bitcoin#1916: internals: Bump version to 0.2.0
8813a63ec9 internals: Bump version to 0.2.0 (Tobin C. Harding)

Pull request description:

  In preparation for release bump the version and add a changelog entry. Includes updating the dependency in `bitcoin` and `hashes`.

ACKs for top commit:
  apoelstra:
    ACK 8813a63ec9
  sanket1729:
    utACK 8813a63ec9

Tree-SHA512: a9bd9d4d69cba21329f3f63a9948afe566bb97c8c65f5d46c329a696a814e9eb31372d378de1ecf0f43f0cb42f11d53dc51bc467223b34629e61315d48b39a29
2023-07-17 16:27:22 +00:00
Tobin C. Harding 71c0043127
Remove docsrs attributes
Somehow when we started using `doc_auto_cfg` we forgot to remove a bunch
of docsrs attributes.
2023-07-14 14:59:11 +10:00
Tobin C. Harding 8813a63ec9
internals: Bump version to 0.2.0
In preparation for release bump the version and add a changelog entry.

Includes updating the dependency in `bitcoin` and `hashes` as well as
the minimal/recent lock files.
2023-07-14 14:31:21 +10:00
Martin Habovstiak 2b6bcf085c Implement support for `alloc`-free parse errors
This implements basic facilities to conditionally carry string inputs in
parse errors. This includes:

* `InputString` type that may carry the input and format it
* `parse_error_type!` macro creating a special type for parse errors
* `impl_parse` implementing parsing for various types as well as its
  `serde`-supporting alternative
2023-06-04 21:15:37 +02:00
Martin Habovstiak 783e1e81dc Move `impl_std_error` to `bitcoin-internals`
The macro is useful for all other crates thus it is moved to the
internals crate in this commit.
2023-05-30 18:04:54 +02:00
Andrew Poelstra ca06d64455
rename bitcoin-private to bitcoin-internals
Since we now have control over the name on crates.io.
2023-05-26 19:49:52 +00:00
Andrew Poelstra ac664106be
Merge rust-bitcoin/rust-bitcoin#1829: Remove `min_value` and `max_value`
6cab7beba3 Deprecate min/max_value methods (Tobin C. Harding)
5fbbd483ea Use MIN/MAX consts instead of min/max_value (Tobin C. Harding)
3885f4d430 Add MIN/MAX consts to amounts (Tobin C. Harding)

Pull request description:

  The new MSRV (1.48.0) uses associated consts MAX/MIN instead of functions, we had functions to be compliant with the old MSRV.

  ~Remove all methods `min_value` and `max_value` including calls to these methods on stdlib types.~

  PR is now split into three patches:
  - patch 1: Add missing associated consts MIN/MAX as needed
  - patch 2: Use consts instead of method calls
  - patch 3: Deprecate methods `min_value` and `max_value`

ACKs for top commit:
  sanket1729:
    ACK 6cab7beba3
  apoelstra:
    ACK 6cab7beba3
  Kixunil:
    ACK 6cab7beba3

Tree-SHA512: 60949d1bb971e0dfbab7f573b4447f889b5fa1a5f1c9ac9325a2970fe17a19ccc93418dba57f07bed7e13864b130de48b6b3741d1d80266c6144237dd4565ff7
2023-05-04 12:59:56 +00:00
Andrew Poelstra 23d80bf1ab
Merge rust-bitcoin/rust-bitcoin#1764: Test with minimal dependency versions
c4c64c0dc5 Test with minimal dependency versions (Martin Habovstiak)
d5655d503a Bump core2 dependency from 0.3.0 -> 0.3.2 (Tobin C. Harding)

Pull request description:

  This is work originally done by Kixunil in #1272, I picked it up to help out. The only changes I made were rebasingg, updating the recent lock file, adding `--locked` to hashes contrib file,  and adding a co-developed-by tag for accountability.

  It could happen that we unknowingly depend on a new version of a crate without updating `Cargo.toml`. This could cause resolution issues for downstream users. It's also unclear for outsiders to know with which dependencies did we test the crate.

  This change commits two lock files: `minimal` and `recent`. `minimal` contains minimal dependency versions, while `recent` contains dependency versions at the time of making the change.

  Further, this adds CI jobs to test with both lock files, CI job for `internals` crate, removes old `serde` pinning and prints a warning if `recent` is no longer up to date. (We may have to override it somehow if any crate breaks MSRV.)

  The documentation is also updated accordingly.

  Closes #1230

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

Tree-SHA512: 7d386e96ab747f6a6bafeea828ac65bd8bb11975eaa3408acecac369cd2f235f6e9d4c57202be18a3dc2eeb2a2df532d73e4d35cd1f3fbf092eb6414c55b1524
2023-05-03 22:35:21 +00:00
Tobin C. Harding 5fbbd483ea
Use MIN/MAX consts instead of min/max_value
We currently use the functions `min_value` and `max_value` because the
consts were not available in Rust 1.41.1, however we recently bumped the
MSRV so we can use the consts now.
2023-05-03 08:22:30 +10:00
Martin Habovstiak c4c64c0dc5
Test with minimal dependency versions
It could happen that we unknowingly depend on a new version of a crate
without updating `Cargo.toml`. This could cause resolution issues for
downstream users. It's also unclear for outsiders to see which
dependencies we tested the crate with.

This change commits two lock files: `minimal` and `recent`. `minimal`
contains minimal depdendency versions, while `recent` contains
dependency versions at the time of making the change.

Further, this adds CI jobs to test with both lock files, CI job for
`internals` crate, removes old `serde` pinning and prints a warning if
`recent` is no longer up to date. (We may have to override it somehow if
any crate breaks MSRV.)

The documentation is also updated accordingly.

Co-developed-by: Tobin C. Harding <me@tobin.cc>

Closes #1230
2023-05-03 08:06:46 +10:00
Tobin C. Harding 1c3bbd4bf2
internals: Remove attribution from all files
As we did for the `bitcoin` crate, remove attribution from all files in
the `internals` crate.

While we are at it add an SPDX line to the few files missing it, whether
this license nonsense is even needed is left as an argument for another
day.

Justification:

Currently we have a mishmash of attribution lines accompanying the SPDX
identifier. These lines are basically meaningless because:

    - The date is often wrong
    - The original author attributed is not the only contributor to a file
    - The term "rust bitcoin developers" is basically just noise

Just remove all the attribution lines and be done with it.
2023-05-01 09:31:42 +10:00
Tobin C. Harding a189942c64
Use doc_auto_cfg
If we use `#![cfg_attr(docsrs, feature(doc_auto_cfg))]` instead of
`#![cfg_attr(docsrs, feature(doc_cfg))]` we no longer need to manually
mark types with `#[cfg_attr(docsrs, doc(cfg(feature = "std")))]`.

Sweeeeeet.
2023-03-29 14:50:33 +11:00
Tobin C. Harding 1dc04fe10f
Remove rust_v_1_46
We just bumped the MSRV to 1.48.0 so we know that we have all features
from 1.46, no need for `rust_v_1_46` check anymore.
2023-03-23 08:27:10 +11:00
Andrew Poelstra 51f2f8483c
rename bitcoin-internals to bitcoin-private 2023-03-13 16:02:12 +00:00
Andrew Poelstra be02045561
update internals CHANGELOG for release 2023-03-08 02:39:15 +00:00
Tobin C. Harding c1360067e9
Enable formatting in CI
Enable formatting in CI by doing:

- Add a section to the `test.sh` scripts to run the formatter (guarded by
  the env variable `DO_FMT`) for all crates (bitcoin, hashes, internals).
- Add `DO_FMT` to the nightly `Tests` CI job.
2023-03-07 08:57:32 +11:00
Tobin C. Harding a11cf07501
Run the formatter
Various formatting issues have crept into the codebase because we do not
run the formatter in CI.

In preparation for enabling formatting checks in CI run `cargo +nightly
fmt` to fix current formatting issues. No changes other than those
create by the formatter.
2023-03-06 10:22:29 +11:00
Harshil Jani a1c3082319 Move deny lint checks to script
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
2023-02-14 10:48:24 +05:30
Tobin C. Harding 8596e402f2
Fix docs.rs to use all features
Many moon ago we were unable to build with `--all-features`, this is no
longer the case.

Instruct docs.rs to build the docs with `--all-features`.
2023-02-10 08:04:11 +11:00
Tobin C. Harding 12f5e37ed9
Add excludes to manifests
We can check which files are included in the packaged release with
 `cargo package --list `.

Add an `exclude` section to each manifest that excludes `tests/` and
`contrib/`. Not all crates have a `tests/` directory yet but they should
so add the exclude anyway to future proof the crates.
2023-02-08 08:24:49 +11:00
Tobin C. Harding f4e7def72f
internals: Add CI test script
We do not currently run the `internals` crate tests in CI. Bad
rust-bitcoin developers, no biscuit.
2023-01-13 07:59:38 +11:00
Tobin C. Harding db6b3f1df5
Fix method names in rustdoc
We have a few incorrect method names in the rustdocs for `internals`,
fix them up.
2023-01-13 07:44:51 +11:00
Martin Habovstiak 1b0988833a Remove `ToHex`
The `ToHex` trait was replaced by either simple `Display`/`LowerHex`
where appropriate or `DisplayHex` from `bitcoin_internals` which is
faster.

This change replaces the usages and removes the trait.
2023-01-07 19:50:03 +01:00
Andrew Poelstra d06bb226bf
Merge rust-bitcoin/rust-bitcoin#1476: Use hex from internals rather than hashes
3e520f9094 Use hex from internals rather than hashes (Martin Habovstiak)

Pull request description:

  `bitcoin-internals` contains a more performant implementation of hex encoding than what `bitcoin_hashes` uses internally. This switches the implementations for formatting trait implementations as a step towards moving over completely.

  The public macros are also changed to delegate to inner type which is technically a breaking change but we will break the API anyway and the consuers should only call the macro on the actual hash newtypes where the inner types already have the appropriate implementations.

  Apart from removing reliance on internal hex from public API this reduces duplicated code generated and compiled. E.g. if you created 10 hash newtypes of SHA256 the formatting implementation would be instantiated 11 times despite being the same.

  To do all this some other changes were required to the hex infrastructure. Mainly modifying `put_bytes` to accept iterator (so that `iter().rev()` can be used) and adding a new `DisplayArray` type. The iterator idea was invented by Tobin C. Harding, this commit just adds a bound check and generalizes over `u8` and `&u8` returning iterators.

  While it may seem that `DisplayByteSlice` would suffice it'd create and initialize a large array even for small arrays wasting performance. Knowing the exact length `DisplayArray` fixes this.

  Another part of refactoring is changing from returning `impl Display` to return `impl LowerHex + UpperHex`. This makes selecting casing less annoying since the consumer no longer needs to import `Case` without cluttering the API with convenience methods.

ACKs for top commit:
  tcharding:
    ACK 3e520f9094
  apoelstra:
    ACK 3e520f9094

Tree-SHA512: 62988cec17550ed35990386e572c0d32dc7107e1c36b7c9099080747e15167e6d66497fb300178afbd22481c0360a6b7a1228fd09402d4ce5d295a8594c02aa6
2022-12-31 19:17:32 +00:00
Martin Habovstiak 64f7d2549e Fix wrong newtype APIs
This fixes several API bugs:

* Use `TryFrom` instead of `From` for fallible conversions
* Move byte conversion methods from `impl_array_newtype` to
  `impl_bytes_newtype`
* Add missing trait impls like `AsRef`, `Borrow`, their mutable versions
  and infallible conversions from arrays

Closes #1336
2022-12-23 01:28:17 +01:00
Martin Habovstiak 3e520f9094 Use hex from internals rather than hashes
`bitcoin-internals` contains a more performant implementation of hex
encoding than what `bitcoin_hashes` uses internally. This switches the
implementations for formatting trait implementations as a step towards
moving over completely.

The public macros are also changed to delegate to inner type which is
technically a breaking change but we will break the API anyway and the
consuers should only call the macro on the actual hash newtypes where
the inner types already have the appropriate implementations.

Apart from removing reliance on internal hex from public API this
reduces duplicated code generated and compiled. E.g. if you created 10
hash newtypes of SHA256 the formatting implementation would be
instantiated 11 times despite being the same.

To do all this some other changes were required to the hex
infrastructure. Mainly modifying `put_bytes` to accept iterator (so that
`iter().rev()` can be used) and adding a new `DisplayArray` type. The
iterator idea was invented by Tobin C. Harding, this commit just adds a
bound check and generalizes over `u8` and `&u8` returning iterators.

While it may seem that `DisplayByteSlice` would suffice it'd create and
initialize a large array even for small arrays wasting performance.
Knowing the exact length `DisplayArray` fixes this.

Another part of refactoring is changing from returning `impl Display` to
return `impl LowerHex + UpperHex`. This makes selecting casing less
annoying since the consumer no longer needs to import `Case` without
cluttering the API with convenience methods.
2022-12-22 10:44:27 +01:00
Andrew Poelstra 1b15a13e5a
run cargo clippy and fmt 2022-12-13 14:52:43 +00:00
Tobin C. Harding fb708ca74b Add newline after brief description
rustdocs should contain a newline to separate the brief description from
the rest of long description.
2022-12-06 12:25:04 +11:00
Martin Habovstiak a6ecc58a5e Add `put_bytes_min` and `space_remaining` methods
Pnicking on oversized slice is useful to catch errors in code that's
supposed to know the exact sizes but this is undesirable in code that
doesn't. These two methods help with handling the case when `buf.len()`
is not known upfront.
2022-12-02 10:48:05 +01:00
Tobin C. Harding 580feab3f9 internals: Add CHANGELOG file
The changelog file is a per crate, per release, thing. Add one to the
`internals` crate.
2022-11-08 08:40:44 +11:00
Tobin C. Harding 8c4fa5ec3d Remove into_bytes from impl_array_newtype
All the types that we define with `impl_array_newtype` are
`Copy` so the correct conversion method to get the underlying byte array
is `to_bytes`. We currently provide `into_bytes` as well as `to_bytes`,
with one of them calling `clone` - this is unnecessary and against
convention.

- Remove `into_bytes` and for `to_bytes` just return the inner field.
- Add a method that causes build to fail if `Copy` is not implemented.
2022-11-05 06:57:40 +11:00
Tobin C. Harding 53b681b838 Move const_assert to bitcoin_internals
This is an internal macro, now that we have the `internals` crate put
`const_assert` in it.
2022-10-20 06:15:44 +11:00
Tobin C. Harding 5a8a5ff6c9 Move debug_from_display to bitcoin_internals
This is an internal macro, now that we have the `internals` crate put
`debug_from_display` in it.
2022-10-20 06:15:23 +11:00
Tobin C. Harding a2f08f2bc6 Improve docs on impl_array_newtype macro
Trivial cleanup of docs.
2022-10-20 06:15:13 +11:00
Tobin C. Harding 771cdde282 Move impl_array_newtype to bitcoin_internals
`impl_array_newtype` is an internal macro, move it to a new, ever so
meaningfully named, `macros` module.

Use `#[macro_export]`, no other changes to the macro.
2022-10-20 06:14:59 +11:00
Tobin C. Harding ee19a1633d internals: Run formatter
Add one `rustfmt::skip` statement and run `cargo +nightly fmt`.
2022-09-20 14:24:47 +10:00
Andrew Poelstra f41ec20ee4
Merge rust-bitcoin/rust-bitcoin#1273: Redesign `hex::BufEncoder` to accept owned arrays
1bf885550e Redesign `hex::BufEncoder` to accept owned arrays (Martin Habovstiak)

Pull request description:

  Not being able to create an owned `BufEncoder` prevented returning it from functions which need to allocate the buffer on stack. Such is the case in WIP serde via consensus serialzation.

  This change refactors `OutBytes` to be unsized, adds an `AsOutBytes` trait and uses that one instead of `Into` to perform the conversion.

  Closes #1270

  This is meant as potentially mergeable demonstration. Interestingly, it was easier than I expected.

ACKs for top commit:
  tcharding:
    Except for the question about the `out_bytes` module, ACK 1bf885550e
  apoelstra:
    ACK 1bf885550e

Tree-SHA512: 39bc48e54ae0e66b988ba5ad6ea7ecbe03e5f4c71792df0f8e2b03aa2e97e2c0fac1cb03e84ecac12ec6f13649554b57e1000710c34c638d17d9bb575d0ac0a1
2022-09-15 13:17:36 +00:00
Martin Habovstiak 1bf885550e Redesign `hex::BufEncoder` to accept owned arrays
Not being able to create an owned `BufEncoder` prevented returning it
from functions which need to allocate the buffer on stack. Such is the
case in WIP serde via consensus serialzation.

This change refactors `OutBytes` to be unsized, adds an `AsOutBytes`
trait and uses that one instead of `Into` to perform the conversion.
2022-09-14 19:41:58 +02:00
Martin Habovstiak 6b96050d1f Document `cfg`
This adds previously-forgotten documentation of items only available on
`alloc` feature.
2022-09-14 09:06:25 +02:00
Martin Habovstiak 6fc4860813 Activate `rust_v_1_46` when on high-enough rustc
This adds a build script that automatically activates the cfg if the
version is sufficient. We don't make API changes here, just improve
debugging by enabling `track_caller`.
2022-09-14 08:55:02 +02:00
Martin Habovstiak 040b14ef1a Implement basic support for fast hex encoding
There's a `hex` module in `bitcoin_hashes` which is a bit out of place
and not very fast - it passes each *digit* through dynamic dispatch not
only adding overhead but also not allowing `String` to make better
allocations.

This change adds basic support for hex encoding using a stack-allocated
buffer which minimizes the overhead of dynamic dispatch. It also
provides a new `DisplayHex` trait designed to replace `ToHex` found in
`bitcoin_hashes`.
2022-09-13 22:17:31 +02:00
Tobin C. Harding 834bbf461f Introduce bitcoin-internals crate
Add a new crate `bitcoin-internals` to be used for internal code needed
by multiple soon-to-be-created crates.

Add the `write_err` macro to `bitcoin-internals`, nothing else.

This patch uses a `path` dependency which means `rust-bitcoin` cannot be
released in its current state, will need to be changed once we release
the `bitcoin-internals` crate on `crates.io`.
2022-09-13 08:59:57 +10:00