Commit Graph

1919 Commits

Author SHA1 Message Date
Andrew Poelstra d363cd2ebc
Merge rust-bitcoin/rust-bitcoin#1039: Fix incorrect argument passed to Error::InvalidSegwitV0ProgramLength and add test
24fdb53c9c Fix incorrect argument passed to Error::InvalidSegwitV0ProgramLength (eunoia_1729)

Pull request description:

  See also: #995, #1038

ACKs for top commit:
  sanket1729:
    utACK 24fdb53c9c. Nice catch
  apoelstra:
    ACK 24fdb53c9c
  tcharding:
    ACK 24fdb53c9c

Tree-SHA512: ced78b69054ec81431399a853291c7bad5b1a49d6683b1ac153a0f1449935bb5d75a31e3d86160602064530959a2ddc3c59a2a2ca268252c42a6805253ead9d0
2022-06-15 13:26:12 +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
sanket1729 09dd83add5
Merge rust-bitcoin/rust-bitcoin#1048: Removed edition change heads up from CONTRIBUTING
7743be00cf Removed edition change heads up from CONTRIBUTING (Martin Habovštiak)

Pull request description:

  It is done.

ACKs for top commit:
  apoelstra:
    ACK 7743be00cf
  sanket1729:
    ACK 7743be00cf

Tree-SHA512: 9cc63a97d959061db1b04757fbf993a5f2cf0e1fff388b23a8729995bf764aced18b3ef49ec25a5a324d8e49168b9e841baf2118f0769fc8689f46c3d9b3463c
2022-06-09 12:02:16 -07:00
Martin Habovštiak 7743be00cf
Removed edition change heads up from CONTRIBUTING
It is done.
2022-06-09 15:26:49 +02:00
sanket1729 8670c53d26
Merge rust-bitcoin/rust-bitcoin#1034: README: remove stale info about upcoming edition change
29cfdc8614 README: remove stale info about upcoming edition change (Dawid Ciężarkiewicz)

Pull request description:

  It is done.

ACKs for top commit:
  tcharding:
    ACK 29cfdc8614
  apoelstra:
    ACK 29cfdc8614
  sanket1729:
    ACK 29cfdc8614

Tree-SHA512: fc5b694229e4a3ebcc8f25cd4d73b65cb798d441934b2e2b473c0811367bb9c5bd6cfae9e5b68b072e3c6320f386ab54138b8589a57fc0816702474ab6de06f8
2022-06-09 01:38:47 -07:00
Andrew Poelstra 3ed3d574dc
Merge rust-bitcoin/rust-bitcoin#1038: Modify from_script functions in address.rs to return result
66e852cd19 Update format of ExcessiveScriptSize error message (eunoia_1729)
89bd4b61a4 Modify from_script functions in address.rs to return result (eunoia_1729)

Pull request description:

  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

ACKs for top commit:
  sanket1729:
    ACK 66e852cd19. LGTM
  tcharding:
    ACK 66e852cd19
  apoelstra:
    ACK 66e852cd19

Tree-SHA512: 0d9529aee0a5459351bed2cc8b2c5571736d3293e2931c43d98f53330e9ac5f3d998a19da2b4575af0a3c1c4dcfd5a24c8813390bf6f5492a689c36ebb9cb426
2022-06-08 23:59:35 +00:00
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
Andrew Poelstra 8fd700859a
Merge rust-bitcoin/rust-bitcoin#1043: Clear clippy warnings from `--all-targets`
271d0ba068 Allow many arguments in test function (Tobin C. Harding)
c0c88fe87d Use vec instead of pushing to a mutable vector (Tobin C. Harding)
73066e7e48 Use values() to iterate map values (Tobin C. Harding)
38ff025122 Remove useless use of vec! (Tobin C. Harding)
d8e82d5cd4 Remove length comparison to zero (Tobin C. Harding)
c1f34f5c0e Return Address directly (Tobin C. Harding)
ff8d585c17 Use flat_map instead of map().flatten() (Tobin C. Harding)
b24a112f08 Remove calls to clone from types that implement Copy (Tobin C. Harding)
2b8d93ec4b Remove unnecessary explicit reference (Tobin C. Harding)
ef90e3d4ed Use plus-equals operator (Tobin C. Harding)
922b820105 Replace assert!(false) with panic! (Tobin C. Harding)
a8039e1742 Remove redundant clone (Tobin C. Harding)
cf8de73169 Remove unnecessary cast of integer literal (Tobin C. Harding)
999ac450bb Do not use assert_eq with literal bool (Tobin C. Harding)
827fcd8a89 Allow unusual digit grouping (Tobin C. Harding)
242c640603 Remove redundant field names (Tobin C. Harding)
0f8f4c5609 Collapse if statements (Tobin C. Harding)
229fcb9f1f Use if let instead of destructuring pattern (Tobin C. Harding)

Pull request description:

  Clear all the clippy warnings (excl. #1042) that are returned by running `cargo clippy --all-targets`.

  I apologize in advance for the review burden :)

ACKs for top commit:
  elichai:
    ACK 271d0ba068
  apoelstra:
    ACK 271d0ba068

Tree-SHA512: 71ad2ec3db808e795791b7513f8b2a1c13dc90317f5328602c9ecbc31c09f82471f79c9c31a71a0ded5280554d1019d2bb4899fb9e8fa6421d46a2397cd31242
2022-06-08 12:50:37 +00:00
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
Dawid Ciężarkiewicz 42a91ab32a Expose SIGHASH_SINGLE bug in `encode_signing_data_to`
Via `Option` return value

Fix #1015
2022-06-06 19:17:01 -07: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
Dawid Ciężarkiewicz 29cfdc8614 README: remove stale info about upcoming edition change
It is done.
2022-06-02 21:07:23 -07: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
eunoia_1729 69707b0ccd
refactor: remove SchnorrSignatureHash::Reserved variant 2022-06-02 03:18:58 +05:30
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
sanket1729 e9a3379228
Merge rust-bitcoin/rust-bitcoin#878: Add chain hash type using consts
8e29f2b493 Add ChainHash type (Tobin Harding)
cd8f511fcb blockdata: constants: Use wildcard import in unit tests (Tobin Harding)
71bf19621a Use fully qualified path in macro (Tobin Harding)

Pull request description:

  The Lightning network defines a type called 'chain hash' that is used to uniquely represent the various Bitcoin networks as a 32 byte hash value. Chain hash is now being used by the DLC folks, as such it is useful to have it implemented in rust-bitcoin.

  One method of calculating a chain hash is by hashing the genesis block for the respective network.

  Add a `ChainHash` type that can be used to get the unique identifier of each of the 4 Bitcoin networks we support. Add a method that calculates the chain hash for a network using the double sha256 of the genesis block. Do so using hard coded consts and add unit tests (regression/sanity) that show these hard coded byte arrays match the hash of the data we return for the genesis block for the respective network.

  The chain hash for the main Bitcoin network can be verified from LN docs (BOLT 0), add a link to this document.

  Closes: #481

ACKs for top commit:
  Kixunil:
    ACK 8e29f2b493
  sanket1729:
    ACK 8e29f2b493.

Tree-SHA512: 8156bb55838b73694ddf77a606cbe403f53a31d363aa0dee11b97dc31aa9b62609d7d84b8f0f92c08e90372a3e8c7b416fb07989d6da9633763373b41339b1f5
2022-06-01 12:34:07 -07:00
sanket1729 68dd23d5ca
Merge rust-bitcoin/rust-bitcoin#993: Replace base64-compat dependency
38c41e4612 Replace base64-compat dependency (Tobin C. Harding)

Pull request description:

  Now that we have MSRV 1.41.1 we can use the more modern `base64` instead of the compat crate. Requires no changes other than changing the dependency.

ACKs for top commit:
  elichai:
    ACK 38c41e4612
  apoelstra:
    ACK 38c41e4612
  sanket1729:
    ACK 38c41e4612

Tree-SHA512: 3b53f7c52c9f8346fe4a958b8a8ffa5312891cbb4ce9f5e413bcad596f416ad2f5d6bbbde8857795544de06eaaa2450e88dde273e3177da918baed264a38d1ec
2022-06-01 11:55:07 -07:00
Andrew Poelstra 57eaf13c86
Merge rust-bitcoin/rust-bitcoin#1021: Enforce segwit v0 script validity when creating address.
6c10d77ecb Address::from_script() - Check witness v0 program lengths. (Noah)

Pull request description:

  Adds a check in `Address::from_script()` that checks if segwit v0 scripts have a valid length.

  Fix: #995

ACKs for top commit:
  tcharding:
    ACK 6c10d77ecb
  sanket1729:
    ACK 6c10d77ecb. Left a comment can be addressed in separate PR.
  apoelstra:
    ACK 6c10d77ecb

Tree-SHA512: 32aebb13477958b1455c688f668aaa3d3af4db0a7936b9549bcd1d03bd0e16635b8471549d96f1e8d408d6501e8fb515df2eb86b17a08c3152774a5be78ae8b1
2022-06-01 16:24:18 +00: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