Commit Graph

5346 Commits

Author SHA1 Message Date
Tobin C. Harding 9a7b1c232b
Wrap the bech32 decoding error
We do not want `bech32` to appear in the public API of the `address`
module in case `bech32` does not stabalize before the soon-to-be-created
`address` crates does.

We already had a go at removing it but forgot one error variant - wrap
the variant in a new type with a private inner bech32 error field.
2024-10-27 08:29:22 +11:00
Tobin C. Harding 5a736edaaa
hashes: Move serde_macros code into macros
Roll the `serde_macros` module into `macros`, requires making `macros`
public but since it explicitly holds public macros this is reasonable.

Keep the original module and deprecate it.
2024-10-27 07:07:01 +11:00
Tobin C. Harding aaa78a3a09
hashes: Rename util to macros
The `utils` module holds public macros, call it `macros` instead.
2024-10-27 07:03:50 +11:00
Tobin C. Harding 34e638d40c
hashes: Separate private and public modules
The private and public modules are already grouped, add a line of
whitespace to make it _even_ more clear. Trivial I know, this patch got
smaller during rebase.
2024-10-27 07:03:50 +11:00
Tobin C. Harding f2e1a4b16c
bitcoin: Add some upgrade notes
While upgrading `miniscript` to use tip of master I made some notes to
help users upgrade. Just throw them in the changelog file or now.
2024-10-27 07:02:30 +11:00
Tobin C. Harding 66da2266e2
Explicitly re-export stuff from crates down the stack
Up until recently we were using wildcard re-exports for types moved to
`units` and `primitives`. We have decided against doing so in favour of
explicit re-exports.

Audit `units` and `primitives` using `git grep 'pub enum'` (and
`struct`) and explicitly re-export all types.

Remove all wildcards except for the re-exports from `opcodes`, there are
too many opcodes, explicitly re-exporting them does not aid clarity.
2024-10-27 06:45:58 +11:00
merge-script b11bd9a6b5
Merge rust-bitcoin/rust-bitcoin#3512: Manually implement `compute_txid` and `compute_wtxid`
5633b10f5c Manually implement compute_txid and compute_wtxid (Tobin C. Harding)

Pull request description:

  We would like to move the `Transaction` type over to `primitives` including the `compute_txid` and `compute_wtxid` functions however currently the implementations, as expected, use `Encodable`.

  Manually implement `Encodable` by hashing all the fields in the correct order.

  Note we have unit tests already that check the output string of the txid returned so these act as regression tests for this patch.

ACKs for top commit:
  apoelstra:
    ACK 5633b10f5c826e0b2ac47dd85f697f12710898d7; successfully ran local tests; nice

Tree-SHA512: 66a955d3d896801cfefe0388aade3a31f22fac5b6da7b996be61f374b93772487c0c203320aaf5165fcef26874564bce375ecb364175b0a01c3008b7ea8db981
2024-10-26 15:05:58 +00:00
Update Stable Rustc Bot b47aff60ef Automated update to Github CI to rustc stable-1.82.0 2024-10-25 00:55:35 +00:00
merge-script 856503ddc1
Merge rust-bitcoin/rust-bitcoin#3514: Remove unnecessary lifetimes
b22db6268c Remove unnecessary lifetimes (Jamil Lambert, PhD)

Pull request description:

  New lint warnings from a recent nightly toolchain in #3467 show some explicit lifetimes that can be omitted.

  The unnecessary lifetimes have been removed.

ACKs for top commit:
  storopoli:
    ACK b22db6268c
  apoelstra:
    ACK b22db6268c609af5bc739168de4fde4a6e82fc43; successfully ran local tests; will one-ACK merge

Tree-SHA512: fa7057a3f2d8d84dfc21baf9784773fa331d808ed7e5153847fba455bf18d1daa1e95661e887fad74e21c953dc01655da6c2797e1fc0d4f546e4852ef1d99ad0
2024-10-24 18:21:42 +00:00
merge-script 6425f2af49
Merge rust-bitcoin/rust-bitcoin#3487: Move `TxIn` and `TxOut` to `primitives`
003dc9cf4d Move TxOut to primitives (Tobin C. Harding)
4d37d7efc6 Move TxIn to primitives (Tobin C. Harding)
ce0d517383 Use explicit re-export of transaction types (Tobin C. Harding)
4c5dba82f4 Introduce TxInExt trait (Tobin C. Harding)
b7e6c698f8 Split the TxIn impl block in two (Tobin C. Harding)
265589d93d Make TxIn::BASE_WEIGHT a file level const (Tobin C. Harding)

Pull request description:

  Turn the crank; move `TxIn` and `TxOut` to `primitives`.

ACKs for top commit:
  apoelstra:
    ACK 003dc9cf4d80c2a6d614de1e3a1c7c4b1d5372e0; successfully ran local tests

Tree-SHA512: fa9ffb7677999f0e07231d4603db5c005d4dc1c1b9d1faa8df9e90bd8a8088f853c3e0cd2997ca724f6a4e13941afedf5877ba95ac70f31e7b3438b34c205034
2024-10-24 13:28:14 +00:00
Jamil Lambert, PhD b22db6268c
Remove unnecessary lifetimes 2024-10-24 14:08:20 +01:00
Tobin C. Harding 5633b10f5c
Manually implement compute_txid and compute_wtxid
We would like to move the `Transaction` type over to `primitives`
including the `compute_txid` and `compute_wtxid` functions however
currently the implementations, as expected, use `Encodable`.

Manually implement `Encodable` by hashing all the fields in the correct
order.

Note we have unit tests already that check the output string of the txid
returned so these act as regression tests for this patch.
2024-10-24 13:33:40 +11:00
merge-script dc443e5b3d
Merge rust-bitcoin/rust-bitcoin#3504: Remove unnecessary lifetimes
ddde3162ff Remove unnecessary lifetimes (Tobin C. Harding)

Pull request description:

  Linter with new nightly toolchain finds another lifetime that can be elided, do so.

ACKs for top commit:
  storopoli:
    ACK ddde3162ff
  apoelstra:
    ACK ddde3162ff8417531920aa16e12d7ac73bc5207d; successfully ran local tests; not bad, just one

Tree-SHA512: cc7fde0f586ba0ca7435933a80d0409b9220df0e65d7b71b89a691dbbfaea19117cae65dc1ea61784640a77a62f0794c6c3e65bca203a62ca55731eb5d1a9fd4
2024-10-23 22:50:19 +00:00
Tobin C. Harding 003dc9cf4d
Move TxOut to primitives
The `TxOut` has all public fields; move the `TxOut` to `primitives`.
2024-10-24 09:04:12 +11:00
Tobin C. Harding 4d37d7efc6
Move TxIn to primitives
The `TxIn` has all public fields; move the `TxIn` to `primitives`.
2024-10-24 09:04:12 +11:00
Tobin C. Harding ce0d517383
Use explicit re-export of transaction types
While moving transaction types to `primitives` I mistakenly used a
wildcard when re-exporting, make the re-exports explicit.
2024-10-24 09:04:12 +11:00
Tobin C. Harding 4c5dba82f4
Introduce TxInExt trait
In preparation for moving the `TxIn` over to `primitives` introduce an
extension trait.
2024-10-24 09:04:12 +11:00
Tobin C. Harding b7e6c698f8
Split the TxIn impl block in two
In preparation for moving the `TxIn` over to `primitives` split the impl
block into two parts, one to stay one to go.

Internal change only.
2024-10-24 09:04:12 +11:00
Tobin C. Harding 265589d93d
Make TxIn::BASE_WEIGHT a file level const
In preparation for moving the `TxIn` over to `primitives` make the
private `TxIn::BASE_WEIGHT` associated const into a file-scoped constant
because the other alternative is to make it public.
2024-10-24 09:04:11 +11:00
merge-script 456bbf11d1
Merge rust-bitcoin/rust-bitcoin#3505: CI: Hobble WASM job
5ec17a2ee8 CI: Hobble WASM job (Tobin C. Harding)

Pull request description:

  The WASM job is not working. `wasm-pack build` works fine but `wasm-pack test` doesn't compile.

  Comment out the line that runs `wasm-pack test`.

ACKs for top commit:
  apoelstra:
    ACK 5ec17a2ee8c963d182777a9661b1bab786956bd4; successfully ran local tests; LGTM

Tree-SHA512: 5ea88bd99f625a8c669dc1dec02486dd549e9ac83d7670c6c7b3b25c86de3fc9a8dbc959dc39de92305dd5e254e0b8ed9424cae5e5941b66a6476ee433009fdd
2024-10-23 19:16:40 +00:00
merge-script 2f40c30f73
Merge rust-bitcoin/rust-bitcoin#3481: Decode an address string based on prefix
9c2ac46902 Split up ParseError (Jamil Lambert, PhD)
3d994f7bdb Decode an address string based on prefix (Jamil Lambert, PhD)

Pull request description:

  When a decoding error occurs for a bech32 address string the error is discarded and the same address string is attempted to be decoded as base58.  This then incorrectly returns a base58 error.

  Check the string prefix and decode as bech32 or base58 and return the relevant error.  If the prefix is unknown return an `UnknownHrpError`.

  Close #3044

ACKs for top commit:
  tcharding:
    ACK 9c2ac46902
  apoelstra:
    ACK 9c2ac46902ae2e6f2513ee125ea5c89953ac89a2; successfully ran local tests

Tree-SHA512: 40c94328828af86723e84d4196e8949430fb9a15efd8865c18cb5048fe59b8a2514d97f4809d828353b78c010544a8a6d4589a8c9c7fbd75d9d0ecceb3151e8f
2024-10-23 16:59:57 +00:00
merge-script c7fbebbad8
Merge rust-bitcoin/rust-bitcoin#3486: Remove the I/O error variant when `consensus::deserialize`'ing
bbffa3db43 Remove the IO error from DecodeError (Tobin C. Harding)
713196be0d Return DeserError from encode::deserialize (Tobin C. Harding)
33566ac58c Split encode::Error into two parts (Tobin C. Harding)
b04142c745 Add encode::Error::MissingData variant (Tobin C. Harding)
5a42ef2850 Do not manually map IO error (Tobin C. Harding)
efd7f9f06c Add error constructor parse_failed_error (Tobin C. Harding)
ebfef3f114 Return generic error as Some (Tobin C. Harding)
a6254212dc Move consensus error code to submodule (Tobin C. Harding)

Pull request description:

  The `consensus::deserialize` and `consensus::deserilaize_partial` functions should not return an I/O error. Doing so causes various other error types to include an `io::Error` and the `io::Error` is an annoying type to work with.

  This PR is a bunch of steps, and it took me a good while with quite a bit of backtracking to get here. As such you may want to review the final state before looking at each patch.

  The `consensus` errors can be further cleaned up but I'd prefer not to spend more time on this unless it has some chance of merging.

ACKs for top commit:
  apoelstra:
    ACK bbffa3db43802b30d23259c0372f16a877a0ef8b; successfully ran local tests

Tree-SHA512: 522fdd29638a214cb7fcee29dd3b9f5c846f041fba087a56a91b83e6d85f033cbed95f659dc4321cd4596943ff233bdd184cdfbfcc787fe89172bb93aa4ab186
2024-10-23 14:25:55 +00:00
merge-script 9f598063c3
Merge rust-bitcoin/rust-bitcoin#3500: Move `taproot` hash types to `primitives`
1b521dce99 Move taproot hash types to primitives (Tobin C. Harding)
24e944ed82 Introduce taproot hash type extension traits (Tobin C. Harding)
c30ef617fb Move combine_node_hashes out of TapNodeHash (Tobin C. Harding)

Pull request description:

  Move the three `taproot` hash types and their associated tags over to the `primitives` crate.

  First two patches are preparation, third on is the move - this one is a no-brainer.

ACKs for top commit:
  apoelstra:
    ACK 1b521dce99db1900326eec29c47445f522f94ee6; successfully ran local tests; nice! will one-ACK merge

Tree-SHA512: 076f017dad6263144ac1a7e0e0251cfb5f1790898ec1d344107471875fc73157116c04f698ff8a02f1b17dee5306b5054d10c990abc84d8098de9ff74f8fc302
2024-10-23 02:58:26 +00:00
merge-script 79ff70255b
Merge rust-bitcoin/rust-bitcoin#3477: Polish the `hashes` crate
1cb24c1f15 hashes:: Polish crate level rustdocs (Tobin C. Harding)
98691186dc hashes: Move engine functions (Tobin C. Harding)
12f261c009 hashes: Re-order from_byte_array (Tobin C. Harding)
c11587d60d hashes: Rename hash_type macro (Tobin C. Harding)
62617cf9ac hashes: Move from_engine function to other macro (Tobin C. Harding)
bb7dd2c479 hashes: Move DISPLAY_BACKWARD to top of impl block (Tobin C. Harding)
71013afe07 hashes: Put attribute under doc (Tobin C. Harding)

Pull request description:

  `hashes 1.0.0` can't be far away, here is a quick polish (done while I waited for my car to get fixed).

  Everything here is internal except stuff to docs. Note please I claim "internal change only" in a bunch of patches that do code moves but these effect the docs build because order is preserved in some instances.

ACKs for top commit:
  apoelstra:
    ACK 1cb24c1f150bc2d65d0be439f2005f41d95ad23c; successfully ran local tests

Tree-SHA512: 430c451afab8fc92fb4596bf2d4b36c086333fe72b3fe5858925b75597641b8c4f5e49f7643888fa19b675d3070ce9a3606623cd56bdba6cfc59e459fbdda440
2024-10-22 22:24:49 +00:00
Tobin C. Harding 5ec17a2ee8
CI: Hobble WASM job
The WASM job is not working. `wasm-pack build` works fine but `wasm-pack
test` doesn't compile.

Comment out the line that runs `wasm-pack test`.
2024-10-23 06:59:51 +11:00
Tobin C. Harding ddde3162ff
Remove unnecessary lifetimes
Linter with new nightly toolchain finds another lifetime that can be
elided, do so.
2024-10-23 06:55:25 +11:00
Tobin C. Harding 1b521dce99
Move taproot hash types to primitives
Move the three `taproot` hash types and their associated tags over to
the `primitives` crate.
2024-10-22 13:50:44 +11:00
Tobin C. Harding 24e944ed82
Introduce taproot hash type extension traits
Introduce three extension traits for the taproot hash types. All logic
for the hash types is now within the extension traits.
2024-10-22 13:50:44 +11:00
Tobin C. Harding c30ef617fb
Move combine_node_hashes out of TapNodeHash
Currently `combine_node_hashes` is an associated function, it is also
private. It is called from within other methods of the `TapNodeHash`.

In preparation for moving the `TapNodeHash` to `primitives` while
leaving all the methods in `bitcoin` in an extension trait; move the
associated function out of `TapNodeHash` and make it a stand alone
private function.
2024-10-22 13:50:43 +11:00
merge-script b4f52ac87a
Merge rust-bitcoin/rust-bitcoin#3498: Seal extension traits
e7d326f071 Seal extension traits (Tobin C. Harding)

Pull request description:

  The extension traits are temporary just while we try to stabalize `primitives`, they are not intended to be implemented by downstream.

  Seal the extension traits so that downstream crates cannot implement them.

  Fix: #3231

ACKs for top commit:
  apoelstra:
    ACK e7d326f071a368389f087ddb10ee9bbf3552c33a; successfully ran local tests; thanks! I know this is tedious and annoying

Tree-SHA512: 365979aeabb7941b9c8fa526f71aaadae3ab1cdd6a39e992c5eea2c1057b4b7c2b3a846ffd96a7eab47b9ad4e3e4de4fb141c24c62747e5cee45c74f52f9a172
2024-10-22 02:19:02 +00:00
Tobin C. Harding bbffa3db43
Remove the IO error from DecodeError
The `DecodeError` (badly named) consensus decodes an object from an
iterator that implements `Read`. The `Read` impl never returns a real IO
error, we use the `io::Error` to temporarily wrap the error returned by
the inner iterator and unwrap it in `IterReader::decode`. As such there
is no reason for the `DecodeError` to hold an `encode::Error`, it can
hold an `encode::ParseError`.

The value of this change is easily seen in the removal of calls to
`unreachable`.
2024-10-22 12:39:07 +11:00
Tobin C. Harding 713196be0d
Return DeserError from encode::deserialize
The `encode::deserialize` function never returns an I/O error. Add a new
error type that expresses this.
2024-10-22 12:04:40 +11:00
Tobin C. Harding 33566ac58c
Split encode::Error into two parts
The `consensus::encode::Error` contains an IO error but reading from a
buffer only ever errors for EOF. We converted all instances of EOF to
`MissingData` already so now we can split the IO error apart from the
actual encoding errors variants.
2024-10-22 11:58:43 +11:00
Tobin C. Harding b04142c745
Add encode::Error::MissingData variant
The `io::Error` is troublesome because it contains a bunch of stuff that
never happens when reading from a buffer. However the EOF variant can
occur if the buffer is too short. As an initial step towards reducing
usage of the `io::Error` add a `MissingData` variant to the
`encode::Error` and when converting from an IO error map to
`MissingData` if EOF is encountered.
2024-10-22 11:53:41 +11:00
Tobin C. Harding 5a42ef2850
Do not manually map IO error
We have a `From` impl for IO error but we are manually mapping.

Done in preparation for patching the `From` impl.
2024-10-22 11:51:20 +11:00
Tobin C. Harding efd7f9f06c
Add error constructor parse_failed_error
The `encode::Error::ParseFailed` variant holds an inner string, this is
suboptimal.

In an effort to patch the `encode::Error` while mimizing the diffs
required add a helper function that creates the variant. The benefit is
that later patches that effect this variant will only need to update the
constructor function and not every call site.

Internal change only.
2024-10-22 11:47:34 +11:00
Tobin C. Harding ebfef3f114
Return generic error as Some
The `std::error::Error` impl for `consensus::DecodeError` should return
the inner generic error.
2024-10-22 11:47:34 +11:00
Tobin C. Harding a6254212dc
Move consensus error code to submodule
The `consensus` module has a bunch of error types, move them all to a
separate module. Add re-exports so the types are still available at the
same place they were. Make the `error` module private and re-export all
errors from the `consensus` module root.
2024-10-22 11:47:34 +11:00
merge-script 7e5911923f
Merge rust-bitcoin/rust-bitcoin#3284: Add a few unit tests for Sequence
4a8e2c3704 Add tests for sequence (Shing Him Ng)

Pull request description:

  Add a few unit tests for Sequence

ACKs for top commit:
  apoelstra:
    ACK 4a8e2c3704 successfully ran local tests; sure
  tcharding:
    ACK 4a8e2c3704

Tree-SHA512: fb793a6a94a9d3f1522357f98a73a87618ba70776875b3ce051631970ca6c15998401dece47e426f7040770b8d24ee1b72f206d3164b7ca76492e12e86116677
2024-10-21 23:58:55 +00:00
merge-script 8de5432de9
Merge rust-bitcoin/rust-bitcoin#3496: Expose units::amount::ParseError
9e607bbbe2 Expose units::amount::ParseError (Casey Rodarmor)

Pull request description:

  Fixes #3490.

ACKs for top commit:
  tcharding:
    ACK 9e607bbbe2
  apoelstra:
    ACK 9e607bbbe2738340f04dae4fab6b35e642e98f38; successfully ran local tests

Tree-SHA512: 70e4e9fae82d5aa2467be1e703d219e64fc3ab24158f109b2f4e73fb4e84d7dabcdc8d75c2363284aeb1736b023f64e8f440a2965c3734241d7748af1ad7da22
2024-10-21 20:27:32 +00:00
Jamil Lambert, PhD 9c2ac46902
Split up ParseError
ParseError is too general and the functions returning it do not have an
error path for all variants.

Split out the Bech32 and Base58 related errors into their own enums.
2024-10-21 20:55:42 +01:00
merge-script f981534be6
Merge rust-bitcoin/rust-bitcoin#3493: Make `Amount::to_sat` and `SignedAmount::to_sat` const
1d2cfb036c Make `Amount::to_sat` and `SignedAmount::to_sat` const (Casey Rodarmor)

Pull request description:

  Fixes #3491.

ACKs for top commit:
  tcharding:
    ACK 1d2cfb036c
  apoelstra:
    ACK 1d2cfb036cff1088420e42a817b4a672e65e5d4b; successfully ran local tests

Tree-SHA512: fc88202176afefb7ff75ad362cb9f139523db0a3d57821e5078af9fead9276b36fa7c915f197c45d4097c73e6bac6a1e72c012007ba9789d92a5514ab1d30f32
2024-10-21 19:20:43 +00:00
Tobin C. Harding e7d326f071
Seal extension traits
The extension traits are temporary just while we try to stabalize
`primitives`, they are not intended to be implemented by downstream.

Seal the extension traits so that downstream crates cannot implement
them.

Fix: #3231
2024-10-21 14:51:23 +11:00
merge-script 98548548d6
Merge rust-bitcoin/rust-bitcoin#3495: Automated nightly rustfmt (2024-10-20)
2a08b29232 2024-10-20 automated rustfmt nightly (Fmt Bot)

Pull request description:

  Automated nightly `rustfmt` changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action

ACKs for top commit:
  tcharding:
    ACK 2a08b29232

Tree-SHA512: f44713f322724cc7e8823efaa5619197478a0927cd11806777ea9ec4d87a8d0fddf25c3bd58e0a23dc8f60baa18c80a63db2b56196523f616943c6e1497060f6
2024-10-21 13:47:51 +11:00
merge-script bceb5b44d8
Merge rust-bitcoin/rust-bitcoin#3492: Automated weekly update to cargo-semver-checks (to 0.36.0)
8fffdc8a52 Automated update to Github CI to cargo-semver-checks version-0.36.0 (Update cargo-semver-checks Bot)

Pull request description:

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

ACKs for top commit:
  tcharding:
    ACK 8fffdc8a52

Tree-SHA512: 9f9056c0efdd68a58fc5a2e96628e9327820868a880a2126c98a17ece9858064dc176b565325cfc4daa29f11dc1911c929eb92ebd2768115706be278c0d4540a
2024-10-21 09:43:04 +11:00
Casey Rodarmor 9e607bbbe2 Expose units::amount::ParseError 2024-10-20 11:25:46 -07:00
Fmt Bot 2a08b29232 2024-10-20 automated rustfmt nightly 2024-10-20 01:21:52 +00:00
Casey Rodarmor 1d2cfb036c Make `Amount::to_sat` and `SignedAmount::to_sat` const 2024-10-19 11:49:14 -07:00
Update cargo-semver-checks Bot 8fffdc8a52 Automated update to Github CI to cargo-semver-checks version-0.36.0 2024-10-19 01:04:35 +00:00
merge-script 51d503730d
Merge rust-bitcoin/rust-bitcoin#3406: Move `Witness` to `primitives`
c1eccfde25 Move Witness to primitives (Tobin C. Harding)
6ce76cd7c8 Add unstable constructor to Witness (Tobin C. Harding)

Pull request description:

  Patch 1 introduces a new policy to the codebase, we use `foo__unstable` for public unstable functions and there are zero semver guarantees if you call these functions.

  Patch 2 does the move.

  Close #3406

ACKs for top commit:
  apoelstra:
    ACK c1eccfde25fd4c2b19e7ec6759352b46ac246113; successfully ran local tests

Tree-SHA512: 2388066be2b6bb2cf3d6757c8f6334beeda6115ef1ce7c537955d32aa5e466add5162d0d2adee27f416fe622fc93c4e94bd848326463ee55e08d1c0f4e03719c
2024-10-18 16:35:15 +00:00