This commit refactors the Address struct and its methods to improve
its functionality and usability.The AddressInner struct now holds
the payload and network, and the PhantomData<V> type is used to track
the network validation state.
Also as_unchecked and assume_checked_red methods are added to allow
conversion between checked and unchecked network validation state.
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
Previous changes enabled passing the string used as a tag into
`sha256t_hash_newtype!` macro rather than hard-coding midstate. This
commit takes advantage of it and replaces the hard-coded values with
compile-time executed (`const`) hashing.
The Rust API guidelines state that macros should be evocative of the
output, which is a sensible recommendation. We already had this for
`hash_newtype!` macro but didn't for sha256t version.
This changes the macro to have this syntax:
```rust
sha256t_hash_newtype! {
// Order of these structs is fixed.
/// Optional documentation details here. Summary is auto-generated.
/*pub*/ struct Tag = raw(MIDSTATE_BYTES, LEN);
/// Documentation here
#[hash_newtype(forward)] // optional, default is backward
/*pub*/ struct HashType(/* attributes allowed here */ _);
}
```
Closes#1427
We've upgraded MSRV but didn't update clippy config, so some things that
could be improved aren't caught by clippy. This updates the config and
fixes the new issues.
I also `rg '1\.41\.1'`ed for interesting changes and found one
additional improvement.
Computing hashes in const fn is useful for esily creating tags for
`sha256t`. This adds `const fn` implementation for `sha256::Hash` and
the algorithm for computing midstate of tagged hash in `const` context.
Part of #1427
1187e10299 Add per crate release notes link (Tobin C. Harding)
Pull request description:
In #1759 we fixed the link to the bitcoin changelog, we can go one step further and add links for each of the crates.
ACKs for top commit:
apoelstra:
ACK 1187e10299
Kixunil:
ACK 1187e10299
sanket1729:
ACK 1187e10299
Tree-SHA512: 10c79c2e633c130855b321d7644b639d7f5fde9dbe94ee54005c34f7ac0821bab714d8a09a6480bfc5363cadc05eeb6dc052409b62e744aae130b7955d9d250d
a189942c64 Use doc_auto_cfg (Tobin C. Harding)
Pull request description:
If we use `#![cfg_attr(docsrs, feature(doc_auto_cfg))]` instead of `#![cfg_attr(docsrs, feature(doc_cfg))]` we no longer need to manually mark types with `#[cfg_attr(docsrs, doc(cfg(feature = "std")))]`.
Sweeeeeet.
Props to pezcore for the lesson :)
ACKs for top commit:
apoelstra:
ACK a189942c64
Kixunil:
ACK a189942c64
Tree-SHA512: 1ced1e09f5d1733b362b83ca650d3f52c89eb57e78e8437f74c496d89776548f8c50feab6750352342e2abe680434681de2c126ce36a81dda21397b9695d4d4e
91863c8a78 Feature (hashes): Add from_bytes_ref and from_bytes_mut to all Hash types (junderw)
Pull request description:
Closes#1756
I added tests to one of the Hash types, let me know if this seems reasonable as a test and I'll add it for all the other Hash types.
ACKs for top commit:
apoelstra:
ACK 91863c8a78
tcharding:
ACK 91863c8a78
Tree-SHA512: e1fc278eab4c13b04462636d424b05c599d8f75d76ac8c50cff195085af5ab71aee8a74386d58a457a7ab528226ff4686b3fd0c0019530835709ac1c9577281e
046bda321b comparing NetworkUncheck addresses (Harshil Jani)
Pull request description:
Closes#1754
This PR adds an implementation of the PartialEq trait for the `Address` struct with NetworkUnchecked. The newly implemented function checks if two addresses are equal based on their network and payload. This implementation is useful when comparing an Address with NetworkUnchecked to another Address with NetworkUnchecked
ACKs for top commit:
Kixunil:
ACK 046bda321b
apoelstra:
ACK 046bda321b
Tree-SHA512: 9db28bd9fe6721c754515812bf8b7ca6a2a1285501e3e998298bb430cc129971dc03b9b9ed4a764aa1ebd9d3cb0b06cc5e7fdb9196682410e795c57211672b87
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
implementation of PartialEq<Address> for Address<NetworkUnchecked>
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
If we use `#![cfg_attr(docsrs, feature(doc_auto_cfg))]` instead of
`#![cfg_attr(docsrs, feature(doc_cfg))]` we no longer need to manually
mark types with `#[cfg_attr(docsrs, doc(cfg(feature = "std")))]`.
Sweeeeeet.
bbda9599fa [Docs] Update internal project link to changelog (David A. Harding)
Pull request description:
The changelog was moved in[1], but the link to it in README.md wasn't updated. I don't see any other outdated links to it in this project via a quick git grep.
---Not your usual Harding
[1] bae64e156e
ACKs for top commit:
tcharding:
ACK bbda9599fa
apoelstra:
ACK bbda9599fa
Tree-SHA512: d2b94f4b1afe161357f6dd1fd85fa641be9aa927d48c1ef6d0c49b982633dbcb1e47caa75ebd7f81ef0706617024d0810bcde6d2b7e9149ea978a3c05a71ab1b
ed80df5ebc Add `ChainHash::from_genesis_block_hash` (Martin Habovstiak)
Pull request description:
This improves readability of converting `BlockHash` into `ChainHash`. It's useful in e.g. Electrum protocol which sends `BlockHash` (serialized backward).
Closes#1751
ACKs for top commit:
apoelstra:
ACK ed80df5ebc
tcharding:
ACK ed80df5ebc
Tree-SHA512: b03eb9ca0a1eb38196cc8e43751c2def0d00b463b774003c5319bf56599db598ddd4bb0e2ad0bd3803f21a925135992d421848e7b1ba5e7bab3a405f60fc973c
We can use `package` to rename `bitcoin_hashes` to `hashes` and
`bitcoin_internals` to `internals`. This makes imports more terse with
no loss of meaning.
82b6332b91 create a set of recognized denomination forms (yancy)
Pull request description:
I took a stab at restricting the acceptable forms here. There was some consensus that "BtC" was confusing that was discussed in a previous pr https://github.com/rust-bitcoin/rust-bitcoin/pull/1715.
Also, personally I felt that the `PossiblyConfusingDenomination` enum variant was itself confusing. I think it's probably cleaner to just maintain a list of acceptable forms and treat everything else as unknown. For now I just created a const of possibly confusing forms.
ACKs for top commit:
Kixunil:
ACK 82b6332b91
apoelstra:
ACK 82b6332b91
Tree-SHA512: f3c212046e4d8a34ce2d50f34065b1778ae190ca80dd9ad73ef41eb5925705c88c0a764ec149d731eb1735d670c5542415953633a7f3f672d0c1e46b6e004d0b
This improves readability of converting `BlockHash` into `ChainHash`.
It's useful in e.g. Electrum protocol which sends `BlockHash`
(serialized backward).
Closes#1751
9ade4f3620 add SECURITY.md (Andrew Poelstra)
Pull request description:
Draft of a SECURITY.md. Right now it only lists me -- if you are willing to be an alternate, don't be afraid to ask. Pretty-much any of the major regular contributors would be fine.
Fixes#1718
ACKs for top commit:
sanket1729:
ACK 9ade4f3620
tcharding:
ACK 9ade4f3620
Tree-SHA512: 8c6ca4e511a23efc132f2ceee7538f38116d815c20bd81b3650cddfa32e695cb812167964f2f0a0c94d6499c037b72a7c8464e5427fd77a8035540ef9e6b6b65
122188f7dd Use shorter import statements (Tobin C. Harding)
Pull request description:
Just patch 2, patch 1 is #1728
From the commit log of patch 2
Use shorter import statements
As per discussion [0] use the shorter form for importing crates that we
re-export (`hashes` and `secp256k1`).
[0] https://github.com/rust-bitcoin/rust-bitcoin/discussions/1661
ACKs for top commit:
apoelstra:
ACK 122188f7dd
sanket1729:
utACK 122188f7dd
Tree-SHA512: 3f540464d38c72ba9d68f8ceda8600540bd0c3eef0ba67531c87fa1e0e4f757af7035cf80a1a5f17aa05604a17fdd9ef59bb6bece6b4145d540dac1e5362fc01
99cb83c3e9 ci: do dry-run releases in CI (Andrew Poelstra)
Pull request description:
Will set this to "allow failure" since I think it'll fail during large parts of development, but this will be useful to avoid last-minute problems with releases.
ACKs for top commit:
tcharding:
ACK 99cb83c3e9
Kixunil:
ACK 99cb83c3e9
Tree-SHA512: 32a3e541deba26c0ef3b70a5cf9b4cf8efcebcb962258dd50ff77bd78b38cd9e749246e37133e9ddb806c558faa9cbbc9d8039061cbe888e8abb247c673325a6
1dc04fe10f Remove rust_v_1_46 (Tobin C. Harding)
71fa9e81e7 Bump MSRV to 1.48.1 (Tobin C. Harding)
Pull request description:
Just patch 2, patch 1 is #1728
From the commit log of patch 2
Bump MSRV to 1.48.1
As per discussion [0] bump our MSRV for all crates in `rust-bitcoin`
repo to 1.48.1 [1].
[0] https://github.com/rust-bitcoin/rust-bitcoin/discussions/1329
[1] https://blog.rust-lang.org/2020/11/19/Rust-1.48.html
ACKs for top commit:
apoelstra:
ACK 1dc04fe10f
sanket1729:
ACK 1dc04fe10f
Tree-SHA512: 533470c55f7aeede88382db8245033dac9317d75b38ced2ad8256d38319632a524335f893044e96300a1e60048f9aaca2d1634735eb324eb8ed9ad3c9ab2f872
dbd2ea07b5 Add kilo weight unit conversion (yancy)
Pull request description:
The FeeRate module defaults to sats per `kwu` so when doing fee calculations, it would be convenient to easily convert weight to the same units.
ACKs for top commit:
Kixunil:
ACK dbd2ea07b5
tcharding:
ACK dbd2ea07b5
apoelstra:
ACK dbd2ea07b5
Tree-SHA512: fe26b631cf474f1dca627a4d21e9052c80f8ada9a0eb635c46b7f8f42095671b9b161fb5012b723699008372faf7668507d5e92bde7d1808d389f85dba33529b
a629bef85e CI: Prevent duplicate CI runs (Jonathan Underwood)
Pull request description:
Closes#1726
This will prevent duplicate CI runs when merging an internal branch into master.
You can opt-in to a non-master branch CI by using the prefix given.
ACKs for top commit:
apoelstra:
ACK a629bef85e
Kixunil:
ACK a629bef85e
Tree-SHA512: b3a43d55ce9ae7d3c3898dfae42058f4c2990ed176a612e688166e4cb01dd0d9ddd5eec3580d275f5cb19101e43b822e4a17a34d75db68f4fe2c5ad23cdea97d
5781896814 Run cargo +nightly rustfmt (Tobin C. Harding)
Pull request description:
We just merged a patch to enable formatting in CI but commit: `05fdead2 Feature: Add difficulty_float method for block::Header.` must have slipped in.
Run the formatter.
ACKs for top commit:
Kixunil:
ACK 5781896814
apoelstra:
ACK 5781896814
Tree-SHA512: 7e97b5d56610ec9771ede30533e491e410ce79441070c8ff22f2e3d7fefc23fe327eb5ce3325ee3e356fc940c8e47806816a628daaa44b463071124beee2fbeb
We just merged a patch to enable formatting in CI but commit: `05fdead2
Feature: Add difficulty_float method for block::Header.` must have
slipped in.
Run the formatter.
913575ac91 hashes: Run the formatter (Tobin C. Harding)
52c4579057 Enable formatting for hashes (Tobin C. Harding)
3f16b6bf9f util: Run the formatter (Tobin C. Harding)
d210d2ac83 Enable formatting for util (Tobin C. Harding)
5973dce9db blockdata: Run the formatter (Tobin C. Harding)
0dcbed3c7b Enable formatting for blockdata (Tobin C. Harding)
a52746d01c psbt: Run the formatter (Tobin C. Harding)
ef306db5e2 Enable formatting for psbt (Tobin C. Harding)
296f2ed82c Make test panic instead of using code comment (Tobin C. Harding)
3ec8a12428 crypto: Run the formatter (Tobin C. Harding)
c8a3c58786 Enable formatting for crypto (Tobin C. Harding)
314e6786b4 crypto: Add rustfmt::skip attributes (Tobin C. Harding)
450a84f6e8 consensus: Run the formatter (Tobin C. Harding)
89143205f9 Enable formatting for consensus (Tobin C. Harding)
ce773af20f tests: Remove useless use of super imports (Tobin C. Harding)
ef01f4d0f6 consensus: Introduce local variables (Tobin C. Harding)
Pull request description:
One final push crew, 16 patches, only a few are big.
All non-trivial formatting is done in separate patches so the changes can be verified mechanically.
With this applied the whole `rust-bitcoin` crate will be formatted.
Big thanks to everyone for putting up with the ongoing formatting PRs, no-one likes doing these but hopefully this an improvement to the project - especially in helping us get more contributors to the project.
ACKs for top commit:
tcharding:
> ACK [913575a](913575ac91). Went through the workflow locally.
sanket1729:
ACK 913575ac91. Went through the workflow locally.
apoelstra:
ACK 913575ac91
Tree-SHA512: b30eaa2893563155de05f8fa97be4a24a7dd8bf43bb426314c5104598477ca2173af279da796da8b18cc53a0ed525908b3d4edd0504836a443465efa0773632d
998b204ece bitcoin: Fix path to the readme (Tobin C. Harding)
Pull request description:
We moved to a submodule and didn't fix the readme path in the `bitcoin` manifest.
ACKs for top commit:
sanket1729:
utACK 998b204ece
apoelstra:
utACK 998b204ece
Tree-SHA512: c7591e05974173eddbabfa7ee0273ad4c71b103108f09e7536696593f3e181f80ecfe05a2fa312963069d35137784ccae1fbb167cceccdacb8a2fab211123bf4
fe83ee6061 Update testing section (Tobin C. Harding)
Pull request description:
The testing section in `CONTRIBUTING.md` is stale, update it to point readers towards the readme.
ACKs for top commit:
apoelstra:
ACK fe83ee6061
Kixunil:
ACK fe83ee6061
Tree-SHA512: 1029de63c7e88cbb164bd637631cbf9b01eea7224914583e2b97b9e189e350fc701b24971a18d89d8d7a99b77609808ca04e2856f0bd0512bcb1010fa455255a
67618d679d Mark `Denomination` as `non_exhaustive` (Martin Habovstiak)
Pull request description:
It is possible that we will add new variants to `Denomination` in the future so making it `non_exhaustive` is better for forward compatibility.
ACKs for top commit:
tcharding:
ACK 67618d679d
apoelstra:
ACK 67618d679d
sanket1729:
ACK 67618d679d
Tree-SHA512: a28b7c6577f098b3d64c505e948e3b9fd0cc43a911a2b7c35610ada6a2f75514a1cb05ab8c99212340cf4e34426ac8b5f0ecc65d5afa22d67296e82d878b9308
2d23e11569 Remove extern crate hashbrown (Tobin C. Harding)
Pull request description:
(Merge candidate only after release of 0.30.0)
We no longer have a "hashbrown" feature, the feature gated `pub extern crate hashbrown` should have been removed when we removed the feature.
ACKs for top commit:
apoelstra:
ACK 2d23e11569
Kixunil:
ACK 2d23e11569
Tree-SHA512: 36d4c539f3f972d42bbc9fda9e96063a78d35afc6aebbf534b878dcef0440b72c2a990bcbdbb2ad3bf99cab7048cdbd4002899c2b314da21e4a7bacaf8c71f0f
05fdead2a4 Feature: Add difficulty_float method for block::Header. (junderw)
Pull request description:
Header had a passthrough method for difficulty so I added one for difficulty_float as well.
ACKs for top commit:
apoelstra:
ACK 05fdead2a4
sanket1729:
ACK 05fdead2a4. Don't mind the floating point comparison as it is in tests.
Kixunil:
ACK 05fdead2a4
tcharding:
ACK 05fdead2a4
Tree-SHA512: 1cbb9627a1d56a3ed29a836081fe7c55b26a8cbef0068a2df6d4960f302519f82e396460e3627f556e8231f06b4d321d3f2af36c065d8c0ef316b71c59aad3c9