Commit Graph

105 Commits

Author SHA1 Message Date
Tobin C. Harding 01a8cc6848 Remove extern crate bitcoin_hashes
Now we have edition 2018 we do not need to use `macro_use` or `extern
crate`; `pub use` works with macros.

Remove the extern crate statement and replace it with a pub use
statement. Requires fixing up various imports statements and also
requires importing `sha256t_hash_newtype` macro directly instead of
using a qualified path to it.
2022-07-20 11:23:59 +10:00
Andrew Poelstra 0c22359618
Merge rust-bitcoin/rust-bitcoin#1001: Remove leading colons
73bc2bb058 Remove leading colons from ::core::cmp::Ordering (Tobin C. Harding)
bffe0e840d Remove _most_ leading double colons (Tobin C. Harding)

Pull request description:

  Leading double colons are a relic of edition 2015. Attempt to remove _all_ leading double colons (assuming I didn't miss any).

  - Patch 1 is done mechanically so it can be repeated by reviewers, just search-and-replace ' ::' with '::' (note the leading space).
  - Patch 2 does a single other instance of leading `::`

ACKs for top commit:
  apoelstra:
    ACK 73bc2bb058
  sanket1729:
    utACK 73bc2bb058.

Tree-SHA512: 8f7aafdda1aed5b69dcc83f544e65085dfec6590765839f0a6f259b99872805d1f00602fd9deac05c80a5cac3bc222d454dde0117dff4484e5cd34ea930fdfa1
2022-07-19 01:39:04 +00:00
Andrew Poelstra 4965495354
Merge rust-bitcoin/rust-bitcoin#1066: Upgrade to secp256k1 v0.23.0
36f29d4357 Upgrade to secp256k1 v0.23.0 (Tobin C. Harding)

Pull request description:

  We recently released a new version of `rust-secp256k1`, upgrade to use it.

ACKs for top commit:
  apoelstra:
    ACK 36f29d4357
  Kixunil:
    ACK 36f29d4357

Tree-SHA512: 46a909dec8bc59daa78acdb76824d93f4f1da0e9736cf6ca443d3bbadfa43867e720293bb7c4919cb0658e75ec59daeffea080611f0e7eed4df439ddac0305de
2022-07-12 14:03:49 +00:00
Tobin C. Harding 36f29d4357 Upgrade to secp256k1 v0.23.0
We recently released a new version of `rust-secp256k1`, upgrade to use
it.
2022-07-12 09:22:55 +10:00
Andrew Poelstra 5d06177644
Merge rust-bitcoin/rust-bitcoin#1076: Introduce SPDX license identifiers
91ff2f628c Introduce SPDX license identifiers (Tobin C. Harding)

Pull request description:

  When `rust-bitcoin` was started in 2014 the SPDX license list and short identifiers where not a thing. Now that we have short identifiers and they are gaining popularity in other projects we can consider using them.

  - Add links to the SPDX website in the readme
  - Shorten the author section to a single line
  - Remove all the licence information in each file and replace it with an
  SPDX ID (see https://spdx.dev/ids/#how)

  Of note:

  - If the author of a file is explicitly listed, maintain this information
  - If the 'author' is listed as the generic 'Rust Bitcoin developers' just remove the attribution, this is implicit. This does loose the date info but that can be seen at any time from the git index using

    `git log --follow --format=%ad --date default <FILE> | tail -1`

  apoelstra, please confirm that I'm not treading on your toes here, especially, are you ok with the new 'written by' string format?

  ### Ref
  - https://spdx.dev/ids/#how
  - https://spdx.org/licenses/CC0-1.0.html
  - https://spdx.dev/ids/

ACKs for top commit:
  apoelstra:
    ACK 91ff2f628c
  sanket1729:
    ACK 91ff2f628c. I am also in IDGAF camp, but I like more red lines in diff.
  Kixunil:
    ACK 91ff2f628c

Tree-SHA512: ca8aac00f015c18ec18de83dfeb50dd6f4f840653c7def85daa2436a339021ada5f3c34ad0cdf6b18e3e39c45a6d58a8313742e4001d467785b10eee7fdbc938
2022-07-11 15:11:03 +00:00
Tobin C. Harding bffe0e840d Remove _most_ leading double colons
Leading double colons are a relic of edition 2015. Remove all leading
double colons that follow a space, done like this so that reviewers can
do the same and verify the diff. Done with

search-and-replace ' ::' '::'

And, for the record:

```bash
function search-and-replace() {
    if (($# != 2))
    then
        echo "Usage: $0 <this> <that>"
        return
    fi

    local this="$1"
    local that="$2"

    for file in $(git grep -l "$this")
    do
        perl -pi -e "s/$this/$that/g" "$file"
    done
}
```
2022-07-11 15:20:05 +10:00
Tobin C. Harding 91ff2f628c Introduce SPDX license identifiers
When `rust-bitcoin` was started in 2014 the SPDX license list and short
identifiers where not a thing. Now that we have short identifiers and
they are gaining popularity in other projects we can consider using
them.

- Add links to the SPDX website in the readme
- Shorten the author section to a single line
- Remove all the licence information in each file and replace it with an
SPDX ID (see https://spdx.dev/ids/#how)

Of note:

- If the author of a file is explicitly listed, maintain this
information
- If the 'author' is listed as the generic 'Rust Bitcoin developers'
just remove the attribution, this is implicit. This does loose the date
info but that can be seen at any time from the git index using

  `git log --follow --format=%ad --date default <FILE> | tail -1`
2022-06-29 14:12:02 +10:00
Tobin C. Harding af16286679 Implement TryFrom sha256::Hash for TaprootMerkleBranch
TryFrom` became available in Rust 1.34 so we can use it now we have
bumped our MSRV.

Add a macro for implementing `TryFrom` for various lists of
`sha256::Hash` types. Use the macro to for vec, slice, and boxed slice.
2022-06-28 10:04:59 +10:00
Tobin C. Harding 38ff025122 Remove useless use of vec!
Clippy warns of useless use of `vec!` macro, remove it.
2022-06-07 15:34:58 +10:00
Tobin C. Harding 2b8d93ec4b Remove unnecessary explicit reference
Clippy warns about creating a reference that is immediately
de-referenced.

Remove unnecessary explicit `&`, while we are at it remove unnecessary
explicit types that appear on the same lines of code.
2022-06-07 15:26:59 +10:00
sanket1729 165cae959a
Merge rust-bitcoin/rust-bitcoin#1003: Improve error `Display` implementations
57dd6739c3 Do not print error when displaying for std builds (Tobin C. Harding)
b80cfeed85 Bind to error_kind instead of e (Tobin C. Harding)
241ec72497 Bind to b instead of e (Tobin C. Harding)
01f481bf5c Bind to s instead of e (Tobin C. Harding)
5c6d369289 network: Remove unused error variants (Tobin C. Harding)
e67e97bb37 Put From impl below std::error::Error impl (Tobin C. Harding)
6ca98e5275 Remove error TODO (Tobin C. Harding)

Pull request description:

  As part of the ongoing error improvement work and as a direct result of [this comment](https://github.com/rust-bitcoin/rust-bitcoin/pull/987#issuecomment-1135563287) improve the `Display` implementations of all our error types so as to not repeat the source error when printing.

  The first 5 patches are trivial clean ups around the errors. Patch 6 is the real work.

  EDIT: ~CC @Kixunil, have I got the right idea here bro?~ Patch 6 now includes a macro as suggested.

ACKs for top commit:
  Kixunil:
    ACK 57dd6739c3
  apoelstra:
    ACK 57dd6739c3
  sanket1729:
    ACK 57dd6739c3. Did not check if we covered all cases. We need to remember to use `write_err!` instead of `write!` in future.

Tree-SHA512: 1ed26b0cc5f9a0f71684c431cbb9f94404c116c9136be696434c56a2f56fd93cb5406b0955edbd0dc6f8612e77345c93fa70a70650118968cc58e680333a41de
2022-06-01 15:17:24 -07:00
sanket1729 471f90923d
Merge rust-bitcoin/rust-bitcoin#1006: Feature `use-serde` renamed to `serde`
2e7effc604 Feature `use-serde` renamed to `serde` (Martin Habovstiak)

Pull request description:

  Features activating external crates are supposed to have same name as
  those crates. However we depend on same feature in other crates so we
  need a separate feature. After MSRV bump it is possible to rename the
  crates and features so we can now fix this inconsistency.

  Sadly, derive can't see that the crate was renamed so all derives must
  be told to use the other one.

  Replaces #373

ACKs for top commit:
  apoelstra:
    ACK 2e7effc604

Tree-SHA512: b20364b9e8f30c2269bef915e821b2b2ec929e71dd0e88af2bc3a021821f87011d35e095cb8efe99add77a23dde940a17537eb387fb4582b05c57c8679969eb0
2022-06-01 14:29:02 -07:00
Andrew Poelstra 50489c8d5e
Merge rust-bitcoin/rust-bitcoin#1026: Add non_exhaustive to all error enums
99f565f932 Add non_exhaustive to all error enums (Tobin C. Harding)

Pull request description:

  Adding an error variant to a public enum is an API breaking change, this means making, what could be, small refactorings or improvements harder. If we use `non_exhaustive` for error types then we mitigate this cost.

  There is a tradeoff however, downstream users who explicitly match on our public error types must include a wildcard pattern.

ACKs for top commit:
  apoelstra:
    ACK 99f565f932
  Kixunil:
    ACK 99f565f932

Tree-SHA512: ff329f87d52b3fbe24654f32e4062ddae73173cba5a13d511591158e68ee278e9bdc0a70a3e0b42d6606b369255923f9c46d8b3d1b2ff75f8461a82567df80cd
2022-06-01 16:22:44 +00:00
Tobin C. Harding 99f565f932 Add non_exhaustive to all error enums
Adding an error variant to a public enum is an API breaking change, this
means making what could be small refactorings or improvements harder. If
we use `non_exhaustive` for error types then we mitigate this cost.
There is a tradeoff however, downstream users who explicitly match on
our public error types must include a wildcard pattern.
2022-05-31 14:29:50 +10:00
Tobin C. Harding 57dd6739c3 Do not print error when displaying for std builds
We implement `source` for all our error types. This means that we should
not display the source error explicitly because users can call `source`
to get the source error.

However, `std::Error::source()` is only available for "std" builds, so
that we do not loose the error source information in "no-std" builds add
a macro that conditionally adds the source onto the error message.
2022-05-27 08:38:52 +10:00
Martin Habovstiak 2e7effc604 Feature `use-serde` renamed to `serde`
Features activating external crates are supposed to have same name as
those crates. However we depend on same feature in other crates so we
need a separate feature. After MSRV bump it is possible to rename the
crates and features so we can now fix this inconsistency.

Sadly, derive can't see that the crate was renamed so all derives must
be told to use the other one.
2022-05-26 10:10:47 +02:00
Tobin C. Harding 841f1f5832 Implement Default for TaprootBuilder
Clippy emits:

  warning: you should consider adding a `Default` implementation for
  `TaprootBuilder`

As suggested, implement `Default` or `TaprootBuilder`.
2022-05-26 08:50:48 +10:00
Tobin C. Harding 27649ba182 Use copied instead of map to copy
Clippy emits:

  warning: you are using an explicit closure for copying elements

In one instance we have `map` followed by `flatten`, this can be
replaced by the `flat_map` combinator.

As suggested use `copied` combinator.
2022-05-26 08:50:48 +10:00
Tobin C. Harding 62ccc9102c Use iter().flatten().any() instead of if let Some
Clippy emits:

  warning: unnecessary `if let` since only the `Some` variant of the
  iterator element is used

Use combinator chain `iter().flatten().any()` to check for an node with
hidden nodes.
2022-05-26 08:50:43 +10:00
Tobin C. Harding b7d6c3e02c Remove additional reference
Clippy emits:

  warning: this expression creates a reference which is immediately
  dereferenced by the compiler

As suggested, remove the additional reference.
2022-05-25 13:21:25 +10:00
Tobin C. Harding fcd0f4deac Use struct field init shorthand
Clippy emits:

  warning: redundant field names in struct initialization

As suggested use struct field init shorthand.
2022-05-25 13:15:20 +10:00
Andrew Poelstra 0e82376bf8
Merge rust-bitcoin/rust-bitcoin#987: Implement `std::error::Error` for the new MSRV
97a5bb1439 Implement std::error::source codebase wide (Tobin C. Harding)
0a9191b429 Add parenthesis around left hand side of companion (Tobin C. Harding)
7cf8af2f86 Put Error impl block below Display (Tobin C. Harding)
2384712364 Re-order Display match arms (Tobin C. Harding)

Pull request description:

  Now that we have MSRV of 1.41.1 we should use `source` instead of `cause`. Audit the whole codebase and implement `source` for _every_ error type we have.

  The first three patches are preparatory cleanup, patch 3 is particularly shameful (adds parenthesis to make my editor work).

  CC @Kixunil because he is championing the error stuff.

ACKs for top commit:
  apoelstra:
    ACK 97a5bb1439

Tree-SHA512: 46313a28929445f32e01e30ca3b0246b30bc9d5e43db5754d4b441e9c30d3e427efaf247100eb6b452f98beec5a4fcde1daba7943a772114aa34f78ab52cbc60
2022-05-21 14:08:52 +00:00
Tobin C. Harding 97a5bb1439 Implement std::error::source codebase wide
Audit ever error type we have and implement `source` for each.
2022-05-19 16:35:11 +10:00
Tobin C. Harding 0a9191b429 Add parenthesis around left hand side of companion
Parenthesis are not needed around this expression but my editor is going
mad and cannot format the code without them. Since it does not hurt
readability add parenthesis around the expression.
2022-05-19 16:33:49 +10:00
Tobin C. Harding 2384712364 Re-order Display match arms
Put the match arms in the same order as the enum that defines them.
2022-05-19 16:33:49 +10:00
Tobin C. Harding 58f94bee9b Remove sha256t_hash_newtype macro
Since commit `commit 275adc6c335a4326699cfbd444949e1725864ea1` on
`bitcoin_hashes` we have the identical implementation of the macro
`sha256t1_hash_newtype` in this crate and in `bitcoin_hashes`.

Remove the `sha256t_hash_newtype` macro from this crate in favour of the
one in `bitcoin_hashes`.
2022-05-19 14:10:57 +10:00
Tobin C. Harding 9f0c687d89 Enable edition 2018
Add 'edition = "2018"' to the manifest and do a bunch of manual path
fixups (use statements and fully qualified paths).
2022-05-11 10:16:48 +10:00
Tobin C. Harding dca0d67771 Fix in preparation for next edition
Use cargo to upgrade from edition 2015 to edition 2018.

 cargo fix --edition

No manual changes made. The result of the command above is just to fix
all the use statements (add `crate::`) and fix the fully qualified path
formats i.e., `::Foo` -> `crate::Foo`.
2022-05-11 10:16:17 +10:00
Tobin C. Harding 6410095687 Use chunks_exact
Now that we are going to bump the MSRV above 1.31 we can use
`chunks_exact`.
2022-04-27 07:59:40 +10:00
sanket1729 9f79f8d1ce
Merge rust-bitcoin/rust-bitcoin#936: Make TaprooBuilder::finalize able to return keyspend only
7969b7a43e Make TaprooBuilder::finalize able to return keyspend only (Jeremy Rubin)

Pull request description:

ACKs for top commit:
  JeremyRubin:
    > ACK 7969b7a
  sanket1729:
    ACK 7969b7a43e
  apoelstra:
    ACK 7969b7a43e

Tree-SHA512: 26d0b730590f610a858061394faafaa74b13dd353f34ccf1c6166d0cbb62937010eed5661a887f7bea4f983ac9eab8cdca10a5fe7bd74f2dd5701a7782cbac64
2022-04-20 09:39:20 -07:00
Dr Maxim Orlovsky 7a5482d23a
Rename LeafInfo into ScriptLeaf 2022-04-19 20:32:13 +02:00
Dr Maxim Orlovsky 6f871ba47d
Add convenience LeafInfo::depth method
Without this method computation of the leaf depth requires cloning due
to the requirements of merkle_branch.into_inner()
2022-04-19 20:31:49 +02:00
Dr Maxim Orlovsky 3c502ffc2d
Making all LeafInfo fields private 2022-04-19 20:31:49 +02:00
Dr Maxim Orlovsky 79345fcd02
LeafInfo field accessor methods 2022-04-19 20:31:49 +02:00
Dr Maxim Orlovsky 5958466678
Make LeafInfo::leaf_hash public and change its name and return type 2022-04-19 20:31:49 +02:00
Dr Maxim Orlovsky c83893d497
Make taproot LeafInfo public
LeafInfo structure is a useful form of representing leaf script information (script, leaf version and merkle proof).
2022-04-19 20:31:49 +02:00
Dr Maxim Orlovsky b0f3992db1
Rename TaprootBuilder::is_complete into is_finalized 2022-04-05 22:29:32 +02:00
Dr Maxim Orlovsky 56adfa4527
TaprootBuilder::has_hidden_nodes method 2022-04-05 22:18:00 +02:00
Dr Maxim Orlovsky e69701e089
Rename taproot `*_hidden` API into `*_hidden_nodes` 2022-04-05 22:16:59 +02:00
Dr Maxim Orlovsky 6add0dd9dc
Track information about hidden leaves in taproot NodeInfo 2022-04-05 22:16:27 +02:00
Jeremy Rubin 7969b7a43e Make TaprooBuilder::finalize able to return keyspend only 2022-04-03 16:24:56 -04:00
sanket1729 7fa8ce0bd0
Merge rust-bitcoin/rust-bitcoin#926: Remove redundant code computing tap hashes
f3ebfd6f8b Remove repeated tap branch hash computing logic (Dr Maxim Orlovsky)
1b28375658 Abstract tap branch hash computing into a dedicated method (Dr Maxim Orlovsky)

Pull request description:

ACKs for top commit:
  apoelstra:
    ACK f3ebfd6f8b

Tree-SHA512: d66d544df324a7d25c8cc9dc48ddedf086ac87eb2ed09a8d7a568cc1488ae44e0807d53ccb7a6e61dbeef0d3d62a1cacf0d69ba7b8de9178ac5c13bae944d08b
2022-04-01 11:35:14 -07:00
sanket1729 efbe1417fe
Merge rust-bitcoin/rust-bitcoin#923: Taproot docs nits
da731c4825 Add further description to the NodeInfo struct (Tobin Harding)
492ccebd99 Use links for error types (Tobin Harding)
3e05887579 Use 'the' to improve sentence (Tobin Harding)

Pull request description:

  See to nits from review of https://github.com/rust-bitcoin/rust-bitcoin/pull/912

  Three minor patches to the `taproot` module docs.

  CC @dr-orlovsky

ACKs for top commit:
  dr-orlovsky:
    ACK da731c4825
  sanket1729:
    ACK da731c4825

Tree-SHA512: 17a27a19c88f9baa8127023b2ee30fc2259cb0058a92dc9d8ae595e9e02ccb047fefcba7548ff7900fffa7bc6853447183e80660b8756d90d055ab8aa96ae938
2022-04-01 08:55:57 -07:00
Dr Maxim Orlovsky f3ebfd6f8b
Remove repeated tap branch hash computing logic 2022-03-31 15:21:36 +02:00
Dr Maxim Orlovsky 1b28375658
Abstract tap branch hash computing into a dedicated method 2022-03-31 15:16:39 +02:00
Dr Maxim Orlovsky e3f173e521
Require taproot tree depth argument always to be u8 2022-03-31 15:12:05 +02:00
Tobin Harding da731c4825 Add further description to the NodeInfo struct
Further assist devs in understanding the `NodeInfo` struct by adding
docs about when/why the struct is used.
2022-03-31 10:57:37 +11:00
Tobin Harding 492ccebd99 Use links for error types
We can help the users by linking them to errors when mentioning them in
the docs.
2022-03-31 10:57:05 +11:00
Tobin Harding 3e05887579 Use 'the' to improve sentence
Adding a 'the' makes this sentence a little better.
2022-03-31 10:56:36 +11:00
Tobin Harding c25eddd187 Remove unnecessary documentation
We have some text quoted directly from BIP341, this text is on the net
if folk wish to read it, we don't need it in the source code.
2022-03-29 10:28:29 +11:00