Commit Graph

498 Commits

Author SHA1 Message Date
Andrew Poelstra 895db71156
Merge rust-bitcoin/rust-bitcoin#1763: Use doc_auto_cfg
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
2023-03-30 16:56:49 +00:00
Harshil Jani 046bda321b comparing NetworkUncheck addresses
Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>

implementation of PartialEq<Address> for Address<NetworkUnchecked>

Signed-off-by: Harshil Jani <harshiljani2002@gmail.com>
2023-03-29 11:33:20 +05:30
Tobin C. Harding a189942c64
Use doc_auto_cfg
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.
2023-03-29 14:50:33 +11:00
Andrew Poelstra dc72dfb9f2
Merge rust-bitcoin/rust-bitcoin#1753: Add `ChainHash::from_genesis_block_hash`
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
2023-03-28 01:25:18 +00:00
Andrew Poelstra 2e2d5e9e34
Merge rust-bitcoin/rust-bitcoin#1740: create a set of recognized denomination forms
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
2023-03-27 19:43:00 +00:00
yancy 82b6332b91 create a set of recognized denomination forms 2023-03-27 11:19:55 +02:00
Martin Habovstiak ed80df5ebc Add `ChainHash::from_genesis_block_hash`
This improves readability of converting `BlockHash` into `ChainHash`.
It's useful in e.g. Electrum protocol which sends `BlockHash`
(serialized backward).

Closes #1751
2023-03-26 10:42:22 +02:00
Andrew Poelstra 531dbc888c
Merge rust-bitcoin/rust-bitcoin#1730: Use shorter imports
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
2023-03-23 17:39:03 +00:00
Andrew Poelstra 3417585a53
Merge rust-bitcoin/rust-bitcoin#1729: Bump MSRV to 1.48.0
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
2023-03-23 00:50:33 +00:00
Andrew Poelstra 3ca9de82a6
Merge rust-bitcoin/rust-bitcoin#1735: Add kilo weight unit conversion
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
2023-03-23 00:11:12 +00:00
Tobin C. Harding 1dc04fe10f
Remove rust_v_1_46
We just bumped the MSRV to 1.48.0 so we know that we have all features
from 1.46, no need for `rust_v_1_46` check anymore.
2023-03-23 08:27:10 +11:00
Tobin C. Harding 71fa9e81e7
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
2023-03-23 08:03:06 +11:00
yancy dbd2ea07b5 Add kilo weight unit conversion 2023-03-22 20:05:07 +01:00
Tobin C. Harding 122188f7dd
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
2023-03-22 14:09:58 +11:00
Tobin C. Harding 5781896814
Run cargo +nightly rustfmt
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.
2023-03-22 13:49:17 +11:00
Andrew Poelstra 24af58c5ad
Merge rust-bitcoin/rust-bitcoin#1434: Format the `rust-bitcoin` crate
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
2023-03-22 01:40:01 +00:00
Tobin C. Harding 998b204ece
bitcoin: Fix path to the readme
We moved to a submodule and didn't fix the readme path in the `bitcoin`
manifest.
2023-03-22 12:08:48 +11:00
Andrew Poelstra d65646ce99
Merge rust-bitcoin/rust-bitcoin#1699: Release tracking PR - v0.30.0
ffee8ad81b Bump version to v0.30.0 (Tobin C. Harding)

Pull request description:

  Add changelog notes and bump the version number to v0.30.0.

  ## TODO - pre-merge

  - [x] Release `bitcoin_hashes` 0.12: https://github.com/rust-bitcoin/rust-bitcoin/pull/1694
  - [x] Release secp 0.27: https://github.com/rust-bitcoin/rust-secp256k1/pull/588
    - https://github.com/rust-bitcoin/rust-secp256k1/pull/590
  - [x] Update `secp256k1` dependency to use newly released v0.27: https://github.com/rust-bitcoin/rust-bitcoin/pull/1714
  - [x] Merge
    - ~https://github.com/rust-bitcoin/rust-bitcoin/pull/1696~
    - https://github.com/rust-bitcoin/rust-bitcoin/pull/1695
    -  https://github.com/rust-bitcoin/rust-bitcoin/pull/1111
  - [x] If time permits merge these:
    - #1710
    - #1705
    - #1713
  - [x] Set the release date in changelog header
  - [x] And merge these:
    - https://github.com/rust-bitcoin/rust-bitcoin/pull/1721
    - https://github.com/rust-bitcoin/rust-bitcoin/pull/1720
    - https://github.com/rust-bitcoin/rust-bitcoin/pull/1719
    - https://github.com/rust-bitcoin/rust-bitcoin/pull/1717

  ## TODO  - post release
  - [ ] Release the blogpost: https://github.com/rust-bitcoin/www.rust-bitcoin.org/pull/2
     - ~Set the date in the blog post to match the date 0.30 is released~

ACKs for top commit:
  sanket1729:
    reACK ffee8ad81b
  Kixunil:
    ACK ffee8ad81b
  apoelstra:
    ACK ffee8ad81b

Tree-SHA512: b0ea113ee1726fd9b263d0e01fe14bd544c007c05a9ac43b6c2d4edbeef3bb3ad456b061ef086626e1e1b27a0cda49cb6bc28aac3ad1691d72ffe00400ed5b45
2023-03-22 01:05:12 +00:00
Andrew Poelstra 311b023eef
Merge rust-bitcoin/rust-bitcoin#1721: Mark `Denomination` as `non_exhaustive`
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
2023-03-21 23:08:28 +00:00
Andrew Poelstra 86142f17fb
Merge rust-bitcoin/rust-bitcoin#1717: Remove extern crate hashbrown
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
2023-03-21 22:47:58 +00:00
Tobin C. Harding ffee8ad81b
Bump version to v0.30.0
Add changelog notes and bump the version number to v0.30.0.
2023-03-22 08:41:21 +11:00
Martin Habovstiak 67618d679d Mark `Denomination` as `non_exhaustive`
It is possible that we will add new variants to `Denomination` in the
future so making it `non_exhaustive` is better for forward
compatibility.
2023-03-21 20:21:37 +01:00
junderw 05fdead2a4
Feature: Add difficulty_float method for block::Header. 2023-03-21 10:30:17 -07:00
Tobin C. Harding 2d23e11569
Remove extern crate hashbrown
We no longer have a "hashbrown" feature, the feature gated `pub extern
crate hashbrown` should have been removed when we removed the feature.
2023-03-21 15:14:29 +11:00
Tobin C. Harding 3f16b6bf9f
util: Run the formatter
Run `cargo +nightly fmt`, no other manual changes.
2023-03-21 08:33:24 +11:00
Tobin C. Harding 5973dce9db
blockdata: Run the formatter
Run `cargo +nightly fmt`, no other manual changes.
2023-03-21 08:33:24 +11:00
Tobin C. Harding 0dcbed3c7b
Enable formatting for blockdata
Add `rustfmt::skip` attribute in a couple of places and then remove the
exclude for the `blockdata` module. Do not run the formatter, that will
be done as a separate patch to aid review.
2023-03-21 08:33:23 +11:00
Tobin C. Harding a52746d01c
psbt: Run the formatter
Run `cargo +nightly fmt`, no other manual changes.
2023-03-21 08:33:23 +11:00
Tobin C. Harding 296f2ed82c
Make test panic instead of using code comment
Currently we have a code comment that is supposed to assist devs in
maintaining the `network::constants::Network` type by failing to build
if a new variant is added. This plays havoc with the formatter because
the comment is hanging at the bottom of a match block and the formatting
thinks its for the proceeding line of code.

Instead of using a code comment add a panic so the unit test fails if a
new variant is added to `network::constants::Network`.
2023-03-21 08:33:23 +11:00
Tobin C. Harding 3ec8a12428
crypto: Run the formatter
Run `cargo +nightly fmt`, no other manual changes.
2023-03-21 08:33:23 +11:00
Tobin C. Harding 314e6786b4
crypto: Add rustfmt::skip attributes
In preparation for formatting the `crypto` module add a couple of `skip`
attributes to keep arrays formatted 8 bytes per line.
2023-03-21 08:33:22 +11:00
Tobin C. Harding 450a84f6e8
consensus: Run the formatter
Run `cargo +nightly fmt`, no other manual changes.
2023-03-21 08:33:22 +11:00
Tobin C. Harding ce773af20f
tests: Remove useless use of super imports
We already import `super::*`, these other imports are useless.
2023-03-21 08:33:22 +11:00
Tobin C. Harding ef01f4d0f6
consensus: Introduce local variables
In preparation for running the formatter introduce a couple of local
variables to reduce the line length and inhibit function call from being
split over multiple lines.

Refactor only, no logic changes.
2023-03-21 08:33:22 +11:00
yancy 39e528fdfc Add CentiBitcoin to denominations 2023-03-20 16:39:28 +01:00
Andrew Poelstra 2f404f9b5c
Merge rust-bitcoin/rust-bitcoin#1714: update rust-secp to 0.27.0
bef7992ce5 Update readme to mention pin for 1.47 (Tobin C. Harding)
58033cf14e pin serde dep on 1.47 (Tobin C. Harding)
f5f4a33fa9 pin serde dep on 1.41 (Andrew Poelstra)
ee9b297e98 ci: update dupe check to whitelist syn (Andrew Poelstra)
6aa640ff8d update rust-secp to 0.27.0 (Andrew Poelstra)

Pull request description:

  Also remove the spurious dev-dependency copy of rust-secp, which should've been updated to remove the "recovery" feature in https://www.github.com/rust-bitcoin/rust-bitcoin/pull/545 and then been removed entirely in https://www.github.com/rust-bitcoin/rust-bitcoin/pull/1387

ACKs for top commit:
  Kixunil:
    ACK bef7992ce5
  tcharding:
    ACK bef7992ce5

Tree-SHA512: 7d1bf062dc6920bcafa85311b4b5ed348e31fb20aa21156e545bf7a4cc4c194e2b6dcfd0d3c6db3df337e4e2cd0f7b74f41ea421549521f07080feb88fbd9382
2023-03-20 15:11:12 +00:00
Andrew Poelstra e7521fa225
Merge rust-bitcoin/rust-bitcoin#1710: Support weight prediction in `const` context
00b46d6d9d Indent functions (Martin Habovstiak)
d56d202aeb Support weight prediction in `const` context (Martin Habovstiak)

Pull request description:

  **Notes for reviewers:**
  This is something that I want to use in my code and hopefully reasonably easy to review, so if this can get into 0.30 that'd be really nice. No hard feelings if it doesn't.
  I tried to put extra effort into making review easier by:
  * intentionally "mis-formatting" the first commit so diff is smaller and easy to understand - see individual commits.
  * copying patterns from non-const fn to const fn so it's obviously correct (includes same variable names)
  * not bothering with the array trick in `VarInt::len` and simply accepting the limitation of Rust 1.46+ (I use 1.48 BTW).

  **Description**

  Some smart contracts or simplified wallets statically know the sizes of
  transactions or inputs. The possible approaches to handling them so far
  were re-computing the values (and hoping the optimizer will const fold
  them) or using a simple constant which may be harder to understand and
  get right. It's much nicer to just use a `const` but our code didn't
  support it until now.

  This change adds methods that can compute the prediction in `const`
  context for Rust versions >= 1.46.0 which allow use of loops (and
  conditions but those could be workaround anyway).

  As a side effect of this, the change also adds `const` to `VarInt::len`
  in Rust 1.46+. While this one could be made unconditional using array
  trick it's probably not worth it because of the planned MSRV bump.

ACKs for top commit:
  apoelstra:
    ACK 00b46d6d9d
  tcharding:
    ACK 00b46d6d9d

Tree-SHA512: 5509886a68b4de5227db0e28d92a40be8de64592e0b189c519213db21bcfe98ca03d9a1936b1024729b97db69e8ec0b55fac870a7ce9bab0d0c9a47b2087990f
2023-03-19 13:22:34 +00:00
Tobin C. Harding 58033cf14e
pin serde dep on 1.47 2023-03-19 12:15:56 +11:00
Andrew Poelstra f5f4a33fa9
pin serde dep on 1.41 2023-03-18 22:10:18 +00:00
Andrew Poelstra ee9b297e98
ci: update dupe check to whitelist syn 2023-03-18 22:08:45 +00:00
Andrew Poelstra 6aa640ff8d
update rust-secp to 0.27.0
Also remove the spurious dev-dependency copy of rust-secp, which
should've been updated to remove the "recovery" feature in
https://www.github.com/rust-bitcoin/rust-bitcoin/pull/545 and
then been removed entirely in https://www.github.com/rust-bitcoin/rust-bitcoin/pull/1387
2023-03-18 22:01:42 +00:00
junderw 4924148dc6
Swap out `Work::log2` implementation for `U256::to_f64` 2023-03-17 14:10:00 -07:00
Martin Habovstiak 00b46d6d9d Indent functions
This fixes indentatiion that was intentionally "messed up" to make code
review easier.
2023-03-17 08:16:21 +01:00
Martin Habovstiak d56d202aeb Support weight prediction in `const` context
Some smart contracts or simplified wallets statically know the sizes of
transactions or inputs. The possible approaches to handling them so far
were re-computing the values (and hoping the optimizer will const fold
them) or using a simple constant which may be harder to understand and
get right. It's much nicer to just use a `const` but our code didn't
support it until now.

This change adds methods that can compute the prediction in `const`
context for Rust versions >= 1.46.0 which allow use of loops (and
conditions but those could be workaround anyway).

As a side effect of this, the change also adds `const` to `VarInt::len`
in Rust 1.46+. While this one could be made unconditional using array
trick it's probably not worth it because of the planned MSRV bump.

Note: this commit is intentionally unformatted to make diff easier to
understand. Formatting will be done in future commit.
2023-03-17 08:16:17 +01:00
Salvatore Ingala 2961c0c589
Exclude usage of atomic types if not supported for the target
The gate is only added for Rust >= v1.60, since earlier versions don't support #[cfg(target_has_atomic = ...)]
2023-03-16 22:42:15 +01:00
Martin Habovstiak a6188a90c0 Improve QR code formatting documentation
It wasn't obvious that displaying address with alternate formatting
upper cases bech32 addresses.

This change adds information about this and also a note about the
compatibility of various wallets.
2023-03-15 06:45:58 +01:00
Andrew Poelstra edcb6fb81f
Merge rust-bitcoin/rust-bitcoin#1700: update internals CHANGELOG for release
51f2f8483c rename bitcoin-internals to bitcoin-private (Andrew Poelstra)
ca3b4330e8 specify `internals` version in other Cargo.toml files (Andrew Poelstra)
be02045561 update internals CHANGELOG for release (Andrew Poelstra)

Pull request description:

  .

ACKs for top commit:
  Kixunil:
    ACK 51f2f8483c
  tcharding:
    ACK 51f2f8483c

Tree-SHA512: 6eca1dded06da2567f4f7b032b800f8dbd5f6ea768693eb70c7853a06ae7e19be109fbeaf2af45a196180597f7e122b85e8f0abaa702ec60e1b72868c5a74db9
2023-03-14 19:12:05 +00:00
Andrew Poelstra 37b02199e6
Merge rust-bitcoin/rust-bitcoin#1707: Add a method to `pow::Target` for returning difficulty as an f64.
2158f88f1d Add a method to `pow::Target` for returning difficulty as an f64. (junderw)

Pull request description:

  Closes #1703

  This adds a conversion function to U256 to get an f64. We use the method shown in the following blog post.

  https://blog.m-ou.se/floats/

  Target::MAX was converted to a f64 and set as a const that is verified in a unit test.

  The code is rather confusing, so I took a crack at explaining it in my comments as well. Please let me know if you want it cleaned up some more.

ACKs for top commit:
  apoelstra:
    ACK 2158f88f1d
  tcharding:
    ACK 2158f88f1d

Tree-SHA512: 7c0e82bd1756950c1c6dfb9da91fd71b276e2e7dc8a33e69112f87b87e358240f0f7c4894d24ab228e149d862938833a2e65e345ce2712a78dc86dec197da34f
2023-03-14 18:25:38 +00:00
Andrew Poelstra 51f2f8483c
rename bitcoin-internals to bitcoin-private 2023-03-13 16:02:12 +00:00
Steven Roose 9dd4c54a74
Fix CI builds where default features are added accidentally 2023-03-12 20:24:55 +00:00