Commit Graph

3758 Commits

Author SHA1 Message Date
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 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
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 b93397d472
Merge rust-bitcoin/rust-bitcoin#2489: ci: pin nightly compiler, add CI cronjob to update it.
ee113aa91f ci: add daily job to update nightly rustc (Andrew Poelstra)
f82567fda4 ci: rename a couple .yml files to indicate that they're scheduled (Andrew Poelstra)
85ead84a99 ci: pin nightly in current CI (Andrew Poelstra)
c97f2ccc69 ci: require a nightly compiler rather than using +nightly (Andrew Poelstra)
e386cbfadf ci: delete *test.sh files (Andrew Poelstra)

Pull request description:

  We should be pinning our nightly compiler in CI so that
  * running CI on old release branches will continue to work (not quite -- we'd want to do the same thing for Cargo.lock, but ok, one PR at a time)
  * when CI breaks due to nightly updates (usually new Clippy lints), we can address that in a dedicated "update nightly" PR rather than having every other PR suddenly break on us

  Co-authored with ChatGPT which found several typos and suggested most of the error-handling logic.

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

Tree-SHA512: f198349291a7654f4e6f03998d02c1f7d2c7f999e0b5a89a915beb3e7c741148c2c65367b107c54c34d6669e6f0972699401ef85e76e76e5900c1fb5c844db4f
2024-03-01 15:11:19 +00:00
Andrew Poelstra 6f14a1031a
Merge rust-bitcoin/rust-bitcoin#2527: Tidy description
e3db95226a Tidy description (yancy)

Pull request description:

  I noticed `uncheced_add` looked really bad with two spaces (my mistake).  Fixed some others as well.

ACKs for top commit:
  apoelstra:
    ACK e3db95226a oops, we should have caught this. Thanks for the fix!
  tcharding:
    ACK e3db95226a

Tree-SHA512: 8a2e7f85262f17063bea6ac22855ae45d99a1559a2d30f2627ffba1108f0fd8ebd0b541b50fe746b5af2ebb013cb3e9ea432987b90f37c046120388a808c5443
2024-02-29 21:14:31 +00:00
Andrew Poelstra 83d3e5d97a
Merge rust-bitcoin/rust-bitcoin#2487: Improve amount errors
08f83898a3 Report the position of an invalid char in amount (Martin Habovstiak)
73b325aec5 Report position of the first "too precise" digit (Martin Habovstiak)
28d83551eb Improve `ParseAmountError::InputTooLarge` (Martin Habovstiak)
b7689a7d60 Split up `ParseAmountError::InvalidFormat` (Martin Habovstiak)

Pull request description:

  This contains several improvements to `PareAmountError`& co - see the individual commit messages. The changes should be pretty easy to follow.

  Note that my planned amount error work is not complete by this, so if this happens to get ACK by tomorrow, I'll wait for this to merge, if not I'll add more commits (without changing the existing ones).

  I want to get this stuff into the first `units` release.

ACKs for top commit:
  tcharding:
    ACK 08f83898a3
  apoelstra:
    ACK 08f83898a3

Tree-SHA512: aee476c4b306b940978b61f8e7ea89ce401a5736971fb3d4bd6fbfc54916695631022199cd0247a3ecb678653facbe486c89e667de26dc9e67902037cb00b23a
2024-02-29 14:41:13 +00:00
yancy e3db95226a Tidy description
Add one space between header and description body
2024-02-29 15:21:46 +01:00
Tobin C. Harding e49a3c0bfe
Remove link to std from rustdoc
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.
2024-02-29 10:16:39 +11:00
Tobin C. Harding 3a56ecc677
Add consts to Params for individual networks
Add consts to the `Params` type for the individual networks.
2024-02-29 08:54:54 +11:00
Andrew Poelstra ee113aa91f
ci: add daily job to update nightly rustc 2024-02-28 20:47:39 +00:00
Andrew Poelstra f82567fda4
ci: rename a couple .yml files to indicate that they're scheduled
A small attempt to organize the various github workflows
2024-02-28 20:47:39 +00:00
Andrew Poelstra 85ead84a99
ci: pin nightly in current CI 2024-02-28 20:47:39 +00:00
Andrew Poelstra c97f2ccc69
ci: require a nightly compiler rather than using +nightly
If we pin the version of nightly to a specific date then `cargo
+nightly` will stop working. And even locally, if you want to use a
specific version of nightly, you can't if the script is overriding your
version with "+nightly". Instead the user should set RUSTUP_TOOLCHAIN.
2024-02-28 20:47:35 +00:00
Andrew Poelstra e386cbfadf
ci: delete *test.sh files
These are not run in CI since #2353 and are likely to go out of date. If
we want a script that users can run locally then we should create a new
script that wraps our current CI.
2024-02-28 20:45:56 +00:00
Andrew Poelstra 162094322f
Merge rust-bitcoin/rust-bitcoin#2510: Trivial error cleanup
86f8043e80 Remove Error suffix from variant (Tobin C. Harding)
482c8cb7f8 Clean up error type from impls (Tobin C. Harding)

Pull request description:

  Done while working on other error code; two trivial cleanups.

  This PR gives us a place to debate the current error `From` impl format. The canonical form is, as far as I understand:

  ```rust
  impl From<FooError> for Error {
      #[inline]
      fn from(e: FooError) -> Self { Self::Foo(e) }
  }
  ```

ACKs for top commit:
  apoelstra:
    utACK 86f8043e80
  Kixunil:
    ACK 86f8043e80

Tree-SHA512: 82169baf5ec58f5fd08c7615e6f639721870a264dd93e253d3128ebee5bfe3646354fa10d38b496792bf979e03a1c7a54fb47c7a4dce9822ea7f04b84a0fbac1
2024-02-28 20:45:36 +00:00
Andrew Poelstra 1f3d05ea98
Merge rust-bitcoin/rust-bitcoin#2512: internals: Implement Default for ArrayVec
a55e78a28d internals: Implement Default for ArrayVec (Tobin C. Harding)

Pull request description:

  In an unrelated PR CI run we got the following error:

  ```
  error: you should consider adding a `Default` implementation for `ArrayVec<T, CAP>`
  ```

  I did not bother to dig any deeper since this seems like a reasonable suggestion by the compiler since we provide a `new` function that takes zero arguments.

  Add a `Default` implementation to `ArrayVec`.

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

Tree-SHA512: 85b8248ca3b6d098eeb65042d89f69fc359ef1d167c52abf321b5a6597c0a8d44cd7383668b959c2082156214a47a61478d725431718c41f23f3ca48fb274342
2024-02-28 19:06:46 +00:00
Tobin C. Harding a55e78a28d
internals: Implement Default for ArrayVec
In an unrelated PR CI run we got the following error:

```
error: you should consider adding a `Default` implementation for `ArrayVec<T, CAP>`
```

I did not bother to dig any deeper since this seems like a reasonable
suggestion by the compiler since we provide a `new` function that takes
zero arguments.

Add a `Default` implementation to `ArrayVec`.
2024-02-28 13:19:43 +11:00
Tobin C. Harding 86f8043e80
Remove Error suffix from variant
We do not use a suffix on error variants, remove it.
2024-02-28 10:48:46 +11:00
Tobin C. Harding 482c8cb7f8
Clean up error type from impls
Make the `From` impls conform to our convention.

Refactor only, no logic changes.
2024-02-28 10:48:46 +11:00
Andrew Poelstra 36aa627d83
Merge rust-bitcoin/rust-bitcoin#2508: Add `NetworkValidationError`
7e2a81d03b Remove unused address::Error type (Tobin C. Harding)
a92dc9c35c Add NetworkValidationError (Tobin C. Harding)

Pull request description:

  Replaces #2502 because there is going  to be way too much arguing on this to bother a newer contributor with.

  This PR takes into consideration #2507 but does not improve the issue, it also does not make it worse. I propose to do this and then consider #2507 since this is a step forwards IMO.

  Remove the `address::Error` because its not good. Add a `NetworkValidationError` and return it from `require_network` - leaving the door open for resolving Kix's issue in 2507.

ACKs for top commit:
  Kixunil:
    ACK 7e2a81d03b
  apoelstra:
    ACK 7e2a81d03b

Tree-SHA512: 0a220dbec1457f35e3d95f32399f258e65c0477e8b4d14dbe2dfad0a44966ab0339d4c2d9828da318bf131db45cecb2447c0e32d5669a5f4c4739b90c83d3c0d
2024-02-27 14:35:42 +00:00
Tobin C. Harding 7e2a81d03b
Remove unused address::Error type 2024-02-27 11:10:03 +11:00
Tobin C. Harding a92dc9c35c
Add NetworkValidationError
The `require_network` function can fail in one way only, add a specific
error for the failure.
2024-02-27 11:08:38 +11:00
Andrew Poelstra 42e8f537e6
Merge rust-bitcoin/rust-bitcoin#2504: base58: Use pub extern crate instead of module
9d688396c9 base58: Use pub extern crate instead of module (Tobin C. Harding)

Pull request description:

  We don't add any implementations to the `base58` types so we can just `pub extern` the crate instead of using a module and re-exporting.

ACKs for top commit:
  Kixunil:
    ACK 9d688396c9
  apoelstra:
    ACK 9d688396c9

Tree-SHA512: 521af0fd1ae365a6d060dd3c38fc18c1fb3a6c46adb7cba64e53128c7a898c766bcc603078b4cb8a3672df96559633495b23203a33147b5b4959b0c690ab7451
2024-02-27 00:04:00 +00:00
Tobin C. Harding b873a3cd44
Do infallible int from hex conversions
We have three integer wrapping types that can be created from hex
strings where the conversion from an integer is infallible:

- `absolute::LockTime`
- `Sequence`
- `CompactTarget`

We would like to improve our handling of the two prefix characters (eg
0x) by making it explicit.

- Modify the inherent `from_hex` method on each type to error if the
input string does not contain a prefix.

- Add an additional inherent method on each type `from_unprefixed_hex`
that errors if the input string does contain a prefix.

This patch does not touch the wrapper types that cannot be infallibly
constructed from an integer (i.e. absolute `Height` and `Time`).
2024-02-27 10:40:52 +11:00
Tobin C. Harding 4d762cb08c
Remove the FromHexStr trait
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.
2024-02-27 10:09:20 +11:00
Tobin C. Harding 026537807f
Remove mention of packed
We removed the `PackedLockTime`, remove all mentions of the word packed.
2024-02-27 10:09:20 +11:00
Andrew Poelstra 87f4091a65
Merge rust-bitcoin/rust-bitcoin#2506: Update bech32 dependency
4e557fa4e6 Update bech32 dependency (Tobin C. Harding)

Pull request description:

  Update `bech32` to the newly released version `0.11.0`.

ACKs for top commit:
  apoelstra:
    ACK 4e557fa4e6
  Kixunil:
    ACK 4e557fa4e6

Tree-SHA512: bbf19876553b7b27191610a68da60a7d1c5246646c0109dd9bc4909259244ca79f624e0c8a6fc205d93fcdacfd3a82201cda6cf09e0c233cceb10e25b3133871
2024-02-26 22:57:49 +00:00
Tobin C. Harding 4e557fa4e6
Update bech32 dependency
Update `bech32` to the newly released version `0.11.0`.
2024-02-26 15:31:51 +11:00
Tobin C. Harding 9d688396c9
base58: Use pub extern crate instead of module
We don't add any implementations to the `base58` types so we can just
`pub extern` the crate instead of using a module and re-exporting.
2024-02-26 08:48:30 +11:00
Andrew Poelstra d85817b880
Merge rust-bitcoin/rust-bitcoin#2497: Add the `FromScriptError` for handling errors in `address`
c2d658ac05 Add `P2shError` for handling errors related to P2sh (harshit933)
5182a8d7a8 Remove unused variants from `Address::Error` (harshit933)
05b24946eb Add the `FromScriptError` for handling errors in `address` (harshit933)

Pull request description:

  This commit adds the `FromScriptError` struct to handle the errors while generating address from any script. It includes :
  - Unrecognized script error.
  - Witness Program error.
  - Witness Version error.

ACKs for top commit:
  tcharding:
    ACK c2d658ac05
  apoelstra:
    ACK c2d658ac05

Tree-SHA512: 891eed787129aaf1b664cc16d325178d5d2f77cc41a0543a3d9d1a5af1b58188daece1f6a653bdc6b76b82db0490a39e9bba7fc090e3727d15ee9b8977733698
2024-02-24 15:59:45 +00:00