Commit Graph

567 Commits

Author SHA1 Message Date
Steven Roose dad3abd20f
transaction: Rename is_coin_base to is_coinbase
Keep the old method as deprecated and add doc alias.
Also change internal usage of the method.
2023-04-19 16:02:59 +01:00
Tobin C. Harding 6c61e1019e
Fix pinning (schemars and MSRV)
Done as is single patch to make sure all the docs and CI are in sync and
correct.

We currently pin the `schemars` dependency using `<=0.8.3` as well as a
the `dyn-clone` transient dependency in the manifest (`hashes` and the
extended test crate). This is incorrect because it makes usage of the
crate klunky (or possibly impossible) if downstream users wish to use a
later version of `schemars`.

Observe also that we do not have to pin `schemars`, we do however have to pin
the `serde` crate if either `serde` or `schemars` features are enabled.
Do so in CI and document in the readme file within hashes.

Currently we have a pin remaining from the old MSRV (`syn` due to use
of `matches!`).

Fix pinning by:

- Remove pin in manifest for `schemars`
- Fix pinning for MSRV in CI and docs (this includes documenting pinning
  requirements for `schemars` feature because it is related to the other
  pin of `serde`) in both `hashes` readme and main repo readme.
2023-04-19 10:17:18 +10:00
Sergi Delgado Segura aa6a3530a6 Adds as_core_arg serde module to network
The new module provides serde functions to convert from/to Bitcoin Core
network variants

Includes tests suggested by @tcharding
2023-04-17 12:28:13 +02:00
Andrew Poelstra 0af8d45e21
Merge rust-bitcoin/rust-bitcoin#1797: Add predict_weight test for witness address types
8f6317fbab Add predict_weight test for witness address types (yancy)

Pull request description:

  Add a predict_weight test for address types with witness data

ACKs for top commit:
  Kixunil:
    ACK 8f6317fbab
  apoelstra:
    ACK 8f6317fbab

Tree-SHA512: 954908f068d6b0e8f7cc6bc6bffd110d490d7165cf2544ff0f936264761cb1f8e4da1e37fd5a6a34fd8b05f8d72817a3b340bbf968b29c9f538f10853347fdf0
2023-04-14 16:08:31 +00:00
yancy 8f6317fbab Add predict_weight test for witness address types 2023-04-14 12:02:37 +02:00
yancy dff757d7db Comment predict_weight 2023-04-13 17:44:41 +02:00
Steven Roose 3d524e06e4
Add Inventory::network_hash() method 2023-04-13 16:23:22 +01:00
Steven Roose ed6421c939
address: Add generic serde::Serialize for Address
Otherwise a generic `Address<impl NetworkValidation>` is not
serializable.
2023-04-09 19:02:53 +01:00
Steven Roose 814b9917da
address: Add Sync, Send, Sized and UnPin marker traits on NetworkValidation 2023-04-09 19:02:43 +01:00
Andrew Poelstra e83a2d3422
Merge rust-bitcoin/rust-bitcoin#1742: Use package in manifest and shorten import
fabcde036f Use package in manifest and shorten import (Tobin C. Harding)

Pull request description:

  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.

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

Tree-SHA512: bc5bff6f7f6bf3b68ba1e0644a83da014081d8c6c9d578c21cb54fdd56a018f68733dd1135d05b590ba193ed9efd12fa9019182c1fed347e604d8548f6ef9103
2023-04-05 14:20:06 +00:00
Andrew Poelstra 8edfc4597b
Merge rust-bitcoin/rust-bitcoin#1765: unsafe address type conversions
29cb34eed7 Refactor Address struct and its methods (Harshil Jani)

Pull request description:

  Closes #1755

  In this PR the `as_unchecked` is added to the Address struct, which returns a reference to the same address but with the type Address<NetworkUnchecked>.  Similarly, the `assume_checked_ref` is added to Address<NetworkUnchecked>, which returns a reference to the same address but with the type Address.

ACKs for top commit:
  tcharding:
    ACK 29cb34eed7
  apoelstra:
    ACK 29cb34eed7

Tree-SHA512: 75ba40883d9fb31026b0e94e8d3fdcf808ff38a4d10f61f99a1e14ddc48358da86bad44cd78563dc67aa5d39382a5493e73c03891317f361f590e39b6257cb84
2023-04-04 17:40:33 +00:00
Andrew Poelstra 350b413e59
Merge rust-bitcoin/rust-bitcoin#1773: Make `sha256t_hash_newtype!` evocative of the output.
91f45a214f Replace hardcoded values with compile-time hashing (Martin Habovstiak)
095b7958dd Make `sha256t_hash_newtype!` evocative of the output. (Martin Habovstiak)

Pull request description:

  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 https://github.com/rust-bitcoin/rust-bitcoin/issues/1427

  Depends on #1769

  How do you like the syntax? Is weird `struct Foo = bar(..);` acceptable?

ACKs for top commit:
  tcharding:
    ACK 91f45a214f
  apoelstra:
    ACK 91f45a214f

Tree-SHA512: f6b555b20311a4c1cb097bc296c92459f6fbe16ba102d8c977eb2383dbcae3cc8ffce32e3cb771e7e22197fda26379971aa4feaadc5e2e70d37fa690ae8b8859
2023-04-03 18:21:58 +00:00
Andrew Poelstra 142b4fc431
Merge rust-bitcoin/rust-bitcoin#1771: Use slice patterns
873501a85f Use slice patterns (Martin Habovstiak)

Pull request description:

  Some code looks better with slice patterns. This changes `bip32` to use them.

ACKs for top commit:
  apoelstra:
    ACK 873501a85f
  tcharding:
    ACK 873501a85f

Tree-SHA512: 2e91b21d0f943c04f592112f241444ba3b1b1dad47ea6bea162f62cfbcaf98e383257cad144072b3807aaa0c122dabab638ac10b1cc1f5179727a5f05aac0659
2023-04-03 15:48:35 +00:00
Harshil Jani 29cb34eed7 Refactor Address struct and its methods
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>
2023-04-03 15:24:45 +05:30
Martin Habovstiak 91f45a214f Replace hardcoded values with compile-time hashing
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.
2023-04-02 17:01:10 +02:00
Martin Habovstiak 095b7958dd Make `sha256t_hash_newtype!` evocative of the output.
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
2023-04-02 17:00:52 +02:00
Martin Habovstiak 8b4280d5ef Update clippy MSRV configuration
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.
2023-04-02 16:28:10 +02:00
Martin Habovstiak 873501a85f Use slice patterns
Some code looks better with slice patterns. This changes `bip32` to use
them.
2023-04-02 01:08:03 +02:00
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
Tobin C. Harding fabcde036f
Use package in manifest and shorten import
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.
2023-03-28 12:20:04 +11: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
junderw 2158f88f1d
Add a method to `pow::Target` for returning difficulty as an f64.
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.
2023-03-10 07:54:36 -07:00
yancy f0a3aad5b8 Add tests to Weight type 2023-03-09 17:00:22 +01:00
Andrew Poelstra ca3b4330e8
specify `internals` version in other Cargo.toml files 2023-03-08 15:02:31 +00:00
yancy b311e96603 Fix weight subtract bug 2023-03-08 12:22:50 +01:00
Andrew Poelstra 9ffbbb8efb
Merge rust-bitcoin/rust-bitcoin#1694: release bitcoin_hashes 0.12
bfd401c96e bitcoin_hashes: add CHANgELOG (Andrew Poelstra)
d1b7b54e3a bump bitcoin-hashes version to 0.12 (Andrew Poelstra)

Pull request description:

  It was a little tricky to bump the version number because of https://github.com/rust-bitcoin/rust-bitcoin/issues/1553. There are a couple other things I considered trying, which maybe we'll do for future releases, but I believe this works for now.

  Maybe should wait for #1111.

ACKs for top commit:
  tcharding:
    ACK bfd401c96e
  sanket1729:
    utACK bfd401c96e. ChangeLog looks good to me, did not review whether all noteworthy changes were included.

Tree-SHA512: d2104fc93e364415ae955e8123e6087c1eaa4c955aeaf4647ead051a223563326f66c0e278d68f64335e22c9d0af9b296dc3b744cd9d82d206844461fe7bf9c9
2023-03-08 02:13:45 +00:00
Andrew Poelstra d6134248df
Merge rust-bitcoin/rust-bitcoin#1690: Add tests for the FeeRate type
e3f95ee22b Add tests for the FeeRate type (yancy)

Pull request description:

  Adds some tests for the `FeeRate` type.

ACKs for top commit:
  apoelstra:
    ACK e3f95ee22b
  tcharding:
    ACK e3f95ee22b
  Kixunil:
    ACK e3f95ee22b

Tree-SHA512: 74d6597c747d5aa62a6510bf9fa8de971f89ad56f571aadd496f6487e80cc88bb2b5a1c6bcfed825d09d18ca2310b2bfd6fdbe330f2760369d167a653d26bef8
2023-03-08 01:07:48 +00:00
Andrew Poelstra e9e8be3acc
Merge rust-bitcoin/rust-bitcoin#1692: Add constants to `InputWeightPrediction`
3eb648df01 Add constants to `InputWeightPrediction` (Martin Habovstiak)

Pull request description:

  There are several common spends in Bitcoin that have known input weight predictions. It can be useful to have these as constants, so this change adds them. However, this only adds native segwit ones as the others are slowly fading away and might clutter the API.

  If anyone wants other constants, please write them for me, their value is not that great to me so I'm not motivated to figure out the correct numbers. :)

  This would be nice to add to 0.30 since it's small and easy but not critical.

ACKs for top commit:
  apoelstra:
    ACK 3eb648df01
  tcharding:
    ACK 3eb648df01
  sanket1729:
    ACK 3eb648df01

Tree-SHA512: 51d2cd2ecef7e6b79f9d4b52319e34b908fe8b5a337551dc2088994feeafc9c3ca87884c3db8369f8bd002947d6d14b373f08ef1419db282713206ed6f1b309a
2023-03-08 00:37:05 +00:00
Andrew Poelstra cfc4fd943f
Merge rust-bitcoin/rust-bitcoin#1695: fix clippy lint
4a2f11cc49 fix clippy lint (Andrew Poelstra)

Pull request description:

  Looks like a new clippy lint landed.

ACKs for top commit:
  yancyribbens:
    ACK 4a2f11cc49
  tcharding:
    ACK 4a2f11cc49
  sanket1729:
    utACK 4a2f11cc49

Tree-SHA512: 04fd77c2daeeeed99ea854731d73bcb43fbe5fbdba2e241a93a5058ca81f05dfbf6759d055236a8c70c58331d2b93d0fafd81e7cd631b636f881d9a0b1cdc5ca
2023-03-07 21:11:52 +00:00
Martin Habovstiak 3eb648df01 Add constants to `InputWeightPrediction`
There are several common spends in Bitcoin that have known input weight
predictions. It can be useful to have these as constants, so this change
adds them. However, this only adds native segwit ones as the others are
slowly fading away and might clutter the API.
2023-03-07 09:50:13 +01:00
Tobin C. Harding c1360067e9
Enable formatting in CI
Enable formatting in CI by doing:

- Add a section to the `test.sh` scripts to run the formatter (guarded by
  the env variable `DO_FMT`) for all crates (bitcoin, hashes, internals).
- Add `DO_FMT` to the nightly `Tests` CI job.
2023-03-07 08:57:32 +11:00
yancy e3f95ee22b Add tests for the FeeRate type 2023-03-06 10:30:45 +01:00
Tobin C. Harding 61c560baba
Improve the DO_BENCH error message
Benchmarking requires a non-stable toolchain not a nightly toolchain
i.e., includes beta.

Improve the error output to indicate as such.
2023-03-06 10:22:31 +11:00
Tobin C. Harding a11cf07501
Run the formatter
Various formatting issues have crept into the codebase because we do not
run the formatter in CI.

In preparation for enabling formatting checks in CI run `cargo +nightly
fmt` to fix current formatting issues. No changes other than those
create by the formatter.
2023-03-06 10:22:29 +11:00
Andrew Poelstra 4a2f11cc49
fix clippy lint 2023-03-05 17:19:03 +00:00
Andrew Poelstra d1b7b54e3a
bump bitcoin-hashes version to 0.12
Because we have rust-secp in the loop, we need to update rust-secp, push
a new tag, and use that here, to ensure that the direct dependency on
bitcoin_hashes, and the rust-secp version, are compatible.
2023-03-05 13:40:20 +00:00
Andrew Poelstra 10eb0da1ef
Merge rust-bitcoin/rust-bitcoin#1533: Implement support for Hidden nodes in taproot trees and Fix taproot serde bugs
74022baa44 Rename ScriptLeaf to LeafNode (sanket1729)
289dc1e7f5 Remove serde for taprootspendinfo (sanket1729)
a397ab0c19 Remove serde for ScriptLeaf (sanket1729)
9affda3012 Introduce Hidden leaves in ScriptLeaves (sanket1729)
22bc39a143 Fix serde for TaprootMerkleBranch (sanket1729)
38ed9bdf49 MOVE ONLY: Move TapTree to taproot module (sanket1729)

Pull request description:

  This PR changes/removes the serde implementation for the following types

  - TaprootSpendInfo: Removed. This data structure contains derived information for taproot spending that cannot be validated easily. To elaborate, `TaprootSpendInfo` is constructed from a tree, but loses information about the tree structure and maintains handy information like `script_control_block_map`, cached tweaked key, Merkle root etc.
  - TaprootBuillder: Removed. Hard to implement and not very useful.
  - TapTree: Modified to check invariants.
  - NodeInfo: Now implements serde with support for Hidden nodes
  - ScriptLeaf: Removed serde. Users should not directly construct this. This is just an output iterator item of `TapTree::script_leaves()`

  Data structure changes:

  - Introduced `LeafNode`: Supports Hidden leaves. Has serde implemented
  - Cleanly separate `TapTree` and `NodeInfo`:  `TapTree` is a full BIP370 compatible tree with no hidden nodes. `NodeInfo` is a tree that can potentially contain hidden leaves.
  - Added `NodeInfo::leaf_nodes`: Iterator that iterates over known and hidden leaves of `NodeInfo`.
  - Updated `TapTree::script_leaves`: Iterator that is guaranteed to output known leaves.

ACKs for top commit:
  tcharding:
    ACK 74022baa44
  apoelstra:
    ACK 74022baa44

Tree-SHA512: 919ea5bf60dc0cd8431301c1b744b046d1d781b3bed302b83a600cfa644216b6c682752795d463646b2723ac8661879284f557862a67e4572fd965fcf3dc194d
2023-03-04 13:41:37 +00:00
Andrew Poelstra 1679ad878d
Merge rust-bitcoin/rust-bitcoin#1685: Improve the public API for Feerate and Weight
b0b0cdb46c Improve the public API for Feerate and Weight (yancy)

Pull request description:

  Small nit for https://github.com/rust-bitcoin/rust-bitcoin/pull/1627/ to re-export `Weight` and `FeeRate` to shorten the use path.

  ```
  use bitcoin::Weight;
  use bitcoin::FeeRate;
  ````

ACKs for top commit:
  tcharding:
    ACK b0b0cdb46c
  Kixunil:
    ACK b0b0cdb46c
  apoelstra:
    ACK b0b0cdb46c

Tree-SHA512: 81e508c980c4f37e3791d26616459608dd60e5a6255ef28b3a049c1d27281b2853b92474d42f10031254c8c46878adf666eb709826aa4ffde1b4b3542451e080
2023-03-04 01:55:53 +00:00
Andrew Poelstra ea606d93a0
Merge rust-bitcoin/rust-bitcoin#1682: Include address in Error::NetworkValidation
73e876ffd4 Include address in Error::NetworkValidation (Subhradeep Chakraborty)

Pull request description:

  Fixes: #1677

  ## Change
  In `bitcoin/src/address.rs`, a new field `address` is added to the enum variant `Error::NetworkValidation`. Also, the implementation of `Display` trait for `Error` is updated to print the `address` field.

  However, to print the `address` through `Display`, either the reference is needed or `Address` and `Payload` both need to derive the `Copy` trait. Since I am little new to both the rust-bitcoin codebase and rust itself, I am confused about choosing between the two and have moved with the first one. Would appreciate any feedback on this.

ACKs for top commit:
  Kixunil:
    ACK 73e876ffd4
  tcharding:
    ACK 73e876ffd4
  apoelstra:
    ACK 73e876ffd4

Tree-SHA512: dd53b8648bccc8372c829e56817402fb02a9d51d1dffc854f24e68814bbefe7ea777f67aefb0d170762dbf6cdd50bd3ec55af325a1ffc21b1241d1df5531cd24
2023-03-03 16:09:21 +00:00
Subhradeep Chakraborty 73e876ffd4 Include address in Error::NetworkValidation 2023-03-02 20:46:48 +05:30
yancy b0b0cdb46c Improve the public API for Feerate and Weight 2023-03-02 09:57:36 +01:00
sanket1729 74022baa44 Rename ScriptLeaf to LeafNode
ScriptLeaf feels like leaf has to be a script, but it can a hidden
subtree. LeafNode conveys this better
2023-03-01 16:59:13 -08:00
sanket1729 289dc1e7f5 Remove serde for taprootspendinfo
Implementing this for spendinfo is really complicated because it
contains some cached data without retaining the components that are used
to compute them.

Users should serde the 1) NodeInfo and 2) internal key and reconstruct
TaprootSpendInfo from it.
2023-03-01 16:58:24 -08:00
sanket1729 a397ab0c19 Remove serde for ScriptLeaf
This was incorrect and not needed. Users should not be able to create
only tree leaves directly without going through the tree construction in
rust-bitcoin
2023-03-01 16:58:24 -08:00
sanket1729 9affda3012 Introduce Hidden leaves in ScriptLeaves
Cleanly separate `TapTree` and `NodeInfo`. Fix serde not respecting
invariants for several data structures

Repurpose some tests from removed taproot builder for taptree
2023-03-01 16:58:24 -08:00
sanket1729 22bc39a143 Fix serde for TaprootMerkleBranch 2023-03-01 16:57:56 -08:00
sanket1729 38ed9bdf49 MOVE ONLY: Move TapTree to taproot module 2023-03-01 16:57:55 -08:00
Andrew Poelstra 2cf1a4c088
Merge rust-bitcoin/rust-bitcoin#1678: Improve the public API
42b07586ac Improve the public API (Tobin C. Harding)

Pull request description:

  We created the `crypto` crate as a container for cryptography modules with the idea that it may be split out into a separate crate. There is no reason for users of the lib to know about this module. Also, we have two `taproot` modules, one in `crypto` and one at the crate root, this makes for un-ergonomic usage of the lib.

  Improve the public API by doing:

  - Make the `crypto` module private (`pub(crate)`).
  - Re-export `crypto::taproot::Signature` (and `Error`) from `crate::taproot`

  Fix: #1668

ACKs for top commit:
  apoelstra:
    ACK 42b07586ac
  Kixunil:
    ACK 42b07586ac

Tree-SHA512: 5713b98b2a48d2776cdd6ca2c0e798d6e2df604d780e5182bd770fb2df807cf1f65bc24663ee6f7734fc1e0c80494c5a87dc60e44c83acefcffec7f059203a47
2023-03-01 15:42:36 +00:00
Tobin C. Harding 42b07586ac
Improve the public API
We created the `crypto` crate as a container for cryptography modules
with the idea that it may be split out into a separate crate. There is
no reason for users of the lib to know about this module. Also, we have
two `taproot` modules, one in `crypto` and one at the crate root, this
makes for un-ergonomic usage of the lib.

Improve the public API by doing:

- Make the `crypto` module private (`pub(crate)`).
- Re-export `crypto::taproot::Signature` (and `Error`) from
  `crate::taproot`
2023-03-01 09:28:42 +11:00
Andrew Poelstra 5ad2bec626
Merge rust-bitcoin/rust-bitcoin#1679: Add constant for coinbase maturity
7d1645aea0 Add constant for coinbase maturity (benthecarman)

Pull request description:

  Not sure if this is the best place to put this but it is nice to have a constant for this instead of having other libraries make their own (ie https://github.com/lightningdevkit/rust-lightning/pull/1924#pullrequestreview-1222807626)

ACKs for top commit:
  tcharding:
    ACK 7d1645aea0
  apoelstra:
    ACK 7d1645aea0

Tree-SHA512: 5ac2a3359cadd303158c66ba45db8f4bf8cc80b6c19604262999ff361fd0bd98e2a4851c57da1962cb5c74f5789a85c8b3861f1742706a60ce1fbc57c3c200cc
2023-02-28 22:01:34 +00:00
benthecarman 7d1645aea0
Add constant for coinbase maturity 2023-02-28 05:37:10 -06:00
Andrew Poelstra 13143d0f6f
Merge rust-bitcoin/rust-bitcoin#1675: Add utils to convert ChainHash to a Network
56569b32ef Add utils to convert ChainHash to a Network (benthecarman)

Pull request description:

ACKs for top commit:
  Kixunil:
    ACK 56569b32ef
  tcharding:
    ACK 56569b32ef

Tree-SHA512: a489fcb1c1208db4271076d88288658988a63209e56e7433bde82d7d5719450433348fcc3cb6aae59ffa6ed8aff510d6b031c6899d5cf64c503a53b2d4c692b8
2023-02-27 23:55:24 +00:00