Commit Graph

3840 Commits

Author SHA1 Message Date
Andrew Poelstra 1ceac90bf6
Merge rust-bitcoin/rust-bitcoin#2565: Removes txid prefix in transaction IDs
56132f59d5     Remove the `:#` formatting for `hex_fmt_impl` macro (448 OG)

Pull request description:

  This commit attempts to solve #2505  by ensuring that formatting is not forced using the `:#` in the hex macro code generating in macro rule `hex_fmt_impl` in the hashes/utils.rs file.

  The write! macro forces all formatting to add the prefix `0x` by adding an alternate by (#) default

  ```rust
  impl<$($gen: $gent),*> $crate::_export::_core::fmt::Debug for $ty<$($gen),*> {
              #[inline]
              fn fmt(&self, f: &mut $crate::_export::_core::fmt::Formatter) -> $crate::_export::_core::fmt::Result {
                  write!(f, "{:#}", self) // <-- This is where the formatting is being forced.
              }
          }
  ```

  By removing this formatting, the `:#` must be specified by the user in order for a prefix to be added.

  ```rust
  let outpoint = bitcoin::OutPoint::default();
      println!("{:?}", &outpoint);
      println!("{:#?}", &outpoint);
      println!("{:#}", &outpoint);
      println!("{:x}", &outpoint.txid);
      // `{:#}` must be specified to pretty print with a prefix
      println!("{:#}", &outpoint.txid);
      dbg!(&outpoint);
      dbg!(&outpoint.txid);
  ```

  The PR also adds testcase for this when running `cargo test` .

ACKs for top commit:
  tcharding:
    ACK 56132f59d5
  apoelstra:
    ACK 56132f59d5

Tree-SHA512: 9e4fc9f30ab0b3cf2651d3c09f7f01d8245ac8ea7ae3a82bb4efd19f25c77662bf279020a31fa61b37587cc0c74284696c56045c59f1ba63b2dd42a210d98ebc
2024-03-13 17:28:09 +00:00
Andrew Poelstra fd1b364a48
Merge rust-bitcoin/rust-bitcoin#2538: Add support for SHA384
4e3bb7350a Add support for SHA-384 (Matt Corallo)

Pull request description:

  Based on #2473 as we need support for 48-byte arrays <-> hex conversions.

  Closes #2483

ACKs for top commit:
  Kixunil:
    ACK 4e3bb7350a
  sanket1729:
    ACK 4e3bb7350a

Tree-SHA512: e78d97f80ab8afda8a3ea240023338f17f7e95604a879b38fc9bde057fbb45b74b1f3fb3bd2b17af89682b79dda42bf114989e7c63066b3029451ef07894e82f
2024-03-13 17:10:21 +00:00
Andrew Poelstra d2617f99b2
Merge rust-bitcoin/rust-bitcoin#2530: Improve leaf errors
f8de7954b2 Remove unused pow::TryFromError type (Tobin C. Harding)
43c5eb765c Fix witness_version leaf error type (Tobin C. Harding)
2af764e859 hashes: Fix leaf error type (Tobin C. Harding)

Pull request description:

  In light of recent discussion go over the codebase and look for some places that the leaf errors are wrong. Does not do the whole code base, excludes `p2p` and a couple of other places.

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

Tree-SHA512: 2905878363869ee205cce49c58c060c712c9b7b55965ee60bb856128842968a4be86c93a194ffffdb35e215b2bea8ad33b04ee47e8e17cc784b0641ea48518e5
2024-03-13 15:03:57 +00:00
Tobin C. Harding 6ecc41d126
Return error when constructing pubkey from slice
Constructing a pubkey using `PublicKey::from_slice` can fail for reasons
other than just incorrect length - we should not be using `expect` but
rather returning the error.

A purist might argue that we are now returning a nested error type with
an unreachable variant:

  `ParsePublicKeyError::Encoding(FromSliceError::InvalidLength)`

Is this acceptable or do we want to further improve this?
2024-03-13 09:22:11 +11:00
Andrew Poelstra 6f6cc00eb7
Merge rust-bitcoin/rust-bitcoin#2572: Upgrade bitcoinconsenus
be329c2d7b Upgrade bitcoinconsenus (Tobin C. Harding)

Pull request description:

  Upgrade to the most recent `bitcoinconsensus` version that excludes Taproot verification i.e., one version before latest.

ACKs for top commit:
  sanket1729:
    ACK be329c2d7b
  apoelstra:
    ACK be329c2d7b

Tree-SHA512: 428e8e5010719a46401be58c2d4fe88662991766afe97c879147599c1bd79c85ced09dcf5ef37f3cf3f49d79c53b390881969eac93c1475dad751cc760ffd64e
2024-03-12 15:01:38 +00:00
Matt Corallo 4e3bb7350a Add support for SHA-384
This is another truncated variant of SHA-512, so there's not a lot
to add here, but its occasionally useful, though often in
non-Bitcoin contexts.
2024-03-12 13:56:58 +00:00
Andrew Poelstra 960b30c1e6
Merge rust-bitcoin/rust-bitcoin#2573: Remove useless convertion
62f726d5a8 Remove useless convertion (Tobin C. Harding)

Pull request description:

  No clue how this got into master, I thought pinning nightly stopped things like this; found with `just sane`.

  Clippy emits:

   useless conversion to the same type: `amount::ParseAmountError`

  As suggested, remove the useless conversion.

ACKs for top commit:
  sanket1729:
    utACK 62f726d5a8

Tree-SHA512: c73a7ba79c17451f226ba004e2abea709e083aa71b9c117e39beb1623c16d9ca85c398f12da079de14bfdd21725057ba89e1515be034970bcc2ce40fc766cd14
2024-03-12 12:02:58 +00:00
448 OG 56132f59d5
Remove the `:#` formatting for `hex_fmt_impl` macro
This fixes the issue where pretty debug like `dbg` or `{:#}` introduce the use of
    `0x` prefix to hex encoded transaction ID.

    The transaction id is being forced to pretty print inside the `hex_fmt_impl` macro
    using `{:#}` in the line `write!(f, "{:#}", self)` debug formatter.

    Resolves: #2505
2024-03-12 11:48:05 +03:00
Tobin C. Harding 62f726d5a8
Remove useless convertion
No clue how this got into master; found with `just sane`.

Clippy emits:

 useless conversion to the same type: `amount::ParseAmountError`

As suggested, remove the useless conversion.
2024-03-12 12:56:07 +11:00
Tobin C. Harding f8de7954b2
Remove unused pow::TryFromError type 2024-03-12 12:14:26 +11:00
Tobin C. Harding 43c5eb765c
Fix witness_version leaf error type
Leaf error types should typically have private fields, provide accessor
functions, and not use `non_exhaustive`.
2024-03-12 12:14:14 +11:00
Tobin C. Harding 2af764e859
hashes: Fix leaf error type
Leaf error types should typically have private fields, provide accessor
functions, and not use `non_exhaustive`.
2024-03-12 12:13:05 +11:00
Tobin C. Harding be329c2d7b
Upgrade bitcoinconsenus
Upgrade to the most recent `bitcoinconsensus` version that excludes
Taproot verification i.e., one version before latest.
2024-03-12 12:04:32 +11:00
Tobin C. Harding cbee9781e8
Move unit types to units
Move the following unit types to the new `units` crate:

- `locktime::absolute::{Height, Time}`
- `locktime::relative::{Height, Time}`
- `FeeRate`
- `Weight`

Also move the `parse` module as well as constants as required.

Do minimal changes to get things building:

- Feature gate on "alloc" as needed.
- Remove rustdocs that use `bitcoin` types.
- Re-export units types so this is a non-breaking change.
- Fix import paths.
2024-03-12 11:59:39 +11:00
Tobin C. Harding 5bd0d7194b
Remove unused absolute::Error
The `absolute::Error` is not used, we originally intended it as possibly
useful for users of the library. We have not made effort in other
modules to provide such errors - lets remove it.
2024-03-12 09:13:09 +11:00
Andrew Poelstra a124ff41c4
Merge rust-bitcoin/rust-bitcoin#2473: Upgrade to `hex v0.2.0`
f337dec2b1 hashes: Remove unnecessary feature guard from test (Tobin C. Harding)
0cea90d505 Test hashes honour Formatter::precision (Tobin C. Harding)
4bfb466bb9 Upgrade hex dependency (Tobin C. Harding)
f0558e8eb9 Use fmt_hex_exact (Tobin C. Harding)
6820f51408 hashes: Add fmt roundtrip tests (Tobin C. Harding)
e302e30e7c Import with super::* in unit test (Tobin C. Harding)

Pull request description:

  Upgrade to use the newly released `hex` code.

  - Patch 1: Does trivial preparatory cleanup
  - Patch 2: Adds some unit tests to check we roundtrip hashes correctly (added because in the test PR I had the `Midstate` iml wrong and it was not being caught).
  - Patch 3: Uses macro in place of `forward_hex` and `backward_hex` - needs concept review, I hacked this without understanding why the functions existed in the first place.
  - Patch 4: Does the upgrade, I've attempted to make minimal changes, so there is room for a bunch of cleanups if/when this merges.
  - Patch 5: Adds a unit test to verify that we can close #2494
  - Patch 6: Removes unnecessary feature gate from unit test.

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

Tree-SHA512: 7913d1b3079cf5ba1b0e70f5c33e091c5ef1258026c8f27bbe8a050100bbc7622b6555d560b15be3b3d90d47ce873f137a73cf2d772108d2915fb30ed129bded
2024-03-11 21:01:24 +00:00
Andrew Poelstra 24b19d7776
Merge rust-bitcoin/rust-bitcoin#2433: Split relative locktime error up
3c8edae25b Split relative locktime error up (Tobin C. Harding)

Pull request description:

  The `relative` module has a single general error type, we are moving away from this style to specific error types.

  Split the `relative::Error` up into three error structs.

  I forget the policy on public inner fields.

ACKs for top commit:
  sanket1729:
    utACK 3c8edae25b
  apoelstra:
    ACK 3c8edae25b

Tree-SHA512: f3079f81a825125f1efe54657fbba64618530b25aecaa3844902900517bf23bec26ff5399cf22f4e63e44316ebb603e8692cbaece2782ecafe09ffed3eab553c
2024-03-11 17:42:54 +00:00
Tobin C. Harding f337dec2b1
hashes: Remove unnecessary feature guard from test 2024-03-10 10:35:02 +11:00
Tobin C. Harding 0cea90d505
Test hashes honour Formatter::precision
Test that the new version of `hex` honours `Formatter::precision` for
new wrapped hash types (ie, types created with `hashes::hash_newtype`).

Fix: #2494
2024-03-10 10:35:02 +11:00
Tobin C. Harding 4bfb466bb9
Upgrade hex dependency
Upgrade to the new `hex v0.2.0` release.
2024-03-10 10:35:01 +11:00
Tobin C. Harding f0558e8eb9
Use fmt_hex_exact
Currently we have two functions for displaying forwards and backwards and
we also have `fmt_hex_exact`. I do not know why we added the functions.

In the latest version of hex we do not have the ability to construct a
`DisplayArray` type so we have to use `fmt_hex_exact`.

Make the change now, separate from the `hex` upgrade, to assist review.
2024-03-10 10:35:01 +11:00
Tobin C. Harding 6820f51408
hashes: Add fmt roundtrip tests
Different hashes output to hex strings differently depending on whether
they display backward or not but we are not currently testing that our
parsing and formatting impls both correctly handle backwards/forwards.

Add unit tests to roundtrip through a hex string, do so for one forwards
printing hash (sha256), on backwards printing hash (sha256d), and also
test that the `hash_newtype!` macro correctly passes on display backward.
2024-03-10 10:35:01 +11:00
Tobin C. Harding e302e30e7c
Import with super::* in unit test
As is customary import using a wildcard. Includes `use Hash as _` to
remove naming conflict between the trait and type.
2024-03-10 10:35:01 +11:00
Andrew Poelstra b3273cfcb8
Merge rust-bitcoin/rust-bitcoin#2562: Replaced Deprecated Function
08a9962035 Replaced Deprecated Function (Sh0g0-1758)

Pull request description:

  Changed deprecated Function with a supported one.

ACKs for top commit:
  apoelstra:
    ACK 08a9962035 yep, this seems reasonable. Thanks!
  tcharding:
    ACK 08a9962035

Tree-SHA512: fd0a55ab25cd15a3254a6c353e4906b4f4c74175d648e1f532be8b8642490e5187b96aa0aa7365771016e10a481054d3377b9074b93cd001da515177315b0d92
2024-03-09 23:10:54 +00:00
Tobin C. Harding 3c8edae25b
Split relative locktime error up
The `relative` module has a single general error type, we are moving
away from this style to specific error types.

Split the `relative::Error` up into three error structs.

Note the change of parameter `h` to `height`, and using `h` as the
pattern matched variable - this makes sense because it gives the
variable with large scope the longer name.
2024-03-10 09:57:11 +11:00
Sh0g0-1758 0d64ae6eb4
Added tests for PublicKey::from_str 2024-03-10 04:21:32 +05:30
Andrew Poelstra f69417f8bc
Merge rust-bitcoin/rust-bitcoin#2396: Add consts to Params for individual networks
3a56ecc677 Add consts to Params for individual networks (Tobin C. Harding)

Pull request description:

  Add consts to the `Params` type for the individual networks.

ACKs for top commit:
  apoelstra:
    ACK 3a56ecc677
  Kixunil:
    ACK 3a56ecc677
  sanket1729:
    ACK 3a56ecc677

Tree-SHA512: 0d265a14dd6a591a267da5381d3dcfd0d313f950dec4922f96d25349047d0c8a366c41dcdc1fc523fe4b178ec6a00b717bda25286625e222194f345cee5e7a97
2024-03-09 13:14:10 +00:00
Andrew Poelstra e58975adbc
Merge rust-bitcoin/rust-bitcoin#2555: Add ServiceFlags::P2P_V2
5818e04328 Add ServiceFlags::P2P_V2 (Ava Chow)

Pull request description:

ACKs for top commit:
  tcharding:
    ACK 5818e04328
  sanket1729:
    ACK 5818e04328
  Kixunil:
    ACK 5818e04328

Tree-SHA512: 077424c984a11af93e65873d57cdf03fe9fcc479ca270bcbe6383afeb5d2161882edf72b27ef3b5abd7a2b58efff8b95cf41e3f68221c91a3b3dc6a6b7ce9f60
2024-03-09 13:00:09 +00:00
Sh0g0-1758 08a9962035
Replaced Deprecated Function 2024-03-09 17:18:00 +05:30
Andrew Poelstra 4de3a64727
Merge rust-bitcoin/rust-bitcoin#2521: Remove link to std from rustdoc
e49a3c0bfe Remove link to std from rustdoc (Tobin C. Harding)

Pull request description:

  We can't link to `std::error::Error` in rustdoc because it breaks non-std builds. Just use backticks - this is not an optimal solution but I know no other.

  I have no clue why this is showing up now.

ACKs for top commit:
  apoelstra:
    ACK e49a3c0bfe
  sanket1729:
    ACK e49a3c0bfe

Tree-SHA512: 96c540aec59b1db7ad9b185d4ebf4e431dc2a4c9599e2e241b1948ca47995ffe88bf753bb63b01a35c9f82783231744bf8a2bdb89bfb95fbd9324172c4f9c608
2024-03-09 03:02:56 +00:00
Andrew Poelstra db01a6363f
Merge rust-bitcoin/rust-bitcoin#2516: Impl `From<core::convert::Infallible>` for Errors
b9f7462958 Implement infallible for errors (Liam Aharon)

Pull request description:

  Closes https://github.com/rust-bitcoin/rust-bitcoin/issues/1222

  Example usage
  ```rust
  use internals::impl_from_infallible;

  #[derive(Debug, Clone, PartialEq, Eq)]
  enum Error {
      SomeError(u8),
      SomeOtherError(u32, u32),
  }

  impl_from_infallible!(Error);
  ```

  Feel free to request changes :)

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

Tree-SHA512: 33576248c6c7f26f59c24827e444ccefc4a299365416f5e396bb441318c0d2f17f4d5f3bad279d201b6b358147bc977e88d6fedd02a98fe538d3192483e75bcd
2024-03-08 23:54:07 +00:00
Ava Chow 5818e04328 Add ServiceFlags::P2P_V2 2024-03-08 15:07:34 -05:00
Andrew Poelstra 9641e2d731
Merge rust-bitcoin/rust-bitcoin#2548: tweak nightly CI update
6b3c8b9f6b ci: use personal access token for daily nightly update (Andrew Poelstra)
775d0c74cd ci: change automatic CI bot committer name to something without special characters (Andrew Poelstra)
aa8655552b ci: change branch of nightly bot to not conflict with rustfmt bot (Andrew Poelstra)

Pull request description:

  Rename the bot's committer name to not have special characters, which causes some problem in tcharding's locale; also change the branch name to not overlap with the "weekly CI" job, since it's causing the two jobs to overwrite each others' PRs.

  Was part of #2531 but pulled out here to be in a branch that isn't getting clobbered every 24 hours :).

ACKs for top commit:
  tcharding:
    ACK 6b3c8b9f6b

Tree-SHA512: 2e605991132eb36543d8fb2636bc70c7cc834db6078d2cc6242c65c0f8c5fd270fc9881e6a5c28f5d87a03551fa4f1e0ad3e87c86c226db5e5b8a4c21270ef8c
2024-03-08 14:53:05 +00:00
Liam Aharon b9f7462958
Implement infallible for errors
Creates a new macro `impl_from_infallible`, and applies it to custom
error types in the codebase.

Closes #1222.
2024-03-08 16:48:34 +11:00
Andrew Poelstra 6b3c8b9f6b
ci: use personal access token for daily nightly update
The chatbot says this should cause CI to trigger on the nightly update
PRs. With the default token this does not happen because it has the
potential to cause recursive CI actions. (How this is avoided by using a
PAT, I don't know, but whatever.)
2024-03-07 14:46:16 +00:00
Andrew Poelstra 1ac7c292b1
Merge rust-bitcoin/rust-bitcoin#2546: Fix CJDNS marker byte check
ec67456172 Fix CJDNS marker byte check (Ava Chow)

Pull request description:

  Only the first byte of a CJDNS address is 0xfc, the second byte should be ignored.

  See https://github.com/hyperboria/peers for examples of CJDNS addresses.

ACKs for top commit:
  apoelstra:
    ACK ec67456172
  sanket1729:
    urACK ec67456172.
  Kixunil:
    ACK ec67456172

Tree-SHA512: 0da1054a8e997b6bf6e0aaedc40943edb6a6c7b23f660c92b34dc9395e6153e7e10b0268335a77fbcb5bb635352e1ed92839b350188fd6d33dabe558e88c00bb
2024-03-07 14:43:52 +00:00
Andrew Poelstra ea6aa99ae4
Merge rust-bitcoin/rust-bitcoin#2492: Remove the FromHexStr trait
b873a3cd44 Do infallible int from hex conversions (Tobin C. Harding)
4d762cb08c Remove the FromHexStr trait (Tobin C. Harding)
026537807f Remove mention of packed (Tobin C. Harding)

Pull request description:

  The `FromHexStr` trait is used to parse integer-like types, however we can achieve the same using inherent methods.

  Move the hex parsing functionality to inherent methods, keeping the same behaviour in regard to the `0x` prefix.

  Patch 1 is trivial preparatory cleanup.

ACKs for top commit:
  apoelstra:
    ACK b873a3cd44
  sanket1729:
    ACK b873a3cd44

Tree-SHA512: a280169b68304fcc1a531cc9ffb6914b70238efc4c2241a766105053911a373a0334b73e5ea3525c331ccb81ce98c43fea96dae77668804e608376a48d5ed8ac
2024-03-07 14:36:53 +00:00
Andrew Poelstra 0a3b457acf
Merge rust-bitcoin/rust-bitcoin#2531: Automated daily update to rustc (to nightly-2024-03-05)
de264c0c55 Automated update to Github CI to rustc nightly-2024-03-05 (Update Nightly Rustc Bot)

Pull request description:

  Automated update to Github CI workflow `rust.yml` by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action

ACKs for top commit:
  apoelstra:
    ACK de264c0c55 just gonna merge this since we have no problem with the update, just with the CI config

Tree-SHA512: 87c7054680c7fc746223573ebb6d6812bf9a80bdd4880b66ee8ecb4bff24183bcb7ae5c3b48696e5d8e96364d71fdd06a5aa3db4af26f8f13ccadb1ce87e3094
2024-03-07 14:30:50 +00:00
Andrew Poelstra 775d0c74cd
ci: change automatic CI bot committer name to something without special characters 2024-03-07 13:51:40 +00:00
Andrew Poelstra aa8655552b
ci: change branch of nightly bot to not conflict with rustfmt bot 2024-03-07 13:51:40 +00:00
Update Nightly Rustc Bot de264c0c55 Automated update to Github CI to rustc nightly-2024-03-05 2024-03-07 00:52:39 +00:00
Ava Chow ec67456172 Fix CJDNS marker byte check
Only the first byte of a CJDNS address is 0xfc, the second byte should
be ignored.
2024-03-06 13:53:09 -05:00
Andrew Poelstra 0a62e3bc37
Merge rust-bitcoin/rust-bitcoin#2542: Improve contributing doc
41f0a802af Remove assigned docs (Tobin C. Harding)
7ba63fec82 Fix typo (Tobin C. Harding)

Pull request description:

  Do two trivial improvements to the contributing doc. Yes, I am struggling to find stuff to work on because hex is clogging the pipeline :)

ACKs for top commit:
  apoelstra:
    ACK 41f0a802af

Tree-SHA512: f6a302d4b26b36b4d73aea38ae43230811ad266296706b31bbf220f8031ea4e95feaa770bc28f030495cb41762c7cb2ad6583393323c444389a503f4a2b58689
2024-03-06 17:54:12 +00:00
Tobin C. Harding 41f0a802af
Remove assigned docs
We don't assign issues, remove the incorrect section.
2024-03-06 08:53:29 +11:00
Tobin C. Harding 7ba63fec82
Fix typo 2024-03-06 08:53:14 +11:00
Andrew Poelstra 70588ccae2
Merge rust-bitcoin/rust-bitcoin#2534: fix some comments
a6adfd845c fix some comments (geekvest)

Pull request description:

ACKs for top commit:
  tcharding:
    ACK a6adfd845c
  apoelstra:
    ACK a6adfd845c Thank you! I really appreciate PRs like this.

Tree-SHA512: dce79b898d3839c2f98dff8f073ea60d185583bd0a7f82a380115eb44e77a87214bc5522435f183082c54807968445bb9f358bc796a00c5be7a7c0e3e71da97e
2024-03-04 14:48:39 +00:00
geekvest a6adfd845c fix some comments
Signed-off-by: geekvest <cuimoman@sohu.com>
2024-03-03 13:41:23 +08:00
Andrew Poelstra 32f9b1a231
ci: gate coverage analysis on whether source code changed 2024-03-01 16:13:40 +00:00
Andrew Poelstra 2203c02347
ci: gate fuzztesting on whether source code changed 2024-03-01 16:12:23 +00:00
Andrew Poelstra 09f7fc3cff
ci: gate CI workflow on source being changed 2024-03-01 16:12:23 +00:00