Commit Graph

1933 Commits

Author SHA1 Message Date
Andrew Poelstra 06a777d02d
Merge rust-bitcoin/rust-bitcoin#990: Derive Hash on a bunch of types
ef7fef001c Derive Hash on a bunch of types (Tobin C. Harding)

Pull request description:

  In preparation for being able to derive `Hash` on all types in `miniscript`, derive `Hash` on all of the required types.

  This PR includes all the changes in https://github.com/rust-bitcoin/rust-bitcoin/pull/933/files and hence supersedes it.

  ref: https://github.com/rust-bitcoin/rust-miniscript/issues/226

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

Tree-SHA512: 1a1db8b4df2ea8f9e176434bb6fdee5b96f47dcdc6395ebc59e5f5ac5eb13a66fb61e1d90cdbbf12a027f7685fdff21060338c5f27b9d9bf5e9fee452c7c7e83
2022-07-17 22:55:55 +00:00
Andrew Poelstra 2ba759e269
Merge rust-bitcoin/rust-bitcoin#1100: Document PSBT roles and limitation
896ca42a53 Document PSBT roles and limitation (DanGould)

Pull request description:

  The READEME claims rust-bitcoin supports PSBT finalization, but really needs rust-miniscript for that. I think we should make this clear in this crate's PSBT examples as well.

  > > Understanding scripts and witnesses doesn't scream rust-miniscript to me. Miniscript crate is not the first place I'd look, since it's additional.
  >
  > We should probably add it to the README here or something. If I needed to deal with scripts or witnesses in any way beyond reserializing them or hashing scriptpubkeys into addresses, I'd immediately turn to Miniscript. You basically can't work on scripts without it, unless you are doing something very specific.
  >
  > >Anywhere there's PSBT code I expect a finalizer, even if it had documented limitations.
  >
  > Not to be too glib, but suppose we had a finalizer that just always returned an error, and was documented not to finalize any transactions. Would that meet your expectations? It is hard to do much more without Miniscript.
  >

  _Originally posted by apoelstra in https://github.com/rust-bitcoin/rust-bitcoin/issues/630#issuecomment-1175316689_

ACKs for top commit:
  apoelstra:
    ACK 896ca42a53
  tcharding:
    ACK 896ca42a53

Tree-SHA512: e71a65b8c04134d9b3406ea76bb915fa116e4a961f9f6cb24350422f9d550cba26a630e02f9ba352fae63076926532bc4bf2d1001488666a05f18d7774ddda9e
2022-07-17 22:50:36 +00:00
DanGould 896ca42a53
Document PSBT roles and limitation 2022-07-15 14:45:43 +08:00
Tobin C. Harding ef7fef001c Derive Hash on a bunch of types
In preparation for being able to derive `Hash` on all types in
`miniscript`, derive `Hash` on all of the required types.
2022-07-15 10:00:32 +10:00
Andrew Poelstra 9cfa9bd9df
Merge rust-bitcoin/rust-bitcoin#1049: Implement std::error::Error for ParseAmount
5ce34011f2 Implement std::error::Error for ParseAmount (Tobin C. Harding)

Pull request description:

  The `ParseAmountError` does not implement `std::error::Error`, must have been missed when we did the rest.

  Implement `std::error::Error` for `ParseAmount`.

ACKs for top commit:
  Kixunil:
    ACK 5ce34011f2
  apoelstra:
    ACK 5ce34011f2

Tree-SHA512: 8dafc472b7c23b54d856344e786e0f22e8e179f30f6c1011fbf5f8f0c6b1b5d74ed8e4f2638e5f8246f04dbb429e60027db6fe584d51a78957a6e904feb9e8a3
2022-07-14 13:24:35 +00:00
Andrew Poelstra ed00c2aab9
Merge rust-bitcoin/rust-bitcoin#1065: Upgrade `bitcoin_hashes` dependency
1e46eeaa88 Upgrade to bitcoin_hashes v0.11.0 (Tobin C. Harding)

Pull request description:

  We just released a new version of `bitcoin_hashes`, upgrade the dependency to v0.11.0

ACKs for top commit:
  apoelstra:
    ACK 1e46eeaa88
  Kixunil:
    ACK 1e46eeaa88

Tree-SHA512: 32173349c280c255681ebf15a1aa98a28b7016bb813ca907ac55a9797d9d17e1da344e2d8e74c02c2c80d2e6873a03f522c2d55b289b65d7ac55f402b19d689b
2022-07-13 15:46:22 +00:00
Andrew Poelstra 758dbfa1da
Merge rust-bitcoin/rust-bitcoin#1084: Add PublicKey::to_sort_key method for use with sorting by key
24f0441d54 Add PublicKey::to_sort_key method for use with sorting by key (junderw)

Pull request description:

  Replaces #524

  See previous PR for reasoning.

  This solution is a little more straightforward. The name and documentation should be enough to prevent misuse.

  We can also impl a to_sort_key for any CompressedKey added later. (or just impl Ord in a BIP67 compliant way)

  TODO:

  - [x] Add more sorting test vectors. Ideas of edge cases to test are welcome.

ACKs for top commit:
  apoelstra:
    ACK 24f0441d54
  tcharding:
    ACK 24f0441d54
  Kixunil:
    ACK 24f0441d54

Tree-SHA512: 92d68cccaf32e224dd7328edeb3481dd7dcefb2f9090b7381e135e897c21f79ade922815cc766c5adb7ba751b71b51a773d103af6ba13fc081e1f5bfb846b201
2022-07-13 13:02:00 +00:00
Tobin C. Harding 1e46eeaa88 Upgrade to bitcoin_hashes v0.11.0 2022-07-13 09:38:05 +10:00
Andrew Poelstra a24b223ae4
Merge rust-bitcoin/rust-bitcoin#1094: Remove extern crate core statement
35edcaa4ca Remove extern crate core statement (Tobin C. Harding)

Pull request description:

  Now that we have an MSRV of 1.41.1 we no longer need `extern crate core`, remove it.

ACKs for top commit:
  apoelstra:
    ACK 35edcaa4ca
  Kixunil:
    ACK 35edcaa4ca

Tree-SHA512: 0efa0f05d3e9f797c493757fce6ca7703dd8439dbce4e9ff8113494fc71691ab4171c6f0fb5239b57ff5f0e223d48b057265a3df79898a399ca455040580aab2
2022-07-12 23:00:12 +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
Andrew Poelstra 3f27131823
Merge rust-bitcoin/rust-bitcoin#1091: Add custom error for invalid parsing of address types
19ba7ecc03 Add custom error for unknown address type parsing (Arturo Marquez)

Pull request description:

  Adds a custom error `UnknownAddressType(_)` which is returned in cases where an unknown address type tries to be parsed via
  `FromStr`. This provides more context for the error, since it contains the `String` that tried to be parsed.

  Closes https://github.com/rust-bitcoin/rust-bitcoin/issues/1064

ACKs for top commit:
  Kixunil:
    ACK 19ba7ecc03
  dunxen:
    ACK 19ba7ec
  tcharding:
    ACK 19ba7ecc03
  apoelstra:
    ACK 19ba7ecc03

Tree-SHA512: 2f94eb2e122c1acafcb8c852f7bfe22cb3725806541ae40f82d3a882011fb911ce8fc430153ebea4066f43c5a51813359a4c9b95d2a9077ce8f6dcaa58eee6fd
2022-07-12 01:17:41 +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
Tobin C. Harding 35edcaa4ca Remove extern crate core statement
Now that we have an MSRV of 1.41.1 we no longer need `extern crate
core`, remove it.
2022-07-12 09:05:14 +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
Arturo Marquez 19ba7ecc03
Add custom error for unknown address type parsing
Adds a custom error `UnknownAddressType(_)` which is returned in
cases where an unknown address type tries to be parsed via
`FromStr`. This provides more context for the error.

For more info see [1].

[1] - `https://github.com/rust-bitcoin/rust-bitcoin/issues/1064`
2022-07-11 08:56:56 -05:00
Andrew Poelstra 97c680db8c
Merge rust-bitcoin/rust-bitcoin#1081: Use `to_hex` when available
32cfd93933 Use to_hex when available (Tobin C. Harding)

Pull request description:

  We have a bunch of calls to `format!("{:x}", foo)` for types that implement `ToHex`. The code is terser with no loss of clarity if we use the trait method and call `to_hex()`.

ACKs for top commit:
  apoelstra:
    ACK 32cfd93933
  Kixunil:
    ACK 32cfd93933

Tree-SHA512: 87cb6660708c11dfafb56bd6e2ea2634043b2226d51903a20806c1ba51c6e7c4f0e4cc25e49f820b5b1236600af7da2a20893c49a5b8845d7652b143fd0ec388
2022-07-08 16:59:19 +00:00
junderw 24f0441d54
Add PublicKey::to_sort_key method for use with sorting by key 2022-07-07 18:05:53 +09:00
Andrew Poelstra 443bc4f533
Merge rust-bitcoin/rust-bitcoin#1085: Remove redundant compile_error
6adb2c64d9 Remove redundant compile_error (junderw)

Pull request description:

  Same compile_error with more verbose explanation is also on line 66.

ACKs for top commit:
  apoelstra:
    ACK 6adb2c64d9
  Kixunil:
    ACK 6adb2c64d9

Tree-SHA512: e6ee9a0212e3babeb0e7235495295aa6893470db8308159c349784320f916216e17ab23285351ab19517baf0448a3b9d0beb88f0e31f66b8ee8d6ee4fbdda113
2022-07-04 17:50:12 +00:00
junderw 6adb2c64d9
Remove redundant compile_error 2022-07-04 22:34:40 +09:00
Andrew Poelstra 21abc42b68
Merge rust-bitcoin/rust-bitcoin#1083: Remove unused lifetimes
64152ff6fc Remove unused lifetimes (Tobin C. Harding)

Pull request description:

  We somehow have two lifetimes that are unused and causing clippy warnings, remove them.

  This fixes the red CI runs on a bunch of other open PRs. FTR I have no idea how these got past clippy onto master.

ACKs for top commit:
  Kixunil:
    ACK 64152ff6fc
  apoelstra:
    ACK 64152ff6fc

Tree-SHA512: cced838b575b29d90c4325ab42ada93bae4751721d3ca2c19ec801892c38130570613e4ab8de757b73ecc83cda5c00a32867139e04a2615833d05dc21551af1a
2022-07-01 16:23:35 +00:00
Tobin C. Harding 64152ff6fc Remove unused lifetimes
We somehow have two lifetimes that are unused and causing clippy
warnings, remove them.
2022-07-01 11:56:50 +10:00
Andrew Poelstra 30baeea738
Merge rust-bitcoin/rust-bitcoin#1014: Use fragment-specifier literal
4d2291930b Use fragment-specifier literal (Tobin C. Harding)

Pull request description:

  Currently we are using the fragment-specifier `expr` in a bunch of
  macros for captures that are only used for literals. If we use `literal`
  instead it allows the compiler to give slightly more specific error
  messages.

  The benefits of this change are minor. Of note, this patch found one
  unusual macro call site (removed unnecessary `&`).

  The macros changed are all internal macros, this is not a breaking change.

ACKs for top commit:
  Kixunil:
    ACK 4d2291930b
  apoelstra:
    ACK 4d2291930b

Tree-SHA512: 51c109fe3a884191bf623508555c1d5ad337a3f3b48538d18aec13e581f2c5fbbd055be49600ced19f38541412c34090bd8bac61fd05d5aa9702c96ff521364f
2022-06-30 15:01:50 +00:00
Tobin C. Harding 32cfd93933 Use to_hex when available
We have a bunch of calls to `format!("{:x}", foo)` for types that
implement `ToHex`. The code is terser with no loss of clarity if we use
the trait method and call `to_hex()`.
2022-06-30 16:59:18 +10:00
Andrew Poelstra 05f7545aeb
Merge rust-bitcoin/rust-bitcoin#1075: Remove Uninhabited
a8e62f249b Remove Uninhabited (Tobin C. Harding)

Pull request description:

  Last release, before we had access to `non_exhaustive` we added some fancy types to enable conditionally having a `bitcoinconsensus::Error`.

  Now that we have bumped the MSRV and have already added `non_exhaustive` to the `Error` type in question, we can use a compiler attribute to conditionally include the `bitcoinconsensus` error.

  Remove `Uninhabited` and its usage.

  For more context see the [original attempt ](https://github.com/rust-bitcoin/rust-bitcoin/pull/1025)at using `Infallible` (last comment in discussion thread).

ACKs for top commit:
  Kixunil:
    ACK a8e62f249b
  dunxen:
    ACK a8e62f2
  apoelstra:
    ACK a8e62f249b

Tree-SHA512: 8c03c44d7533af1a9a1185b7f9e0fa2c52369eaac8a45f0e2199e7e1bbd08ba2bfa23d829d2c2abf7f45fe8cc26ccad02f2e1a6d408d2c0fbca23140cafe3801
2022-06-29 19:37:07 +00:00
Andrew Poelstra f401cdc99e
Merge rust-bitcoin/rust-bitcoin#1035: Take Writer/Reader by `&mut` in consensus en/decoding
1fea098dfb Support unsized `R` and `W` in consensus encode/decode (Dawid Ciężarkiewicz)
a24a3b0194 Forward `consensus_decode` to `consensus_decode_from_finite_reader` (Dawid Ciężarkiewicz)
9c754ca4de Take Writer/Reader by `&mut` in consensus en/decoding (Dawid Ciężarkiewicz)

Pull request description:

  Fix #1020 (see more relevant discussion there)

  This definitely makes the amount of generics compiler
  has to generate by avoding generating the same functions
  for `R`, `&mut R`, `&mut &mut R` and so on.

  old:

  ```
  > ls -al target/release/deps/bitcoin-07a9dabf1f3e0266
  -rwxrwxr-x 1 dpc dpc 9947832 Jun  2 22:42 target/release/deps/bitcoin-07a9dabf1f3e0266
  > strip target/release/deps/bitcoin-07a9dabf1f3e0266
  > ls -al target/release/deps/bitcoin-07a9dabf1f3e0266
  -rwxrwxr-x 1 dpc dpc 4463024 Jun  2 22:46 target/release/deps/bitcoin-07a9dabf1f3e0266
  ```

  new:

  ```

  > ls -al target/release/deps/bitcoin-07a9dabf1f3e0266
  -rwxrwxr-x 1 dpc dpc 9866800 Jun  2 22:44 target/release/deps/bitcoin-07a9dabf1f3e0266
  > strip target/release/deps/bitcoin-07a9dabf1f3e0266
  > ls -al target/release/deps/bitcoin-07a9dabf1f3e0266
  -rwxrwxr-x 1 dpc dpc 4393392 Jun  2 22:45 target/release/deps/bitcoin-07a9dabf1f3e0266
  ```

  In the unit-test binary itself, it saves ~100KB of data.

  I did not expect much performance gains, but turn out I was wrong(*):

  old:

  ```
  test blockdata::block::benches::bench_block_deserialize                 ... bench:   1,072,710 ns/iter (+/- 21,871)
  test blockdata::block::benches::bench_block_serialize                   ... bench:     191,223 ns/iter (+/- 5,833)
  test blockdata::block::benches::bench_block_serialize_logic             ... bench:      37,543 ns/iter (+/- 732)
  test blockdata::block::benches::bench_stream_reader                     ... bench:   1,872,455 ns/iter (+/- 149,519)
  test blockdata::transaction::benches::bench_transaction_deserialize     ... bench:         136 ns/iter (+/- 3)
  test blockdata::transaction::benches::bench_transaction_serialize       ... bench:          51 ns/iter (+/- 8)
  test blockdata::transaction::benches::bench_transaction_serialize_logic ... bench:           5 ns/iter (+/- 0)
  test blockdata::transaction::benches::bench_transaction_size            ... bench:           3 ns/iter (+/- 0)
  ```

  new:

  ```
  test blockdata::block::benches::bench_block_deserialize                 ... bench:   1,028,574 ns/iter (+/- 10,910)
  test blockdata::block::benches::bench_block_serialize                   ... bench:     162,143 ns/iter (+/- 3,363)
  test blockdata::block::benches::bench_block_serialize_logic             ... bench:      30,725 ns/iter (+/- 695)
  test blockdata::block::benches::bench_stream_reader                     ... bench:   1,437,071 ns/iter (+/- 53,694)
  test blockdata::transaction::benches::bench_transaction_deserialize     ... bench:          92 ns/iter (+/- 2)
  test blockdata::transaction::benches::bench_transaction_serialize       ... bench:          17 ns/iter (+/- 0)
  test blockdata::transaction::benches::bench_transaction_serialize_logic ... bench:           5 ns/iter (+/- 0)
  test blockdata::transaction::benches::bench_transaction_size            ... bench:           4 ns/iter (+/- 0)
  ```

  (*) - I'm benchmarking on a noisy laptop. Take this with a grain of salt. But I think
  at least it doesn't make anything slower.

  While doing all this manual labor that will probably generate conflicts,
  I took a liberty of changing generic type names and variable names to
  `r` and `R` (reader) and `w` and `W` for writer.

ACKs for top commit:
  RCasatta:
    ACK 1fea098dfb tested in downstream lib, space saving in compiled code confirmed
  apoelstra:
    ACK 1fea098dfb

Tree-SHA512: bc11994791dc97cc468dc9d411b9abf52ad475f23adf5c43d563f323bae0da180c8f57f2f17c1bb7b9bdcf523584b0943763742b81362880206779872ad7489f
2022-06-29 19:29:42 +00:00
Andrew Poelstra 022ab0b069
Merge rust-bitcoin/rust-bitcoin#1007: Implement TryFrom
b29ff9b715 Rename SchnorrSighashType::from_u8 -> from_consensus_u8 (Tobin C. Harding)
af16286679 Implement TryFrom sha256::Hash for TaprootMerkleBranch (Tobin C. Harding)
6b7b440cff Implement TryFrom<Key> for ProprietaryKey (Tobin C. Harding)
5c49fe775f Implement TryFrom<TaprootBuilder> for TapTree (Tobin C. Harding)
632a5db8d9 Implement TryFrom for WitnessVersion (Tobin C. Harding)

Pull request description:

  Audit the whole codebase checking for any method that is of the form `from_foo` where foo is not an interesting identifier (like 'consensus' and 'standard'). Implement `TryFrom` for any such methods, deprecating the original.

  Done as separate patches so any can be easily dropped if not liked.

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

Tree-SHA512: 40f1d96b505891080df1f7a9b3507979b0279a9e0f9d7cd32598bdc16c866785e6b13d5cb1face5ba50e3bc8484a5cd9c7f430d7abc86db9609962476dacd467
2022-06-29 19:27:57 +00:00
Andrew Poelstra 4f5fcd3b37
Merge rust-bitcoin/rust-bitcoin#1071: Optimize `Witness` Serialization
9bf959180b Optimize Witness Serialization (DanGould)

Pull request description:

  fix #942
  > self.to_vec() allocates, it should be possible to avoid it - just feed the items into serializer.

  based on https://github.com/rust-bitcoin/rust-bitcoin/pull/1068

ACKs for top commit:
  Kixunil:
    ACK 9bf959180b
  apoelstra:
    ACK 9bf959180b

Tree-SHA512: 14553dfed20aee50bb6361d44986b38556cbb3e112e1b4d9e3b401c3da831b6bdf159089966254cf371c225ae929fc78516c96a6114b40a7bc1fda7305295e4a
2022-06-29 19:26:38 +00:00
DanGould 9bf959180b
Optimize Witness Serialization
We allocated a new vector when serializing a `Witness`. That was
inefficient and unnecessary. Use `serialize_seq` to feed the witness
elements directly into the serializer.

Optimize `Witness` serialization by removing the allocation.
2022-06-29 17:09:54 +08: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 a8e62f249b Remove Uninhabited
Last release, before we had access to `non_exhaustive` we added some
fancy types to enable conditionally having a `bitcoinconsensus::Error`.
Now that we have bumped the MSRV and have already added `non_exhaustive`
to the `Error` type in question, we can use a compiler attribute to
conditionally include the `bitcoinconsensus` error.

Remove `Uninhabited` and its usage.
2022-06-29 13:23:28 +10:00
Dawid Ciężarkiewicz 1fea098dfb Support unsized `R` and `W` in consensus encode/decode 2022-06-28 18:49:17 -07:00
Andrew Poelstra 8084d6dd42
Merge rust-bitcoin/rust-bitcoin#1072: Make `opcode::to_u8` a const function
0bae41129d Make `opcode::to_u8` a const function (Matt Corallo)

Pull request description:

  In general, if a function can be const, it should be, and this one
  trivially can be, so it should be.

ACKs for top commit:
  tcharding:
    ACK 0bae41129d
  apoelstra:
    ACK 0bae41129d

Tree-SHA512: 0df883894ec65dac1b709c581ffc3d2daca737561d05adb971dfef736e4147c59ea66cdc0520296c619e13e1dac70c07cb062b61304541cf488262244f313009
2022-06-28 23:15:34 +00:00
Matt Corallo 0bae41129d Make `opcode::to_u8` a const function
In general, if a function can be const, it should be, and this one
trivially can be, so it should be.
2022-06-28 17:48:31 +00:00
Tobin C. Harding b29ff9b715 Rename SchnorrSighashType::from_u8 -> from_consensus_u8
The `u8` parameter in the `SchnorrSighashType` constructor is a
consensus valid `u8`. Re-name the constructor to make this explicit.

Deprecate `from_u8` as is typical.
2022-06-28 10:04:59 +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 6b7b440cff Implement TryFrom<Key> for ProprietaryKey
TryFrom` became available in Rust 1.34 so we can use it now we have
bumped our MSRV.

Implement `TryFrom<Key>` for `ProprietaryKey` and deprecate the
`from_key` method.
2022-06-28 10:04:59 +10:00
Tobin C. Harding 5c49fe775f Implement TryFrom<TaprootBuilder> for TapTree
TryFrom` became available in Rust 1.34 so we can use it now we have
bumped our MSRV.

Implement `TryFrom<TaprootBuilder>` for `TapTree` and deprecate the
`from_builder` method.
2022-06-28 10:04:59 +10:00
Tobin C. Harding 632a5db8d9 Implement TryFrom for WitnessVersion
We have a bunch of 'from' methods that are fallible; `TryFrom` became
available in Rust 1.34 so we can use it now we have bumped our MSRV.

Implement the various `WitnessVersion` from methods using `TryFrom` and
deprecate the originals.
2022-06-28 10:04:59 +10:00
Andrew Poelstra b645b6b4b5
Merge rust-bitcoin/rust-bitcoin#1063: Remove duplicate `must_use`
bea5569cd3 Remove duplicate must_use (Tobin C. Harding)

Pull request description:

  Clippy emits:

   warning: this function has an empty `#[must_use]` attribute, but returns a type already marked as `#[must_use]`

  This is because the return type of the function `legacy_encode_signing_data_to` is `EncodeSigningDataResult` which is
  already marked as `must_use`. There is no need to have `must_use` on the function also.

  ##

  Hey apoelstra, this PR is needed before any other PR can get a green CI run. The PR that introduced this warning must have had a green CI run before the 'add clippy to CI' PR merged allowing it to merge without re-running CI.

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

Tree-SHA512: 27b606685bc2d5317a5e332431511af9b1017bf58462c283b322e5b6faf645fd8e006455af3d6888ab2c3c680b11e4b89f538f26440f4f1422e0daabc61825ac
2022-06-24 16:33:07 +00:00
Tobin C. Harding bea5569cd3 Remove duplicate must_use
Clippy emits:

 warning: this function has an empty `#[must_use]` attribute, but
 returns a type already marked as `#[must_use]`

This is because the return type of the function
`legacy_encode_signing_data_to` is `EncodeSigningDataResult` which is
already marked as `must_use`. There is no need to have `must_use` on the
function also.

I'm guessing this got through to master because we only just added
clippy to CI.
2022-06-24 09:54:22 +10:00
Andrew Poelstra 99af5b9cfc
Merge rust-bitcoin/rust-bitcoin#1024: Expose SIGHASH_SINGLE bug in `encode_signing_data_to`
42a91ab32a Expose SIGHASH_SINGLE bug in `encode_signing_data_to` (Dawid Ciężarkiewicz)

Pull request description:

  Via `Option` return value

  Fix #1015

ACKs for top commit:
  tcharding:
    ACK 42a91ab32a
  apoelstra:
    ACK 42a91ab32a

Tree-SHA512: 8e401ba0ee6ed2bdb95ec838440cfd7a0b6414991ada0d941e8b9526ea4a7d9b6ca1fc84318c4b2a317705650cabc957269c1034dd70c92bdeb854ca413e53be
2022-06-23 23:02:50 +00:00
Dawid Ciężarkiewicz a24a3b0194 Forward `consensus_decode` to `consensus_decode_from_finite_reader` 2022-06-23 15:55:21 -07:00
Dawid Ciężarkiewicz 9c754ca4de Take Writer/Reader by `&mut` in consensus en/decoding
Fix #1020 (see more relevant discussion there)

This definitely makes the amount of generics compiler
has to generate by avoding generating the same functions
for `R`, &mut R`, `&mut &mut R` and so on.

old:

```
> ls -al target/release/deps/bitcoin-07a9dabf1f3e0266
-rwxrwxr-x 1 dpc dpc 9947832 Jun  2 22:42 target/release/deps/bitcoin-07a9dabf1f3e0266
> strip target/release/deps/bitcoin-07a9dabf1f3e0266
> ls -al target/release/deps/bitcoin-07a9dabf1f3e0266
-rwxrwxr-x 1 dpc dpc 4463024 Jun  2 22:46 target/release/deps/bitcoin-07a9dabf1f3e0266
```

new:

```

> ls -al target/release/deps/bitcoin-07a9dabf1f3e0266
-rwxrwxr-x 1 dpc dpc 9866800 Jun  2 22:44 target/release/deps/bitcoin-07a9dabf1f3e0266
> strip target/release/deps/bitcoin-07a9dabf1f3e0266
> ls -al target/release/deps/bitcoin-07a9dabf1f3e0266
-rwxrwxr-x 1 dpc dpc 4393392 Jun  2 22:45 target/release/deps/bitcoin-07a9dabf1f3e0266
```

In the unit-test binary itself, it saves ~100KB of data.

I did not expect much performance gains, but turn out I was wrong(*):

old:

```
test blockdata::block::benches::bench_block_deserialize                 ... bench:   1,072,710 ns/iter (+/- 21,871)
test blockdata::block::benches::bench_block_serialize                   ... bench:     191,223 ns/iter (+/- 5,833)
test blockdata::block::benches::bench_block_serialize_logic             ... bench:      37,543 ns/iter (+/- 732)
test blockdata::block::benches::bench_stream_reader                     ... bench:   1,872,455 ns/iter (+/- 149,519)
test blockdata::transaction::benches::bench_transaction_deserialize     ... bench:         136 ns/iter (+/- 3)
test blockdata::transaction::benches::bench_transaction_serialize       ... bench:          51 ns/iter (+/- 8)
test blockdata::transaction::benches::bench_transaction_serialize_logic ... bench:           5 ns/iter (+/- 0)
test blockdata::transaction::benches::bench_transaction_size            ... bench:           3 ns/iter (+/- 0)
```

new:

```
test blockdata::block::benches::bench_block_deserialize                 ... bench:   1,028,574 ns/iter (+/- 10,910)
test blockdata::block::benches::bench_block_serialize                   ... bench:     162,143 ns/iter (+/- 3,363)
test blockdata::block::benches::bench_block_serialize_logic             ... bench:      30,725 ns/iter (+/- 695)
test blockdata::block::benches::bench_stream_reader                     ... bench:   1,437,071 ns/iter (+/- 53,694)
test blockdata::transaction::benches::bench_transaction_deserialize     ... bench:          92 ns/iter (+/- 2)
test blockdata::transaction::benches::bench_transaction_serialize       ... bench:          17 ns/iter (+/- 0)
test blockdata::transaction::benches::bench_transaction_serialize_logic ... bench:           5 ns/iter (+/- 0)
test blockdata::transaction::benches::bench_transaction_size            ... bench:           4 ns/iter (+/- 0)
```

(*) - I'm benchmarking on a noisy laptop. Take this with a grain of salt. But I think
at least it doesn't make anything slower.

While doing all this manual labor that will probably generate conflicts,
I took a liberty of changing generic type names and variable names to
`r` and `R` (reader) and `w` and `W` for writer.
2022-06-23 15:55:14 -07:00
Andrew Poelstra cf5503af74
Merge rust-bitcoin/rust-bitcoin#1061: Enabe clippy on CI
e2e465056c Add clippy to pre-commit githook (Tobin C. Harding)
820adc0de0 Add githooks directory (Tobin C. Harding)
668b37af5c Enable clippy on CI (Tobin C. Harding)
a2a54b3982 Remove unnecessary ? operator (Tobin C. Harding)
67ed8f673e Remove unneeded clone (Tobin C. Harding)
eccd401fc4 Remove unneeded reference (Tobin C. Harding)
fd4239f1d2 Use custom digit grouping (Tobin C. Harding)
acd551e644 Remove unnecessary 'static lifetime (Tobin C. Harding)
3102a48d39 Allow clippy::collapsible_else_if (Tobin C. Harding)
63f4ff6406 Remove redundant field names (Tobin C. Harding)

Pull request description:

  We are almost ready to enable clippy on CI!

  First clear a few remaining warnings from feature gated code. Then add a CI job to run clippy using `--all-features` (note no `--all-targets`). Next add githooks directory (this is the patch from https://github.com/rust-bitcoin/rust-bitcoin/pull/1044/commits). Finally add `cargo clippy` to the pre-commit hook.

  EDIT: I just realized the running of clippy could have been done in `test.sh` instead of as a github action. Does that matter?

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

Tree-SHA512: c78cb78973d3935e5be7908eec7d6ffaa7989724b3e29551b9fa2cb35df1f39574e31e5cc93fdfb32b35039ac9dac5c080ae4287a1e6979dd076bab56e6eda1b
2022-06-23 20:24:02 +00:00
Tobin C. Harding e2e465056c Add clippy to pre-commit githook
We have a `pre-commit` githook, add to it a call to `cargo clippy`.
2022-06-23 16:18:28 +10:00
Tobin C. Harding 820adc0de0 Add githooks directory
Add a `githooks` directory. Copy the sample pre-commit hook into it.
Add a section to the README explaining how to take advantage of the
githooks.

The sample pre-commit hook includes checks for trailing whitespace that
we are seeing occasionally in PRs.

Done in preparation for adding a clippy githook.
2022-06-23 16:18:24 +10:00
Tobin C. Harding 668b37af5c Enable clippy on CI
Add a clippy configuration file configuring the MSRV. Add a github
actions job to run clippy on CI.

Please note the job does _not_ use `--all-targets` because doing so
causes:
```
error[E0554]: `#![feature]` may not be used on the stable release channel
--> src/lib.rs:46:54
|
46 | #![cfg_attr(all(test, feature = "unstable"), feature(test))]
```
2022-06-23 14:07:02 +10:00
Tobin C. Harding a2a54b3982 Remove unnecessary ? operator
clippy emits:

  warning: question mark operator is useless here

As suggested, remove the `?` operator.
2022-06-23 13:58:29 +10:00
Tobin C. Harding 67ed8f673e Remove unneeded clone
clippy emits:

 warning: using `clone` on type `blockdata::transaction::OutPoint` which
 implements the `Copy` trait

Remove unneeded call to `clone`.
2022-06-23 13:57:31 +10:00
Tobin C. Harding eccd401fc4 Remove unneeded reference
clippy emits:

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

As suggested, remove the explicit reference.
2022-06-23 13:56:28 +10:00