Commit Graph

1416 Commits

Author SHA1 Message Date
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 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
Tobin C. Harding b24a112f08 Remove calls to clone from types that implement Copy
Clippy emits:

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

Remove calls to `clone` from types that implement `Copy`.
2022-06-07 15:26:59 +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
Tobin C. Harding ef90e3d4ed Use plus-equals operator
Clippy emits:

  warning: manual implementation of an assign operation

Use the more conventional `+=` operator.
2022-06-07 15:15:26 +10:00
Tobin C. Harding 922b820105 Replace assert!(false) with panic!
Clippy emits:

  warning: `assert!(false)` should probably be replaced

As suggested, replace assert with a call to panic.
2022-06-07 15:15:26 +10:00
Tobin C. Harding a8039e1742 Remove redundant clone
Clippy emits:

  warning: redundant clone

Remove the redundant calls to clone.
2022-06-07 15:15:26 +10:00
Tobin C. Harding cf8de73169 Remove unnecessary cast of integer literal
Clippy emits:

  warning: casting integer literal to `usize` is unnecessary

Remove the unnecessary cast.
2022-06-07 15:15:26 +10:00
Tobin C. Harding 999ac450bb Do not use assert_eq with literal bool
Clippy emits:

  warning: used `assert_eq!` with a literal bool

Use `assert!` instead of `assert_eq!(foo, true)`.
2022-06-07 15:15:25 +10:00
Tobin C. Harding abfeb32e35 Remove unnecessary local variable
In test functions; we bind to `istream` only to re-bind immediately to
`stream`, this is unnecessary and adds no additional information to the
code.
2022-06-07 14:56:06 +10:00
Tobin C. Harding 04b09a4e8d Remove unused loop
We only simulate a single connection in the test function `serve_tcp`.
Remove the unused loop (includes an unconditional break after first
iteration) and use `next` directly.

Found by clippy. Refactor only, no logic changes.
2022-06-07 14:56:06 +10:00
Tobin C. Harding 380e0016cc Use write_all instead of write
In this unit test we want to write all the pieces, use `write_all`.

Clears clippy warning about not using return value of `write`.
2022-06-07 14:55:54 +10:00
Tobin C. Harding 827fcd8a89 Allow unusual digit grouping
Clippy emits:

  warning: digits grouped inconsistently by underscores

Add allow directive for grouping that aims to make explicit 100,000,000
sats/per bitcoin.
2022-06-07 14:29:15 +10:00
Tobin C. Harding 242c640603 Remove redundant field names
Clippy emits:

  warning: redundant field names in struct initialization

As suggested, remove redundant field names in struct initialization.
2022-06-07 14:26:57 +10:00
Tobin C. Harding 0f8f4c5609 Collapse if statements
Clippy emits:

  warning: this `if` statement can be collapsed

As suggested, collapse the if statements into a single statement, with
no loss of clarity.
2022-06-07 14:24:44 +10:00
Tobin C. Harding 229fcb9f1f Use if let instead of destructuring pattern
Clippy emits:

 warning: you seem to be trying to use `match` for destructuring a
 single pattern. Consider using `if let`

As suggested, use `if let`.
2022-06-07 14:22:38 +10:00
Andrew Poelstra a9365375c1
Merge rust-bitcoin/rust-bitcoin#1037: Document `Txid` being displayed backwards
28049ce2d9 Document `Txid` being displayed backwards (Dawid Ciężarkiewicz)

Pull request description:

  Fix #958

  I hope putting it on the most notorious type where people actually notice it is enough. I couldn't find a good way to put it on all other `sha256d` automatically, and copy pasting it seems not worth it.

ACKs for top commit:
  tcharding:
    ACK 28049ce2d9
  apoelstra:
    ACK 28049ce2d9

Tree-SHA512: a5acf5d7a73361a6c48b45ed264fafb911930ae9f1bdb03895dc39c679d508dc56dbf44896fd38cf6569abb652e7fce721028ef06344462747a77078ef5a8f4f
2022-06-06 11:35:13 +00:00
Dawid Ciężarkiewicz 28049ce2d9 Document `Txid` being displayed backwards
Fix #958
2022-06-04 12:08:16 -07:00
Andrew Poelstra de17554a3c
Merge rust-bitcoin/rust-bitcoin#1033: Avoid allocation in build_scriptint
c80dbc2169 Avoid allocation in build_scriptint (Steven Roose)

Pull request description:

  Hehe, reason for party, let's invite apoelstra !

ACKs for top commit:
  apoelstra:
    ACK c80dbc2169
  tcharding:
    ACK c80dbc2169

Tree-SHA512: 8446e765d8b9fa562f636817327db6fad4bb9c906d3f69fda76e61cd258fc4c296e6ffaa440a357125c2ab45603eb05c58cb8d6822deea2fe5746e5c7c3f1e4d
2022-06-03 18:27:21 +00:00
Steven Roose c80dbc2169
Avoid allocation in build_scriptint 2022-06-02 15:36:45 +01:00
Andrew Poelstra 21f4493813
Merge rust-bitcoin/rust-bitcoin#1032: Remove network::Error
99aab446c3 Remove network::Error (Tobin C. Harding)

Pull request description:

  The `network::Error` is not used, remove it.

  (This description has been changed, the thumbs up emojis were put on the previous PR description.)

ACKs for top commit:
  sanket1729:
    reACK 99aab446c3
  apoelstra:
    ACK 99aab446c3

Tree-SHA512: 2342531160966860b7b65f8c5df10e169876ec446e6fd30093d5d81d0b0304cad04e2c2057eb3ca6b23a2fc56453c91ad4ddf426d3796fb301acb7f7d03a66b9
2022-06-02 14:14:41 +00:00
Andrew Poelstra adf3958127
Merge rust-bitcoin/rust-bitcoin#1011: Add non_exhaustive compiler directive to `AddressType`
43b684bbe6 Add non_exhaustive compiler directive to AddressType (Tobin C. Harding)

Pull request description:

  Add non_exhaustive compiler directive to AddressType

  Currently adding variants to enums is a breaking change. In an effort to
  reduce the upgrade burden on users we can use the `non_exhaustive`
  compiler directive so that adding a new variant does not cause
  downstream code to break.

  Add `non_exhaustive` to the `AddressType` since it may be extended in
  the future.

ACKs for top commit:
  sanket1729:
    ACK 43b684bbe6
  Kixunil:
    ACK 43b684bbe6
  apoelstra:
    ACK 43b684bbe6

Tree-SHA512: 2b2a15fb501d23058acca94318776ffcccedf463d43d07afa290fba46a7bd58b3a730f6e1f25605ef399afcfdb5de4c7ad67eaa0adff0ba39b0096cbcec10f57
2022-06-02 14:13:52 +00:00
Tobin C. Harding 43b684bbe6 Add non_exhaustive compiler directive to AddressType
Currently adding variants to enums is a breaking change. In an effort to
reduce the upgrade burden on users we can use the `non_exhaustive`
compiler directive so that adding a new variant does not cause
downstream code to break.

Add `non_exhaustive` to the `AddressType` since it may be extended in
the future.
2022-06-02 12:43:25 +10:00
Tobin C. Harding 99aab446c3 Remove network::Error
The `network::Error` is not used, remove it.
2022-06-02 09:49:33 +10:00
Andrew Poelstra 09b4198b16
Merge rust-bitcoin/rust-bitcoin#1031: refactor: remove SchnorrSignatureHash::Reserved variant
69707b0ccd refactor: remove SchnorrSignatureHash::Reserved variant (eunoia_1729)

Pull request description:

  Resolves #1030

ACKs for top commit:
  sanket1729:
    utACK 69707b0ccd. For reference to other reviewers:
  tcharding:
    ACK 69707b0ccd
  apoelstra:
    ACK 69707b0ccd

Tree-SHA512: d5afe9217e15db8dfd7d712e2fa69d22acda0f93fd7efbc80cf9459303a135a69c8ddf43842584769accb8cffba722ec202dc51f100e0f50262b2561a2fb1699
2022-06-01 23:27:30 +00: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 911a9ec579
Merge rust-bitcoin/rust-bitcoin#1018: Add more documentation to some core types
1875c912c3 Extend docstring for more types (Dawid Ciężarkiewicz)
325ea8fb7d Add "Relevant BIPs` to `Address` (Dawid Ciężarkiewicz)
7c2ca3d20b Add `BlockHeader` Bitcoin Core reference link (Dawid Ciężarkiewicz)
f4922f6fe7 Update `BlockHeader::version` documentation (Dawid Ciężarkiewicz)

Pull request description:

  This is meant to make it more educational, and handy even for experienced developers.

  A first step to make https://docs.rs/bitcoin (or `cargo doc --open`) a go-to place for
  convenient Bitcoin documentation.

ACKs for top commit:
  tcharding:
    tACK 1875c912c3
  apoelstra:
    ACK 1875c912c3
  sanket1729:
    utACK 1875c912c3. Thanks for doing this.

Tree-SHA512: 8457e120f9979bfd95e55e8b18faf6131610aa2241f8e5fc4630fe61dc7e16ddfc35fb6eff46339804016db7b176465943cc0c02d84dcf478ed55da9f5e06fc5
2022-06-01 15:06:35 -07:00