Commit Graph

1442 Commits

Author SHA1 Message Date
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
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 6adb2c64d9
Remove redundant compile_error 2022-07-04 22:34:40 +09: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
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
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
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
Tobin C. Harding fd4239f1d2 Use custom digit grouping
clippy emits a bunch of:

 warning: digits grouped inconsistently by underscores

We have a custom grouping elsewhere in this file

  10_000_000_00 sats == 10 BTC

Fix up all instances of large sats amount to uniformly using this format
and add compiler directives where needed to shoosh clippy.
2022-06-23 13:54:34 +10:00
Tobin C. Harding acd551e644 Remove unnecessary 'static lifetime
clippy emits a bunch of:

 warning: statics have by default a `'static` lifetime

Remove the unnecessary 'static lifetimes.
2022-06-23 13:49:16 +10:00
Tobin C. Harding 3102a48d39 Allow clippy::collapsible_else_if
clippy emits:

  warning: this `else { if .. }` block can be collapsed

In this instance the code is more readable how it is, we should ignore
clippy.

Add compiler directive to quieten warning.
2022-06-23 13:47:22 +10:00
Tobin C. Harding 63f4ff6406 Remove redundant field names
clippy emits two warnings of form:

 warning: redundant field names in struct initialization

Remove the redundant field names.
2022-06-23 13:45:16 +10:00
Andrew Poelstra 66c9fedfdb
Merge rust-bitcoin/rust-bitcoin#1059: Move broken-intra-doc-link lint config to command line
281af7c1b9 Move broken-intra-doc-link lint config to command line (Tobin C. Harding)

Pull request description:

  The docs lint `broken-intra-doc-links` has been changed but the new name
  is not available in our MSRV, this means we get a build warning. We only
  build docs with the nightly toolchain so we can move this lint control
  to the docs build command in `test.sh` instead of doing it crate wide.

  With this patch applied devs risk not noticing docs link issues until
  they hit them on CI _if_ they do not build with the test script or
  explicitly pass in `-- -D rustdoc::broken-intra-doc-links`, which no one
  is going to do. Hence we add a line to the readme with a shell alias
  that can be used to check docs, taken directly from `test.sh`.

ACKs for top commit:
  apoelstra:
    ACK 281af7c1b9
  Kixunil:
    ACK 281af7c1b9

Tree-SHA512: 7c9be3bcf097444a107199c9e9df62324d80b770659556a81eca160b807245e15921cda812f83e8b24d41716273704ff7b78be9300680f1efef3cb1fbffe6afd
2022-06-22 17:05:13 +00:00
Tobin C. Harding 281af7c1b9 Move broken-intra-doc-link lint config to command line
The docs lint `broken-intra-doc-links` has been changed but the new name
is not available in our MSRV, this means we get a build warning. We only
build docs with the nightly toolchain so we can move this lint control
to the docs build command in `test.sh` instead of doing it crate wide.

With this patch applied devs risk not noticing docs link issues until
they hit them on CI _if_ they do not build with the test script or
explicitly pass in `-- -D rustdoc::broken-intra-doc-links`, which no one
is going to do. Hence we add a line to the readme with a shell alias
that can be used to check docs, taken directly from `test.sh`.
2022-06-21 09:21:19 +10:00
Tobin C. Harding 4d2291930b Use fragment-specifier literal
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.
2022-06-20 14:43:06 +10:00
Tobin C. Harding 7a3bb7d3ec Replace runtime size check with compile time check
Add a macro `const_assert` that uses some const declaration trickery to
trigger a compile time error if a boolean expression is false.

Replace runtime checks using `debug_assert_eq!` with the newly defined
`const_assert!` macro.
2022-06-20 14:40:51 +10:00
Andrew Poelstra e7a3bdda66
Merge rust-bitcoin/rust-bitcoin#1053: Implement iter::size_hint and ExactSizeIterator for Witness Iter
ec8dadaf86 Implement iter::size_hint and ExactSizeIterator for Witness Iter (Riccardo Casatta)

Pull request description:

  close https://github.com/rust-bitcoin/rust-bitcoin/issues/1050

  I don't think we need to change the `collect` since it use the `size_hint()` lower bound to initially allocate

  // with size_hint
  // test blockdata::witness::benches::bench_big_witness_to_vec              ... bench:         313 ns/iter (+/- 13)
  // test blockdata::witness::benches::bench_witness_to_vec                  ... bench:         204 ns/iter (+/- 11)

  // without
  // test blockdata::witness::benches::bench_big_witness_to_vec              ... bench:         489 ns/iter (+/- 28)
  // test blockdata::witness::benches::bench_witness_to_vec                  ... bench:         221 ns/iter (+/- 102)

  The reason why the small witness doesn't get big perf boost is because by default vec allocates 4 slots

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

Tree-SHA512: dbe09ba6ebd4014fe0639412894beedab6cc7e844a5ec1697af8f0694b62ae5d423a801df1b48ac7029444c01877975e2d5168728f038fbd4f5808bda90e0f2f
2022-06-16 13:35:24 +00:00
Andrew Poelstra e00b0c39ca
Merge rust-bitcoin/rust-bitcoin#1042: Refactor `serve_tcp` code
abfeb32e35 Remove unnecessary local variable (Tobin C. Harding)
04b09a4e8d Remove unused loop (Tobin C. Harding)
380e0016cc Use write_all instead of write (Tobin C. Harding)

Pull request description:

  Done while clearing clippy warnings, done as a separate PR because its not a simple glance to review like the others.

  Remove 2 clippy warnings and remove unnecessary local variable.

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

Tree-SHA512: 965708999c067dd8c156bbc54b711f608d524fab7051a0e56066f53b5c8d7bea1c233f04e77873b2624cd22e26a58f1d22f47870d2afe4347aa85335c3142245
2022-06-16 12:53:20 +00:00
Riccardo Casatta ec8dadaf86
Implement iter::size_hint and ExactSizeIterator for Witness Iter
// with size_hint
// test blockdata::witness::benches::bench_big_witness_to_vec              ... bench:         313 ns/iter (+/- 13)
// test blockdata::witness::benches::bench_witness_to_vec                  ... bench:         204 ns/iter (+/- 11)

// without
// test blockdata::witness::benches::bench_big_witness_to_vec              ... bench:         489 ns/iter (+/- 28)
// test blockdata::witness::benches::bench_witness_to_vec                  ... bench:         221 ns/iter (+/- 102)
2022-06-16 10:42:58 +02:00
Andrew Poelstra f30df076d0
Merge rust-bitcoin/rust-bitcoin#1051: Add getter methods for PartialMerkleTree fields
9ff0e06810 Add getter methods for PartialMerkleTree fields (eunoia_1729)

Pull request description:

  Resolves: #1046

ACKs for top commit:
  apoelstra:
    ACK 9ff0e06810
  tcharding:
    ACK 9ff0e06810

Tree-SHA512: 849f2bf87ab99a8f975ee9c78eaaf3b8d392c3338317d94234ceb9da0d78bddd488c67dfb3ded1c572d5ce400c10263d75815315a4cd52b80cd6b60e12d55078
2022-06-15 13:27:10 +00:00
eunoia_1729 9ff0e06810
Add getter methods for PartialMerkleTree fields 2022-06-11 15:36:59 +05:30
eunoia_1729 24fdb53c9c
Fix incorrect argument passed to Error::InvalidSegwitV0ProgramLength 2022-06-11 07:04:20 +05:30
eunoia_1729 66e852cd19
Update format of ExcessiveScriptSize error message 2022-06-09 01:22:23 +05:30
eunoia_1729 89bd4b61a4
Modify from_script functions in address.rs to return result
Modify from_script functions to return result instead of option so that, in case of errors, there is more
information on what went wrong.

Resolves: #1022
2022-06-09 01:13:51 +05:30
Tobin C. Harding 271d0ba068 Allow many arguments in test function
This is a unit test helper function, it is ok to have a whole bunch of
arguments.
2022-06-07 15:34:59 +10:00
Tobin C. Harding c0c88fe87d Use vec instead of pushing to a mutable vector
Clippy emits:

  warning: calls to `push` immediately after creation

Use `vec` instead of pushing to a mutable vector.
2022-06-07 15:34:59 +10:00
Tobin C. Harding 73066e7e48 Use values() to iterate map values
Clippy emits:

  warning: you seem to want to iterate on a map's values

As suggested, iterate using `values`.
2022-06-07 15:34: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 d8e82d5cd4 Remove length comparison to zero
Clippy emits:

  warning: length comparison to zero

Remove length comparison to zero, use `!is_empty`.
2022-06-07 15:26:59 +10:00
Tobin C. Harding c1f34f5c0e Return Address directly
Clippy emits:

  warning: returning the result of a `let` binding from a block

Remove the local binding, return the `Address` directly.
2022-06-07 15:26:59 +10:00
Tobin C. Harding ff8d585c17 Use flat_map instead of map().flatten()
Clippy emits:

  warning: called `map(..).flatten()` on `Iterator`

As suggested, use `flat_map` instead of chaining `map` with `flatten`.
2022-06-07 15:26:59 +10:00