Commit Graph

1139 Commits

Author SHA1 Message Date
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 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
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
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
Ava Chow 5818e04328 Add ServiceFlags::P2P_V2 2024-03-08 15:07:34 -05: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 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
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
geekvest a6adfd845c fix some comments
Signed-off-by: geekvest <cuimoman@sohu.com>
2024-03-03 13:41:23 +08: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 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
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
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
Andrew Poelstra 94938ea247
Merge rust-bitcoin/rust-bitcoin#2446: Make constructors const
ac88bc03fd Make constructors const (Tobin C. Harding)

Pull request description:

  Audit the codebase for any function that starts with `/// Creates` and see if we can make it const. Inline them at the same time.

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

Tree-SHA512: 0c71e38018e74b3ce1aae871fc6208b87655a0970ae6cca7a538b9f896c95542c6905eb4d7e02539847e88d8a22a873039a5734130c2a46efb4d1b2b9ffd9f4a
2024-02-24 15:48:46 +00:00
Tobin C. Harding ac88bc03fd
Make constructors const
Audit the codebase for any function that starts with `/// Creates` and
see if we can make it const. Inline them at the same time.
2024-02-24 06:04:41 +11:00
harshit933 c2d658ac05 Add `P2shError` for handling errors related to P2sh
Added a new `P2shError` struct for handling errors emmited while
generating addresses from P2sh scripts.
2024-02-23 19:33:44 +05:30
Tobin C. Harding aa8ba118ae
Add a new base58 crate
Add a new `base58` crate to the workspace and move the `bitcoin::base58`
module to it.

Done as part of crate smashing, specifically so that we can make `bip32`
into a separate crate.
2024-02-23 12:54:24 +11:00
harshit933 5182a8d7a8 Remove unused variants from `Address::Error` 2024-02-23 03:36:35 +05:30
harshit933 05b24946eb Add the `FromScriptError` for handling errors in `address`
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.
2024-02-23 02:21:11 +05:30
Tobin C. Harding 1ee887a2fc
Make from_hex inherent for byte-like types
Byte like types naturally display in hex, therefore they should have
an inherent method `from_hex` and not implement `FromHex`.
2024-02-22 09:16:31 +11:00
Tobin C. Harding 9187bf3a65
Fix new nightly warnings/errors
The latest nightly toolchain introduced a whole bunch of new warnings
and errors, mostly to do with import statements - fix them all.
2024-02-21 14:13:49 +11:00
Tobin C. Harding cf602583bd
io: Bump version to 0.1.1
We attempted to release with the current 0.1.0 version forgetting that
we had previously released an empty crate with that version to reserve
the name on crates.io.

Bump the version to 0.1.1 and release the actual code.
2024-02-18 09:39:28 +11:00
conduition 1384330029
taproot: add TapNodeHash getter method on TapTree and NodeInfo
Fixes a gap in the API of the taproot module. Callers can now use
TapTree::root_hash or NodeInfo::node_hash to extract the taproot
tree merkle root hash for fast validation without any ECC overhead.
2024-02-12 23:47:33 +00:00
Andrew Poelstra 9bdac92e1a
Merge rust-bitcoin/rust-bitcoin#2464: Remove broken kani test
7e1ba7895f Remove broken kani test (Tobin C. Harding)

Pull request description:

  This test is failing. I do not want to dive back into kani right now, just remove it.

  This is what I originally did in #2454 but changed directions and tried to fix it. Running kani test takes ages and I'd need to dig back to refresh my memory to work with kani. I don't have the motivation to do that at the moment. Just remove the test.

  FTR I added the test recently without fulling thinking it through and it has never passed so we are not loosing any coverage. Doing this was the original mistake I should not have made.

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

Tree-SHA512: cb76807173b637be9d5ce790b015e711ca76add95ce0f0acfdc56947c075f57ea89774c09c4314dbc89086dcf7a8e21053552bfae805fd5dc9c91051cd53c468
2024-02-12 14:23:33 +00:00
Tobin C. Harding 7e1ba7895f
Remove broken kani test
This test is failing. I do not want to dive back into kani right now,
just remove it.
2024-02-11 06:58:50 +11:00
yancy 1d13020129 test: Add conditional check for debug_assertions
Adding debug_assertions where the test case panics allows the test suite
to run in release mode successfully.
2024-02-10 12:37:50 +01:00
Andrew Poelstra 53461f71c9
Merge rust-bitcoin/rust-bitcoin#2457: Inline private ScriptBuf::p2wpkh function
10cf51c4c5 Inline private ScriptBuf::p2wpkh function (Tobin C. Harding)

Pull request description:

  This function is a bit unclear and is only called once, just inline it.

  Refactor only, no logic changes.

ACKs for top commit:
  apoelstra:
    ACK 10cf51c4c5
  Kixunil:
    ACK 10cf51c4c5

Tree-SHA512: 3907923f2258089a5fc1cc1e1d0b34e99457d69a5822cefa7bf90405d7ac05d570fb2855f62e2b5b4b871485e349e8dc09eb8f14c0676a8bdd70593e345b9b41
2024-02-08 16:20:17 +00:00
Andrew Poelstra 241e78934c
Merge rust-bitcoin/rust-bitcoin#2335: Improve error handling in errors emmited by `keys`
d3d5ee1047 Improve error handling in errors emmited by `keys` (harshit933)

Pull request description:

  For now I have tried to group those functions which can produce more than one error and changed the functions which were  generating single error from `Key::Error` to the respective error. Let me know if this needs to be changed.

  Also in `psbt/error.rs` I have changed the `InvalidPublicKey(crate::crypto:🔑:Error)` to `InvalidPublicKey(crate::crypto:🔑:FromSliceError)`. What should be done here?

  Changes -
  - in `from_slice` changed the `error` to `FromSliceError`.
  - in `verify` changed to `secp256k1::Error` as it can return only one error.
  - in `from_str` changed to `FromSliceError`.
  - in `CompressedPublicKey` changed `verify` from `Error` to `secp236k1::Error` as it only returns one error.
  - introduces CompressedPublicKeyError
  - Removes impl from `bip32.rs`

  Potential fix #2291

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

Tree-SHA512: 21681bbf87c37eb0caaefe4b356a8a5e1d9b17de3207a0c9294de66b367ab348a7dda1916eb866fe4382e852af14ccab7b9f25a279291cd5beb56bb60b2523c2
2024-02-07 20:01:10 +00:00
Andrew Poelstra 94c6526dbe
Merge rust-bitcoin/rust-bitcoin#2451: Remove m prefix requirement
ccbd09d5fb Remove unnecessary m/ prefix requirement (josibake)

Pull request description:

  `m` in BIP0032 is a variable, not a constant. Requiring it as a constant here is confusing and can lead to erroneous conclusions if using this library as a means of understanding BIP0032.

  Fixes #2449

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

Tree-SHA512: b641679f958f20a51c1890b23bbaa0153716802d6180dfd1f649e104f291c5a99143e02b75d292b22254201b28e5c53a04ecd7b6a88ff6f964073106419c5ec1
2024-02-07 19:52:16 +00:00
Andrew Poelstra 48dd9842ef
Merge rust-bitcoin/rust-bitcoin#2454: Remove broken kani test
47569302fc Fix broken kani test (Tobin C. Harding)

Pull request description:

  Recently we added a kani test that doesn't work because of `debug_assert` calls in ops traits.

  Instead of opening the can of worms that is correct panic behaviour in ops lets just remove the test.

ACKs for top commit:
  Kixunil:
    ACK 47569302fc
  apoelstra:
    ACK 47569302fc

Tree-SHA512: f4a862d99173c1502e70fe4c2b9085a1f23dd4501f2ae25dc8a92e3edda7804b42b0580ef32fef2a3d5ea0d98e16b6f0fdba456cf4f0926c5b051ec8a6e54c78
2024-02-07 15:42:24 +00:00
josibake ccbd09d5fb
Remove unnecessary m/ prefix requirement
In BIP0032, m is used as a variable for the root extended key. It is not
meant to be used as a constant prefix when serializing paths.

Update the DerivationPath parser to no longer require the m prefix.
Remove the m prefix from the unit tests and the bip32, ecdsa-psbt,
and taproot-psbt examples.

close #2449
2024-02-07 12:17:45 +01:00
Tobin C. Harding 10cf51c4c5
Inline private ScriptBuf::p2wpkh function
This function is a bit unclear and is only called once, just inline it.

Refactor only, no logic changes.
2024-02-07 10:09:02 +11:00