Commit Graph

1910 Commits

Author SHA1 Message Date
yancy 3523b8e117 Rename generic parameter and variable
Use W for Write
2024-11-07 16:38:13 -06:00
merge-script f963bf38b1
Merge rust-bitcoin/rust-bitcoin#3585: Fix bip34 number parsing for Block
c61df05916 Fix bip34 number parsing for Block (junderw)

Pull request description:

  Fixes #3583

ACKs for top commit:
  apoelstra:
    ACK c61df059160d3aeef73046de28cb5d5afcb962d2; successfully ran local tests
  tcharding:
    ACK c61df05916

Tree-SHA512: 3fade122f98c7c9e3b2888c33479d3a9426fb35f212ccee6b89b7cd5c92d2b58c93e165d5c59eda183c0943809d7e633d929000be92b197988a3ceb0ea37514f
2024-11-07 21:16:25 +00:00
Jamil Lambert, PhD 8098d5ee05
Reword `Address` constructor docs
Change the wording of the Address constructor function docs to be a
standard format.
2024-11-06 19:05:29 +00:00
merge-script 4797a75586
Merge rust-bitcoin/rust-bitcoin#3584: Standardize constructor type function docs
1649b68589 Standardize wording to `constructs a new` (Jamil Lambert, PhD)
27f94d5540 Replace `creates` with `constructs` (Jamil Lambert, PhD)

Pull request description:

  As discussed in issue #3575 there are various ways of saying a new object is created.

  These have all be standardized to the agreed version.

  Close #3575

ACKs for top commit:
  apoelstra:
    ACK 1649b68589834dfe9d5b63812da3e9f0e5930107; successfully ran local tests
  tcharding:
    ACK 1649b68589

Tree-SHA512: 0ed9b56819c95f1fc14da1e0fdbbe03c4af2d97a95ea6b56125f72913e8d832db5d2882d713ae139d00614e651f3834a4d72528bdf776231cceb6772bf2f9963
2024-11-06 16:05:24 +00:00
junderw c61df05916
Fix bip34 number parsing for Block 2024-11-06 14:06:18 +09:00
Jamil Lambert, PhD 1649b68589
Standardize wording to `constructs a new`
There is a range of different wordings used in the docs of constructor
type functions.

Change all to start with `Constructs a new` or `Constructs an empty`.
2024-11-05 13:02:26 +00:00
Jamil Lambert, PhD 27f94d5540
Replace `creates` with `constructs`
In functions that act like constructors there is a mixture of the usage
of `creates` and `constructs`.

Replace all occurrences of `creates` with `constructs` in the first line
of docs of constructor like functions.
2024-11-05 12:47:28 +00:00
Tobin C. Harding 915c9627f6
Put feature gate attribute under test attribute
Either way is fine, just pick one and be uniform.
2024-11-05 11:16:23 +11:00
merge-script 3b0cb0e87d
Merge rust-bitcoin/rust-bitcoin#3539: Improve the `amount` module
81d8699b55 units: Put no_std up top (Tobin C. Harding)
3e332c3839 amount: Fix docs on FromStr (Tobin C. Harding)
5bec76aa51 amount: Fix rustdocs (Tobin C. Harding)
41c80cc476 amount: Improve docs on div by weight (Tobin C. Harding)
2b4a61739a Add type to debug output for Amount (Tobin C. Harding)
42e5043b33 Add from_int_btc group of functions (Tobin C. Harding)

Pull request description:

  Improve the `amount` module by doing:

  - Patch 1: Add/update `from_int_btc` and `from_int_btc_const` functions
  - Patch 2:  Add type to debug output for `Amount`
  - Patch 3: Fix incorrect docs
  - Patch 4: Make docs use correct style and be uniform across the two amount types
  - Patch 5: Fix docs on `FromStr`

ACKs for top commit:
  apoelstra:
    ACK 81d8699b55dad570247cb14d2b3eea64270a83cf; successfully ran local tests
  jamillambert:
    ACK 81d8699b55

Tree-SHA512: ddd6e02b4cd9a9aa8cbdd2d2f7ae289a6bcca9eb002ef0c6d83a6eca950b2cd08f5918286bb33e814f321e3bfe83fdf75ae051cf8f91ee45d3e4abe76c1c2a4c
2024-11-04 23:32:41 +00:00
Tobin C. Harding 6555143478
bitcoin: Re-format crate level re-exports
Is there any advantage trying to lay out the re-exports to give users an
idea of the crate structure?

We have the explicit aim that users who depend on `bitcoin` do not ever
need to reach directly into `primitives` (or `units`) however it is kind
of nice to know where things come from, saves jumping to multiple files
looking for them (for those of us that jump to files manually).

I do not know how all the re-exports interact with other folks IDEs, I
personally open files manually and just remember where stuff is.
2024-11-04 08:49:03 +11:00
merge-script 794fb75497
Merge rust-bitcoin/rust-bitcoin#3562: Re-export `block::Header` as `BlockHeader`
85942c355d Re-export block::Header as BlockHeader (Tobin C. Harding)

Pull request description:

  For users who want to just grab stuff from the crate root it makes total sense for there to be a `BlockHeader`.

  Another nice thing, in the HMTL docs it makes BlockHeader be in the struct list right along with `Block`, `BlockHash`, and `BlockHeight`.

  Close: #3548

ACKs for top commit:
  apoelstra:
    ACK 85942c355dfdcf9ddf9a46202f4db56794dcc85d; successfully ran local tests
  jamillambert:
    ACK 85942c355d

Tree-SHA512: 6fbaf7936062323d31940179ffcbc62951b21f53955a42dca2e28476bda0cebeb041db0e1b4f1ceeac32e43d94fe5476ef055595ae88dc6cfc266d32082bdf4d
2024-11-03 17:02:38 +00:00
merge-script 26873c4ee8
Merge rust-bitcoin/rust-bitcoin#3572: Automated nightly rustfmt (2024-11-03)
5ecf7f2d67 2024-11-03 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:
  apoelstra:
    ACK 5ecf7f2d6795b07f8c4e3f2804e018deca80f113; successfully ran local tests

Tree-SHA512: b66b82b185120cd8f00f5bb986c914011003b727f2c172cb3da720fb2b8ac2d4027e6a9f75673ccda0a1328a77cd1bfff9aaf47506ae40a68e8984b19a250d85
2024-11-03 16:29:56 +00:00
merge-script 7210543f17
Merge rust-bitcoin/rust-bitcoin#3569: script: remove `unsafe` marker from slice-to-script conversions
4431df18fe script: remove `unsafe` marker from slice-to-script conversions (Andrew Poelstra)

Pull request description:

  The length of the slices is not a safety invariant.

  Fixes #3531

ACKs for top commit:
  tcharding:
    ACK 4431df18fe

Tree-SHA512: 85f745058bc5bf68d312f75c53cef570ead986247ca3cb3fc54b5381dd0214e7df55c1fcb99f06e693b0b9478ec6a9785186cac56886f8007ab7b827d903bd01
2024-11-03 15:06:36 +00:00
Fmt Bot 5ecf7f2d67 2024-11-03 automated rustfmt nightly 2024-11-03 01:21:14 +00:00
Andrew Poelstra 4431df18fe
script: remove `unsafe` marker from slice-to-script conversions
The length of the slices is not a safety invariant.

Fairly large diff because I had to remove a bunch of `unsafe` blocks
around calls to this function.

Fixes #3531
2024-11-02 13:45:11 +00:00
Tobin C. Harding 42e5043b33
Add from_int_btc group of functions
Add/update the from_int group of functions to provide one that errors
and one that is const and panics (errors in const context are not useful
because one cannot call `unwrap` in const context).
2024-11-02 10:19:03 +11:00
Tobin C. Harding 90b2ac03e3
hashes: Introduce impl_bytelike_traits macro
We have a couple of problems:

1. There are two macros currently for fmt stuff that do similar things,
`arr_newtype_fmt_impl` and `hex_fmt_impl` - the difference is not
immediately obvious, its the way that the byte array is iterated.

2. Our hash types are missing `AsRef<[u8; len]>` and `Borrow<[u8; len]>`.

Introduce a new macro and remove a bunch of other macros. Include
extensive docs but hide the macro from public docs because its not
really for consumers of the library.

The macro requires `$crate::hex` to point to `hex-conservative`.

Note the macro is pretty generic (as in general purpose), `hashes` might
not be the right home for it. Potentially a better place would be in
`hex` itself?
2024-11-02 08:10:43 +11:00
Tobin C. Harding 85942c355d
Re-export block::Header as BlockHeader
For users who want to just grab stuff from the crate root it makes total
sense for there to be a `BlockHeader`.

Another nice thing, in the HMTL docs it makes BlockHeader be in the
struct list right along with `Block`, `BlockHash`, and `BlockHeight`.
2024-11-02 07:38:10 +11:00
merge-script 112d75eed9
Merge rust-bitcoin/rust-bitcoin#3517: Remove `private_key_debug_is_obfuscated` test
7bff725494 Remove private_key_debug_is_obfuscated test (Diogo Canut)

Pull request description:

  Solves #3186.

ACKs for top commit:
  tcharding:
    ACK 7bff725494
  apoelstra:
    ACK 7bff725494bed02bed7f5d2af8278c89aaf73f40; successfully ran local tests; sure

Tree-SHA512: 68dcdc476ada7960eb224dd456010bc36a302472b8a8b4d1ea3ab9c6981550d7677a98516331d5e5ef636be0cdc7208c45278d70c506e04d067b997758fd4bcf
2024-11-01 14:20:46 +00:00
Tobin C. Harding 6aa8c2b023
Remove needless_borrows_for_generic_args
This has been fixed and we use nightly to lint so we have access to the
merged fix.

Removing the attribute uncovers a bunch of real lint warnings, fix
them while we are at it.
2024-11-01 14:30:45 +11:00
merge-script 4c8347a7ac
Merge rust-bitcoin/rust-bitcoin#3544: Favour `to_vec` over `to_bytes`
a51768af3f key: Deprecate to_bytes (Tobin C. Harding)
3af3239ad0 script: Re-order functions (Tobin C. Harding)
db40297f87 script: deprecate to_bytes (Tobin C. Harding)
c5cd0db493 Revert the change to to_bytes (Tobin C. Harding)
dc2ca785d2 Add to_vec and deprecate to_bytes for array types (Tobin C. Harding)
a6b7ab32a8 Move impl_array_newtype to internal_macros (Tobin C. Harding)

Pull request description:

  Use `to_vec` and deprecate `to_bytes`, the opposite of what we did in #2585.

  For functions that return a `Vec` by first allocating use function name `to_vec`. This explicitly excludes:

  - Functions that return an array (`CompressedPublicKey::to_bytes`)
  - Functions that consume self and return a `Vec` without allocating (`ScriptBuf::into_bytes`)

  See #3025 for discussion and consensus.

  Close: #3025

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

Tree-SHA512: ee932c13ad2e09c2b76a7833b23c859df175aa307f56e673921f3ae8b5d865518c6f999749e3b627594457b3ca33301b777177ada3520cf006acc0f14e5dacf8
2024-11-01 00:55:15 +00:00
merge-script 8bc2f39fca
Merge rust-bitcoin/rust-bitcoin#3547: Remove more wildcard re-exports
0bf1910980 Remove wildcard from script self re-exports (Tobin C. Harding)
397a4b9382 Remove wildcard in push_bytes module (Tobin C. Harding)

Pull request description:

  We thought #3436 was done (well I thought it was), turns out I was wrong.

ACKs for top commit:
  jamillambert:
    ACK 0bf1910980
  apoelstra:
    ACK 0bf1910980a13005496244ec4d4adf0553afbc73; successfully ran local tests

Tree-SHA512: 131a4aa4a907099790d14cfc2d19305943a2270cf6852c7dd92e35ea69188c9a40797fb22fd2ed8b2fefc2d6380b884401b5e32f521711f0f7b2da610d0e332f
2024-10-31 23:51:50 +00:00
Diogo Canut 7bff725494 Remove private_key_debug_is_obfuscated test
The private_key_debug_is_obfuscated test is removed because it belongs
in the secp256k1 library, not in the bitcoin library. Keeping it here
is redundant and creates unnecessary maintenance.
2024-10-31 20:31:59 -03:00
merge-script 8af8bc7886
Merge rust-bitcoin/rust-bitcoin#3543: Bump hex-conservative to 0.3.0
7f289a9fdf Bump hex-conservative to 0.3.0 (Leo Nash)

Pull request description:

ACKs for top commit:
  tcharding:
    ACK 7f289a9fdf
  apoelstra:
    ACK 7f289a9fdf86604cc1ecfb31c6df0ea5bb175465; successfully ran local tests

Tree-SHA512: bf8543ef7dc9b7ec0d11659c0a53213be50b9bbae0e6ba6970a19d32b3d89025315fcae332c23d68582ef69ea5f8e6673192ff74316a1e3dc47521312bbc469e
2024-10-31 21:05:02 +00:00
Tobin C. Harding a51768af3f
key: Deprecate to_bytes
As we have been doing in other places deprecate `to_bytes` in favour of
`to_vec`. Note this is only for functions that return a `Vec`, the `key`
module has `CompressedKey::to_bytes` still as it returns an array.
2024-11-01 07:10:41 +11:00
Tobin C. Harding db40297f87
script: deprecate to_bytes
Deprecate the `Script::to_bytes` function in favour of `to_vec` as we
are doing elsewhere.

Note that `ScriptBuf` has `into_bytes` because it does not copy.
Potentially this should be deprecated in favour of `into_vec`?

Note that in regards to the `to_` prefix this naming as valid according
to convention because the `Script` type is borrowed and `to_vec` copies
the underlying bytes.
2024-11-01 07:09:53 +11:00
Tobin C. Harding c5cd0db493
Revert the change to to_bytes
During this release cycle we deprecated `to_vec` in favour of
`to_bytes`, we have since reversed our position on the name.

Remove the deprecation of `to_bytes` from the three types that had it
and use `to_vec`.
2024-11-01 07:09:11 +11:00
Tobin C. Harding dc2ca785d2
Add to_vec and deprecate to_bytes for array types
For the array wrapper types (eg `ShortId`) created with the
`impl_array_newtype` macro deprecated the `to_bytes` function and add a
`to_vec` function.

Discussed and decided upon in issue: #3025
2024-11-01 07:08:49 +11:00
merge-script 5f3af4bab2
Merge rust-bitcoin/rust-bitcoin#3536: Use `doc(notable_trait)`
dfb76c1e15 Use doc(notable_trait) (Tobin C. Harding)

Pull request description:

  There is an unstable feature that puts up a little 'i' in a circle next to any function that returns a type that implements an notable trait. For us this means we can make the extension traits more discoverable.

  ref: https://doc.rust-lang.org/unstable-book/language-features/doc-notable-trait.html

  Close: #3232

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

Tree-SHA512: 0fbc7a2a3c8c499a9276d1e86b9966a7ae6bd8a354aff5fd40aa11d07945db589b2a9c2cdfa43ddadfafcee706ae7f68cedc269f74622643307cc43cd07d554f
2024-10-31 15:01:19 +00:00
Tobin C. Harding 0bf1910980
Remove wildcard from script self re-exports
In the `script` module remove the wildcards and re-export stuff from
`self` explicitly in both `primitives` and `bitcoin`.

Internal change only, everything is re-exported.
2024-10-31 15:52:54 +11:00
Tobin C. Harding 397a4b9382
Remove wildcard in push_bytes module
Remove the wildcard even though it is only re-exporting things from
module code within the file.
2024-10-31 15:51:29 +11:00
Leo Nash 7f289a9fdf Bump hex-conservative to 0.3.0 2024-10-31 03:36:22 +00:00
Tobin C. Harding a6b7ab32a8
Move impl_array_newtype to internal_macros
The current feature gating is wrong, this bug is unreleased because it
was introduced #2585.

The `impl_array_newtype` macro is only used in the `bitcoin` crate, it
does not need to be in `internals`. Also, other crates have an `alloc`
feature which `bitcoin` does not have so if we ever need it in other
places we'll need a duplicate with the correct feature gating anyways.

Move the macro to `bitcoin::internal_macros` and remove the incorrect
`alloc` feature gating.
2024-10-31 14:15:41 +11:00
Tobin C. Harding dfb76c1e15
Use doc(notable_trait)
There is an unstable feature that puts up a little 'i' in a circle
next to any function that returns a type that implements an notable
trait. For us this means we can make the extension traits more
discoverable.

ref: https://doc.rust-lang.org/unstable-book/language-features/doc-notable-trait.html

Close: #3232
2024-10-31 13:33:28 +11:00
Tobin C. Harding f8f846bb9e
Move Transaction type to primitives
Needs no explanation - lets go!
2024-10-30 12:28:53 +11:00
Tobin C. Harding 7b5af2ad5b
Use `Transaction::compute_txid` in rustdoc
The `txid` function was re-named to `compute_txid` but we missed one
call link in rustdocs - update it.
2024-10-30 12:28:52 +11:00
Tobin C. Harding 98383a0fbe
Introduce Transaction extension traits
WARNING: This is not like all the other extension traits.

Because of the use of generics on various `Transaction` methods it is
not easily possible to use the `define_extension_trait` macro.

Manually create the extension traits (public and private) for the
`Transaction` type. This is quite ugly but c'est la vie

(Includes two in the `transaction` module and one in the
`consensus_validation` module.)
2024-10-30 12:28:52 +11:00
Tobin C. Harding 3f6bc74ae4
Introduce an iterator type for script_pubkey_lens
Currently `script_pubkey_lens` returns a generic `Iterator` using `impl`
syntax. This syntax is not supported in traits and we want to move the
function to the soon-to-be-added `TransactionExt` trait.

Add a struct to hold the iterator returned by `Map`, this is ugly but
its the least ugly thing I could come up with.
2024-10-30 12:28:51 +11:00
Tobin C. Harding 7196992d58
Split Transaction impl block
Split the `Transaction` impl block into three parts:

- The bits going to `primitives`
- The bits staying in a public extension trait
- The bits staying in a private extension trait

Internal change only.
2024-10-30 11:30:41 +11:00
Tobin C. Harding 693000d09c
Use super::* in bench module
It is acceptable to use a wildcard import in bench code for the same
reasons it is acceptable in the `tests` module.

In preparation for introducing extension traits in the `transaction`
module use wildcard import in the module's bench code.
2024-10-30 11:30:36 +11:00
Tobin C. Harding 29d23b4b3a
Move import statement
The code using this import is a feature gated test, move the import into
the test.

Found with clippy. Internal change only.
2024-10-30 11:30:25 +11:00
Tobin C. Harding e84346644e
Run the formatter
Run `just fmt` - no other changes.
2024-10-30 11:30:24 +11:00
merge-script c40826e008
Merge rust-bitcoin/rust-bitcoin#3480: bitcoin: Add some upgrade notes
f2e1a4b16c bitcoin: Add some upgrade notes (Tobin C. Harding)

Pull request description:

  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.

ACKs for top commit:
  storopoli:
    ACK f2e1a4b16c
  apoelstra:
    ACK f2e1a4b16cb8b71b50da723a20761fbe3822d6fc; successfully ran local tests

Tree-SHA512: 3e7a64445476dce8c716edf127b2594c434948bfff7c301ac74a723fa49b2784cca90cf74d231fe18a9fa8e80ffd5cb43232fb90aeae5943568623d4252fc4ef
2024-10-29 14:15:36 +00:00
merge-script 6c8d0ef95b
Merge rust-bitcoin/rust-bitcoin#3519: psbt: Fix bug in Subtype consensus_encode
c89b816437 psbt: Fix bug in Subtype consensus_encode (Tobin C. Harding)

Pull request description:

  In #2906 we switched from using a `u8` for type keys to using a `u64` and encoding as a compact int (inline with the spec). Note that a `u8` encodes to the same bytes as a `u64` when the value is < 252.

  In that patch, I introduced a bug because the length returned by `PoprietaryKey::consensus_encode` uses a hard code 1 for the length of the encoding (because of single byte) instead of the variable length for the new compact encoding.

  Bug showed up in fuzzing, and was isolated by Jamil - mad props.

  Fix: #3501

ACKs for top commit:
  jamillambert:
    ACK c89b816437
  apoelstra:
    ACK c89b8164377123eb20476636f2f5271c6a687406; successfully ran local tests

Tree-SHA512: 1b61b6a9ece197d74038ceedb447fd3ca21db8e2a6a96c9281a99ac232c18c3ca55da8e3f46930401714d3575e9a406a36e4f44929ca963208a5df4be6b46cfb
2024-10-29 13:10:08 +00:00
merge-script 34bf82060c
Merge rust-bitcoin/rust-bitcoin#3520: Use fully qualified path in macro
025a8773bf Use fully qualified path in macro (Tobin C. Harding)

Pull request description:

  Using fully qualified paths in macros reduces maintenance burden. We have one macro where we use relative path to access the `psbt` module.

  Refactor only, no external change.

ACKs for top commit:
  apoelstra:
    ACK 025a8773bf63aacdaca011ef000f41a85a961567; successfully ran local tests; will one-ACK merge

Tree-SHA512: eb5923a48ae4d82499679a58375ef7d2e8ba85c91671e350f7be19f0372750a269f44dd2f05f4a70ed0c7f277b160400eb41ff1d42b90e6057f1344be7e11a89
2024-10-29 04:28:20 +00:00
merge-script 1f578fc929
Merge rust-bitcoin/rust-bitcoin#3518: Automated nightly rustfmt (2024-10-27)
39f46a16bc 2024-10-27 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 39f46a16bc
  apoelstra:
    ACK 39f46a16bc0da356f495166ccd5829627af3749b; successfully ran local tests

Tree-SHA512: 6c27714b18ad6957104246145a2d4243f8e43e378d63f3d946ba05ecaf859432f2fe363fe3e7a29a33c41297216fd1176c165ac55deb109f636813c637ff6c43
2024-10-28 21:34:59 +00:00
merge-script 6c54a1d2f2
Merge rust-bitcoin/rust-bitcoin#3497: Explicitly re-export stuff from crates down the stack
66da2266e2 Explicitly re-export stuff from crates down the stack (Tobin C. Harding)

Pull request description:

  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.

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

Tree-SHA512: 74717f8b127e975e3d131aab884bdfe78e699d88b7ee1db7731ad117437d37684285264001cf6b2182eb1e565171167695e00c4b6aef28a3e26b69d9cebfbb74
2024-10-28 19:20:23 +00:00
merge-script 4bd820b8cc
Merge rust-bitcoin/rust-bitcoin#3045: Remove `bech32` from `address::ParseError`
9a7b1c232b Wrap the bech32 decoding error (Tobin C. Harding)

Pull request description:

  In #2381 we attempted to fully encapsulate the `bech32` crate to help with stabalizing `rust-bitcoin` however we failed to notice the `address:ParseError` has a variant that includes `bech32`. Public enums have public variant internals in Rust. Also the `From<bech32::segtiw::DecodeError` makes `bech32` public.

  Closes: #3043

ACKs for top commit:
  apoelstra:
    ACK 9a7b1c232b494dccdce091a46d916cc411a612a1; successfully ran local tests; will one-ACK merge since this is a gazillion years old and obviously right

Tree-SHA512: b5053aa43107aa47da1fe7e7db0f882cfb231b9769a7b67d8c930532c471df191f588bf98f2b00cc76d5a2e9c74e035ee96128da115363ac3952f96a766494ea
2024-10-28 18:15:38 +00:00
Tobin C. Harding 3e2c43b19e
Elide more lifetimes
clippy found some more lifetimes to elide.
2024-10-28 15:22:13 +11:00
Tobin C. Harding 025a8773bf
Use fully qualified path in macro
Using fully qualified paths in macros reduces maintenance burden. We
have one macro where we use relative path to access the `psbt` module.

Refactor only, no external change.
2024-10-28 09:08:26 +11:00
Tobin C. Harding c89b816437
psbt: Fix bug in Subtype consensus_encode
In #2906 we switched from using a `u8` for type keys to using a `u64`
and encoding as a compact int (inline with the spec). Note that a `u8`
encodes to the same bytes as a `u64` when the value is < 252.

In that patch, I introduced a bug because the length returned by
`PoprietaryKey::consensus_encode` uses a hard code 1 for the length of
the encoding (because of single byte) instead of the variable length for
the new compact encoding.

Bug showed up in fuzzing, and was isolated by Jamil - mad props.
2024-10-28 08:09:41 +11:00
Fmt Bot 39f46a16bc 2024-10-27 automated rustfmt nightly 2024-10-27 01:21:24 +00:00
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 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
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
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 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
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 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
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
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
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
Jamil Lambert, PhD 3d994f7bdb
Decode an address string based on prefix
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`.
2024-10-18 10:38:28 +01:00
ChrisCho-H 9d9a2d53e1 refactor: compute recid in a single line 2024-10-18 16:39:50 +09:00
Tobin C. Harding c1eccfde25
Move Witness to primitives
Move the `Witness` over to `primitives` leaving behind any method that
takes or returns a `Script` or a signature.

Includes addition of a feature gate to unit test.
2024-10-18 14:02:03 +11:00
Tobin C. Harding 6ce76cd7c8
Add unstable constructor to Witness
In preparation for moving the `Witness` to `primitives` we need a way to
construct the `Witness` when decoding. In order to maintain the current
performance and not introduce additional allocations we need to be able
to construct a `Witness` from the content buffer, this leaks the
implementation details of `Witness`.

Add a clearly marked unstable constructor to create a `Witness` from
parts. This introduces the concept of `foo__unstable` function names;
add a section to the README describing unstable functions and semver
guarantees.
2024-10-18 14:01:03 +11:00
merge-script 02bf38e2a6
Merge rust-bitcoin/rust-bitcoin#3478: bitcoin: Set version to `0.33.0-alpha`
f37b573290 bitcoin: Set version to 0.33.0-alpha (Tobin C. Harding)

Pull request description:

  We would like to create branches in other repos/crates that track master in this repo for testing purposes. In order to do so we need a non-0.32 version otherwise `cargo` pulls from crates.io.

  Set the version to `0.33.0-alpha` - try not to get too excited, this release is a looong way away.

ACKs for top commit:
  apoelstra:
    ACK f37b5732901133eff0b8b11744f743c71533c240; successfully ran local tests; though I think if you try you can make cargo behave better

Tree-SHA512: 08d9f6e658ac575e4d42681ffe3fff2116ee35e31c1150b0f21228cb5ef9fc326ea604a9cfc56378a7da60815c2e6e9add4dd4d96969fea2dda2005d1c9af34f
2024-10-17 15:54:30 +00:00
merge-script 7af9e33f2b
Merge rust-bitcoin/rust-bitcoin#3468: Move `block::Header` to `primitives`
ff64fa3c46 Move block::Header to primitives (Tobin C. Harding)
65925117a0 Manually implement block::Header::block_hash (Tobin C. Harding)
b02ab25342 Add regression test for block_hash function (Tobin C. Harding)
5614694b69 block: Remove wildcard re-export (Tobin C. Harding)

Pull request description:

  - Patch 1: Trivial preparation.
  - Patch 2 and 3: Reduce the API surface in a disappointing way due to the orphan rule.
  - Patch 4: Do the move.

ACKs for top commit:
  apoelstra:
    ACK ff64fa3c46 successfully ran local tests; nice!

Tree-SHA512: 8d93de4a12c9f71f9dfbdc023fd8defb78f7d3da995490af8f83a927c2ca6338dd236bc08691311dc7345183fb6d0be61eedce3e4424d4060be2de934facd60a
2024-10-17 13:12:06 +00:00
merge-script 0f20669b40
Merge rust-bitcoin/rust-bitcoin#3472: test: add test for new sign fn
88a35c8918 test: add test for new sign fn (Chris Hyunhum Cho)

Pull request description:

  Follow up https://github.com/rust-bitcoin/rust-bitcoin/pull/3456.
  add test to verify the signature generated from newly added `sign` fn.

ACKs for top commit:
  apoelstra:
    ACK 88a35c8918f48e72f032b73a233a016a1a0056b6; successfully ran local tests; sorry, testing local CI changes..
  tcharding:
    ACK 88a35c8918

Tree-SHA512: 8c457fbabf1ff86a9369934564874e78660f706714465731c185da16eff5c88a5e680c4373effbcc273394a5653edde9f559558917fee6e438b79bfee6f63b22
2024-10-17 02:09:09 +00:00
Tobin C. Harding f37b573290
bitcoin: Set version to 0.33.0-alpha
We would like to create branches in other repos/crates that track master
in this repo for testing purposes. In order to do so we need a non-0.32
version otherwise `cargo` pulls from crates.io.

Set the version to `0.33.0-alpha` - try not to get too excited, this
release is a looong way away.
2024-10-17 08:44:40 +11:00
merge-script 73bb017d78
Merge rust-bitcoin/rust-bitcoin#3474: Remove `allow_unused` flag in serde
49914c50f4 Remove `allow_unused` flag in serde (Jamil Lambert, PhD)

Pull request description:

  In serde `#[allow(unused_variables)]` has been dropped and the unused variables have been "used" when `debug_assertions` is off.

  Close #3332

ACKs for top commit:
  tcharding:
    ACK 49914c50f4
  apoelstra:
    ACK 49914c50f4 successfully ran local tests

Tree-SHA512: c83703f91abb5ce513f6403375ce3b2cb24d5200272c98f0a5e532fe41dda1aae8a5334ee8868751e156457f1cfe6b4fe08849fb5329bfbb1c12ed18364e0b1c
2024-10-16 12:03:47 +00:00
merge-script 17899d1b8c
Merge rust-bitcoin/rust-bitcoin#3475: Unify deprecated note field format
88b53a471e Unify deprecated note field format (Jamil Lambert, PhD)

Pull request description:

  Following the suggestion in Issue #3306 all the deprecated note fields have been changed to be lower case and in the format "use `abc` instead".

ACKs for top commit:
  tcharding:
    ACK 88b53a471e
  apoelstra:
    ACK 88b53a471e successfully ran local tests

Tree-SHA512: 5c20eda7140f37ce78eb58dfdf03ecc11a67fcb10f294d860e81eaaee696e3a4209516017a9885cef9bfff1aa69b845534d139578b674933770fa24d59e4275f
2024-10-16 02:10:58 +00:00
merge-script 84deb29964
Merge rust-bitcoin/rust-bitcoin#3473: Fix lint errors
8696cb4b07 Fix unused import warning (Jamil Lambert, PhD)
fbc7aa7fd5 Remove unnecessary lifetimes (Jamil Lambert, PhD)

Pull request description:

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

  The unnecessary lifetimes have been removed.

  An unused import warning has also been fixed by placing the use statement behind the relevant feature gate.

ACKs for top commit:
  tcharding:
    ACK 8696cb4b07
  apoelstra:
    ACK 8696cb4b07 successfully ran local tests

Tree-SHA512: 37e14ca9be2e8cfa64498084a7363783c2cca92dfce40a0a3ed9bda98f081c1fa9119e5d49d81684b6968329945c7004b86534412fd2fcd4898b862c859d42c6
2024-10-16 00:04:05 +00:00
merge-script 88af71c81f
Merge rust-bitcoin/rust-bitcoin#2906: psbt: Encode keytype as a compact size unsigned integer
2f656f77ba psbt: Use u64 for key type (Tobin C. Harding)

Pull request description:

  Currently we use `u8` for key type but it was pointed out that we should be using a `u64` and encoding it as a compact type. The reason our code works now is because the compact type encoding for a `u8` (less than

  This breaks the `serde` impl, as shown by changes to the regression tests,

  Fix: #2891

ACKs for top commit:
  apoelstra:
    ACK 2f656f77ba successfully ran local tests

Tree-SHA512: ce5fe46b54cb724a0b0f9f874c037e5b5d344e5d3c380f9cdb3fdb5cbc5e31e4e32c229f5f2f72547823238934f6b0c3640c2c2ce79d98aa57bac509d130cb82
2024-10-15 18:37:20 +00:00
merge-script 54f362e148
Merge rust-bitcoin/rust-bitcoin#3426: Update lock files and downgrade minimum arbitrary
adf2fa3113 Update lock files and downgrade minimum arbitrary (Tobin C. Harding)

Pull request description:

  Recently we added a use of `Arbitrary` for `[u8; 64]` (schnorr sig). I hit a build failure locally and discovered that

  - `arbitrary 1.0.0` does not implement `Arbitrary` for 64 byte array
  - We use `arbitrary = 1` in the `bitcoin` manifest
  - We have `arbitrary 1.3.2` in the `Cargo-minimal.lock` file

  Fix this all up by doing:

  - Use `1.0.1` in the `bitcoin` manifest because that is a hard minimum version required to build
  - Downgrade the `Cargo-minimal.lock` file to use `arbitrary v1.0.1`
  - Upgrade the `Cargo-recent.lock` file while we are at it for good measure.

ACKs for top commit:
  shinghim:
    ACK adf2fa3113
  apoelstra:
    ACK adf2fa3113 successfully ran local tests

Tree-SHA512: 7be48d2086523322ca4b5f83a344d5096c46cfaff6bd2deb829d30b439feb045ba86b51e9ab2eac4ad5693b0f54a56ca4b86aadafc17a7e4a15cda4a349d0b18
2024-10-15 18:01:54 +00:00
merge-script 4fa5732486
Merge rust-bitcoin/rust-bitcoin#3417: Update CHANGELOG files
4d18624435 Update CHANGELOG files (Tobin C. Harding)

Pull request description:

  When we create point releases we merge the release tracking PR directly into the version branch, including the changelog entries. This means the changes never end up on `master`. We need to make a mental note to patch `master` anytime we merge a point release PR.

  Audit all crates with a non-zero current point release and check we have the changelog entries on `master`.

ACKs for top commit:
  apoelstra:
    ACK 4d18624435 successfully ran local tests

Tree-SHA512: 826a5e5a565237d4f499dd56471b01ee7970b04125931f5a49355099507e24ae4452108004276939884e338201dd3ae7b66fd68439523b6bb1b07b83d3759ae4
2024-10-15 17:23:33 +00:00
Jamil Lambert, PhD 88b53a471e
Unify deprecated note field format
All the deprecated note fields have been changed to be lower case and in
the format "use `a` instead".
2024-10-15 15:16:01 +01:00
Jamil Lambert, PhD 49914c50f4
Remove `allow_unused` flag in serde
In serde `#[allow(unused_variables)]` has been dropped and the unused
variables "used" when `debug_assertions` is off.
2024-10-15 14:40:54 +01:00
Jamil Lambert, PhD 8696cb4b07
Fix unused import warning
An import was only used behind a feature gate.  The feature gate has
been added to the use statement to remove the warning.
2024-10-15 14:05:19 +01:00
Chris Hyunhum Cho 88a35c8918
test: add test for new sign fn 2024-10-15 12:51:47 +09:00
Tobin C. Harding ff64fa3c46
Move block::Header to primitives
Introduce an extension trait and move the `block::Header` type to
`primitives`.

Nothing surprising here.
2024-10-15 11:04:00 +11:00
Tobin C. Harding 65925117a0
Manually implement block::Header::block_hash
We want to move the `block_hash` function to `primitives` but it uses
`Encodable` which currently lives in `bitcoin`. Just implement it
manually.

We added a regression test already in a previous commit to check that
this is correct.
2024-10-15 10:46:28 +11:00
Tobin C. Harding b02ab25342
Add regression test for block_hash function
In preparation for manually implementing `Header::block_hash` add a
regression test.
2024-10-15 10:38:50 +11:00
Tobin C. Harding 5614694b69
block: Remove wildcard re-export
Use explicit re-exports for `primitives` types when re-exporting from
the `block` module.
2024-10-15 10:01:03 +11:00
Tobin C. Harding e68da281ff
Warn on future deprecations
We use `TBD` in our `deprecated` string and it was discovered that there
is an exception on this string so as not to warn because it is used
internally by the Rust language. However there is a special lint to
enable warnings, lets use it.

Add `#![warn(deprecated_in_future)]` to the coding conventions section
of all crates except `fuzz`.
2024-10-15 07:56:06 +11:00
Tobin C. Harding 2cc944578d
Fully deprecate Hash::from_slice
We had an initial go at this but we didn't do the `Hash` trait method.
In order to do so we need to hack the serde code a fair bit, note the
public visitor types.
2024-10-15 07:56:05 +11:00
Tobin C. Harding 8bc3b2e2c4
Stop using deprecated to_vec
Recently we deprecated `to_vec` in favour of `to_bytes` however we
continued to use `to_vec` in a few places. This wasn't noticed because
of our usage of `TBD` in the `deprecated` attribute.

Use `to_bytes` instead of `to_vec`.
2024-10-15 07:49:48 +11:00
merge-script 1b23d1c66c
Merge rust-bitcoin/rust-bitcoin#3431: Move script types to `primitives`
d649c06238 Move script types to primitives (Tobin C. Harding)
ec4635904b Inline bytes_to_asm_fmt into Script::Display impl (Tobin C. Harding)

Pull request description:

  First patch removes `bytes_to_asm_fmt` as requested by Kix here: https://github.com/rust-bitcoin/rust-bitcoin/pull/3194#discussion_r1756557768

  Second patch does the move. The move is minimal but there is quite a bit of code moved in `script/mod.rs` - I believe it is as minimal as required as well.

ACKs for top commit:
  apoelstra:
    ACK d649c06238 successfully ran local tests

Tree-SHA512: 329a23948ac5617402a724b734d81cde8ab1f57ddd4860f858880618e260ea8b5cc89315de1fd93ae32787d5e8508fd604a41f003b1f5772a773b5b1648d382c
2024-10-14 00:31:38 +00:00
Tobin C. Harding d649c06238
Move script types to primitives
Move the `Script` and `ScriptBuf` types to `primitives`, nothing else.
2024-10-14 09:02:39 +11:00
Tobin C. Harding ec4635904b
Inline bytes_to_asm_fmt into Script::Display impl
This function does not need to exist anymore because it is exactly the
same as what is produced by the `Display` impl.
2024-10-14 09:02:26 +11:00
merge-script 48b2975870
Merge rust-bitcoin/rust-bitcoin#3456: feat: add sign fn for sign_message
c41a6e9b1b feat: add sign fn for sign_message (ChrisCho-H)

Pull request description:

  While it's not hard to create the signature using `secp256k1` modules with `signed_msg_hash`, it's much more convenient and safe to provide one-way function to generate signed signature(even without the understanding about the semantics of bitcoin message signing).

ACKs for top commit:
  apoelstra:
    ACK c41a6e9b1b successfully ran local tests
  tcharding:
    ACK c41a6e9b1b

Tree-SHA512: 84caea275059381040c71100badb54556dd105722f79ac43d2df7eb0e5428cf8e7acc2d7f262625dd008837099a928c3c8be858f9ab11838c2eec1786e9f1844
2024-10-13 21:13:39 +00:00
merge-script cc5b46bfc7
Merge rust-bitcoin/rust-bitcoin#3462: Automated nightly rustfmt (2024-10-13)
f1733309e0 2024-10-13 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:
  apoelstra:
    ACK f1733309e0 successfully ran local tests

Tree-SHA512: 465336b92d9b8a61afbc8e8d0560f3b41a732e3245d764447cc2a5429f693e29172bebeca756a91b5a1f3a16d42728960a526111bbd92316f72b46b420373641
2024-10-13 16:40:17 +00:00
merge-script 7a5816ce0b
Merge rust-bitcoin/rust-bitcoin#3461: Remove unused import
8f79a0560e Remove unused import (yancy)

Pull request description:

  Ran `./maintainer-tools/ci/run_task.sh stable` without error locally, so I don't think this import is needed.

ACKs for top commit:
  tcharding:
    ACK 8f79a0560e
  apoelstra:
    ACK 8f79a0560e successfully ran local tests

Tree-SHA512: 255b97066eb8b75bf33a0846ecda739695441273ff98703516b46983a9fe5c76e76c79ab2548bd64fd654dd8659ea5392b8079142b447e67a6a31d75883aa8d1
2024-10-13 15:24:27 +00:00
merge-script 4717f4d1af
Merge rust-bitcoin/rust-bitcoin#3459: feat: replace ENABLE_RBF_NO_LOCKTIME with ENABLE_LOCKTIME_AND_RBF
3565f70df9 feat: replace ENABLE_RBF_NO_LOCKTIME with ENABLE_LOCKTIME_AND_RBF (ChrisCho-H)

Pull request description:

  follow up https://github.com/rust-bitcoin/rust-bitcoin/pull/3455.
  Replace all `ENABLE_RBF_NO_LOCKTIME`(deprecated) with `ENABLE_LOCKTIME_AND_RBF`

ACKs for top commit:
  apoelstra:
    ACK 3565f70df9 successfully ran local tests
  tcharding:
    ACK 3565f70df9

Tree-SHA512: 4c6c6ad9ac89efe042cf239ce68594e715dbc827c1ae430819e2f16d2191f82d81f1e55b348f8176fc21454cf9d25fc9da1a414982cd3483d5f9f39834441f6c
2024-10-13 14:09:42 +00:00
Fmt Bot f1733309e0 2024-10-13 automated rustfmt nightly 2024-10-13 01:20:28 +00:00
yancy 8f79a0560e Remove unused import 2024-10-12 19:20:11 -05:00
merge-script 65e290a0ce
Merge rust-bitcoin/rust-bitcoin#3450: Add version three variant to transaction version
9e6b8faf84 feat: add version three variant to transaction version (Rob N)

Pull request description:

  Topologically restricted transactions are now considered standard as of Bitcoin 28.0.

ACKs for top commit:
  apoelstra:
    ACK 9e6b8faf84 successfully ran local tests
  tcharding:
    ACK 9e6b8faf84

Tree-SHA512: 289b986304e206802f04cee6607087167f6d91d8a81d4fc49ed01c430f4f6ad00b44646fbefdd000148fc5bfe2d257f92b386bfaf4405c482e4e438d830ab586
2024-10-12 17:55:21 +00:00
merge-script ae2358610d
Merge rust-bitcoin/rust-bitcoin#3457: Fix unused import
a250c8eee4 Fix unused imports (Shing Him Ng)

Pull request description:

  Found some unused imports while working on something unrelated

ACKs for top commit:
  apoelstra:
    ACK a250c8eee4 successfully ran local tests
  tcharding:
    ACK a250c8eee4

Tree-SHA512: ffa4fcddb91c849df7885a6d734405ab704e0353293fa3462a981e179ea49091990df4482eee2324e7b5ef250a0890b2e8983d53ec288ca6e8ada77e30c102dc
2024-10-12 14:56:48 +00:00
Andrew Poelstra 76f022d380 Merge rust-bitcoin/rust-bitcoin#3438: Implement Arbitrary for Block
0c824c9c68 Implement Arbitrary for Block (Shing Him Ng)

Pull request description:

  Implementing `Arbitrary` for `Block` and its child types

ACKs for top commit:
  apoelstra:
    ACK 0c824c9c68 successfully ran local tests
  tcharding:
    ACK 0c824c9c68

Tree-SHA512: 407acd4155ca7496bf7c59af19f103b22b4c74dd013c2e2c42aae690ba7264ecd42ed034355cf8895f2532f8cef77dfdbeac250301a6973afd5f3920be7e4310
2024-10-12 14:15:28 +00:00
ChrisCho-H 3565f70df9 feat: replace ENABLE_RBF_NO_LOCKTIME with ENABLE_LOCKTIME_AND_RBF 2024-10-12 12:42:43 +09:00
ChrisCho-H c41a6e9b1b feat: add sign fn for sign_message 2024-10-12 12:37:04 +09:00
Rob N 9e6b8faf84
feat: add version three variant to transaction version 2024-10-11 06:38:58 -10:00
merge-script 03715872cd
Merge rust-bitcoin/rust-bitcoin#3432: fmt: Use style_edition = 2021
323e706113 Add rustfmt config option style_edition (Tobin C. Harding)
2e4179ed0f Run the formatter (Tobin C. Harding)
2c40b4f4ec Configure formmater to skip read_compact_size (Tobin C. Harding)

Pull request description:

  `rustfmt` is emitting:

   Warning: the `version` option is deprecated. Use `style_edition` instead.

  As suggested add a config option and set it to 2021.

  - Patch 1: Manually configure rustfmt to skip some code
  - Patch 2: Run the formmater with current configuration
  - Patch 3: Add the new config option (remove old one), introduces no new formatting requirements

ACKs for top commit:
  apoelstra:
    ACK 323e706113 successfully ran local tests

Tree-SHA512: 7f80cc89f86d2d50936e51704344955fa00532424c29c0ee3fae1a6836e24030f909b770d28da13e1c5efde3d49ad7d52c6d909d120fb09c33abf1755f62cd38
2024-10-11 12:48:50 +00:00
Shing Him Ng a250c8eee4 Fix unused imports 2024-10-10 23:42:51 -05:00
Shing Him Ng 0c824c9c68 Implement Arbitrary for Block 2024-10-10 23:30:39 -05:00
merge-script fe62d94ff7
Merge rust-bitcoin/rust-bitcoin#3296: Remove the `SliceIndex` implementation from hash types
3b7ba4f977 Remove the SliceIndex implementation from hash types (Tobin C. Harding)

Pull request description:

  If folk really want to index into a hash they can us `as_byte_array` then index that.

  Includes a bump to the version number of `hashes` to `v0.15.0` - this is because otherwise `secp` won't build since we are breaking an API that is used in the current release of secp.

  Fix: #3115

ACKs for top commit:
  apoelstra:
    ACK 3b7ba4f977 successfully ran local tests

Tree-SHA512: 0ba93268cd8133fe683183c5e39ab8b3bf25c15bfa5767d2934d67a5f6a0d2f65f6c9304952315fe8a33abfce488d810a8d28400a28facfb658879ed06acca63
2024-10-10 22:39:21 +00:00
merge-script d5ebb19543
Merge rust-bitcoin/rust-bitcoin#3437: Move `block::Version` to primitives
70264bfcec Move block::Version to primitives (Tobin C. Harding)
819d8d72e8 Stop using private Version constructor (Tobin C. Harding)

Pull request description:

  This is a straight up move of the whole type because there are only three methods, a getter, a setter, and `is_signalling_soft_fork`.

  If we use an extension trait for `is_signalling_soft_fork` then we have to make the two private associated consts public which is in my opinion worse.

  Patch 1 is preparation, use getter/setter, patch 2 does the move.

ACKs for top commit:
  apoelstra:
    ACK 70264bfcec successfully ran local tests

Tree-SHA512: b61e853b4b96cb1cc56c7bfb67cc6c3ba7c631cb9e540393eb780dcf63bd2d934058794f2ac0145b4b5404a6a68887c3a1d225b2d87b57415474c05d3ef2811f
2024-10-10 21:28:44 +00:00
Tobin C. Harding 2f656f77ba
psbt: Use u64 for key type
Currently we use `u8` for key type but it was pointed out that we should
be using a `u64` and encoding it as a compact type. The reason our code
works now is because the compact type encoding for a `u8` (less than
253) is the same as for a `u8`.

This breaks the `serde` impl, as shown by changes to the regression tests.
2024-10-10 11:37:40 +11:00
Tobin C. Harding 2e4179ed0f
Run the formatter
Run `just fmt`, no other manual changes.
2024-10-10 10:39:53 +11:00
Tobin C. Harding 2c40b4f4ec
Configure formmater to skip read_compact_size 2024-10-10 10:39:36 +11:00
merge-script 78bcca71ca
Merge rust-bitcoin/rust-bitcoin#3443: Input weight prediction helpers for nested P2WPKH
aa1fd5f44c Update the doc for InputWeightPrediction::weight() (spacebear)
8fd53c8ecf Add nested P2WPKH helpers to InputWeightPrediction (spacebear)

Pull request description:

  Following up on https://github.com/rust-bitcoin/rust-bitcoin/issues/630#issuecomment-2392050517.

  I amended the docstring on `InputWeightPrediction::weight()` to clarify that it only returns the signature weight. I'm not sure what the rationale was for only returning partial input weight, and if there are any arguments against something like `InputWeightPrediction::total_weight()` which returns `self.weight() + Weight::from_non_witness_data_size(32 + 4 + 4)` (and maybe deprecate `weight()` eventually to prevent misuse).

ACKs for top commit:
  apoelstra:
    ACK aa1fd5f44c successfully ran local tests
  tcharding:
    ACK aa1fd5f44c

Tree-SHA512: 9bdd882164a80a1a1a44c593750aa59e470f2928c0380d4d53a0409add597844cf11945785264ebd6b281029b3f2ef1be6c77e1e9cd148192dbd601df30a60ae
2024-10-09 15:06:46 +00:00
merge-script 31f1a12aaf
Merge rust-bitcoin/rust-bitcoin#2945: Support Testnet4 Network
2424b654d5 feat: rust-bitcoin supports testnet4 (BinChengZhao)
afa91a2030 Introduce TestnetVersion enum with only TestnetV3 (BinChengZhao)

Pull request description:

  Fixed: https://github.com/rust-bitcoin/rust-bitcoin/issues/2749

  1. Adjust `Network` to support `Testnet4`. (Based on https://github.com/rust-bitcoin/rust-bitcoin/issues/2749#issuecomment-2152366608 as an implementation idea.)

  2. Handle conflicting procedure macros and declaration macros, since the original macros can't handle the new `Network::Testnet(TestnetVersion)` structure properly, and make internal implementations compatible with previous versions (e.g., `testnet` for `Testnet3`, `testnet4` for `Testnet4`, to minimize user-side effects).

  3. add `Testnet4` related Params, Block.

  4. optimize compatibility test cases.

  5. Regarding `fn: genesis_block`, calling `bitcoin_genesis_tx` with any Network type internally gets a reasonable `merkle_root`, but not `Testnet4`. (By comparison, I confirmed that the built-in transaction data provided is correct, and combined with the fixed `merkle_root` of `Testnet4` the correct block hash can be computed, which is not possible if the transaction data is incorrect.) **I'd appreciate it if some developer could guide me on what the problem is, and I'll work on it.**

  Of course, all these changes are based on https://github.com/rust-bitcoin/rust-bitcoin/issues/2749 , and the consensus of the discussion, if you have any comments, please leave a message, I will actively improve, and promote the support of `Testnet4`.

ACKs for top commit:
  tcharding:
    ACK 2424b654d5
  apoelstra:
    ACK 2424b654d5 successfully ran local tests

Tree-SHA512: a501f0a320460afdad2eb12ef6ff315b6357b7779dfe7c7028ea090da567019c947599006a06b3834265db1481129752f015629ef72fea6f862d01323ce9d024
2024-10-07 17:15:04 +00:00
BinChengZhao 2424b654d5 feat: rust-bitcoin supports testnet4 2024-10-05 23:47:21 +08:00
Tobin C. Harding 4d18624435
Update CHANGELOG files
When we create point releases we merge the release tracking PR directly
into the version branch, including the changelog entries. This means the
changes never end up on `master`. We need to make a mental note to
patch `master` anytime we merge a point release PR.

Audit all crates with a non-zero current point release and check we have
the changelog entries on `master`.
2024-10-05 15:45:28 +10:00
spacebear aa1fd5f44c
Update the doc for InputWeightPrediction::weight()
Clarify that the returned weight doesn't include txid, index, or
sequence weights.
2024-10-03 19:44:28 -04:00
spacebear 8fd53c8ecf
Add nested P2WPKH helpers to InputWeightPrediction
Add helpers for input weight predictions corresponding to P2WPKH nested
in a P2SH output (nested segwit).
2024-10-03 19:32:57 -04:00
BinChengZhao afa91a2030 Introduce TestnetVersion enum with only TestnetV3 2024-10-03 18:40:06 +08:00
Tobin C. Harding 3b7ba4f977
Remove the SliceIndex implementation from hash types
If folk really want to index into a hash they can us `as_byte_array`
then index that.

Includes a bump to the version number of `hashes` to `v0.15.0` - this
is because otherwise `secp` won't build since we are breaking an API
that is used in the current release of secp.

Fix: #3115
2024-10-02 10:18:45 +10:00
Tobin C. Harding fed94f8899
Bump version of bitcoin-io to 0.2.0
In preparation for releasing `io v0.2.0` bump the version number,
add a changelog entry, update the lock files, and depend on the new
version in all crates that depend on `io`.
2024-10-02 09:47:10 +10:00
Tobin C. Harding 70264bfcec
Move block::Version to primitives
This is a straight up move of the whole type because there are only
three methods, a getter, a setter, and `is_signalling_soft_fork`.

If we use an extension trait for `is_signalling_soft_fork` then we
have to make the two private associated consts public which is in my
opinion worse.
2024-10-02 09:35:23 +10:00
Tobin C. Harding 819d8d72e8
Stop using private Version constructor
In preparation for moving the `block::Version` type over to `primitives`
stop using the private constructor and inner field. Use the public
getter/setter instead (`to_consensus`and `from_consensus` respectively).
2024-10-02 09:35:23 +10:00
merge-script e8a3c1f01b
Merge rust-bitcoin/rust-bitcoin#3117: Release tracking PR: `bitcoin-units 0.2.0`
07a529a132 Bump version of bitcoin-units to 0.2.0 (Tobin C. Harding)
148711a4c6 units: Use double ## in changelog entries (Tobin C. Harding)
80e600ba0c units: Copy 0.1.2 release notes (Tobin C. Harding)

Pull request description:

  In preparation for releasing `units v0.2.0` bump the version number, add a changelog entry, update the lock files, and depend on the new version in all crates that depend on `units`.

  Close: #3095

ACKs for top commit:
  apoelstra:
    ACK 07a529a132 successfully ran local tests

Tree-SHA512: 98a75d485ded6225551a5fc4b4a14d8efecc76911a720f959044cdd62781024a8787f258f171ed297705f5ab470f9a88a81ad5d255c9e03c1e22857615ad2e6d
2024-10-01 22:51:05 +00:00
merge-script f3fbd0e0b9
Merge rust-bitcoin/rust-bitcoin#3408: Prepare `Witness`
3f3f30d6c7 Use iter instead of accessing content field (Tobin C. Harding)
6389d1cbb3 Stop using push_slice (Tobin C. Harding)
be163eec99 Use Witness::len instead of accessing field (Tobin C. Harding)

Pull request description:

  Prepare `Witness` to be moved to `primitives`.

  This is the first three patches out of #3406. Patch 1 and 2 are internal changes, path 3 is also internal but introduces a slight perf hit by doing multiple writes.

ACKs for top commit:
  apoelstra:
    ACK 3f3f30d6c7 successfully ran local tests

Tree-SHA512: 25e2570a22797dbfa15d6e5af9b72938243192ca264bc5fe82c2f327486e52a73993b3b61ee1161e5d17b01a7f9843960cb4031e6550561de4ecafb9f935e375
2024-10-01 19:42:09 +00:00
merge-script 1c030105d7
Merge rust-bitcoin/rust-bitcoin#3428: CI fixes for latest nightly
c2674caf4c clippy: remove some newly-detected unnecessary returns (Andrew Poelstra)
053a633b27 clippy: change accidental doccomments into correct comments (Andrew Poelstra)

Pull request description:

  Blocking #3427

ACKs for top commit:
  tcharding:
    ACK c2674caf4c

Tree-SHA512: 4e24e988cb27b47354c7f7b3474fc6647386379fe2e7581dde57daab75fd11d3a511084f5d00c7421d42cd40c69ecfaf10764943d97f1594479ae250687fa279
2024-10-01 04:09:49 +00:00
Tobin C. Harding 3f3f30d6c7
Use iter instead of accessing content field
We would like to move the `Witness` to `primitives` however in the
`Encodable` implementation we are currently accessing the private
`content` field.

Instead of accessing `content` we can iterate over the witness elements
and write each individually, this has the same result but does a bunch
of additional calls to `Write::write_all` (via `emit_slice`).

This patch effects performance negatively but makes no changes to the
encoding.
2024-10-01 14:04:01 +10:00
Tobin C. Harding 6389d1cbb3
Stop using push_slice
The `Witness::push_slice` function is called by `Witness::push` after
calling `as_ref`, hence is equivalent for all types that implement
`AsRef<[u8]>`. Also, `push_slice` is a private method on `Witness`.

In preparation for moving `Witness` over to `primitives` stop using
`push_slice` in favour of `push`.

Internal change only.
2024-10-01 14:04:01 +10:00
Tobin C. Harding be163eec99
Use Witness::len instead of accessing field
In preparation for moving the `Witness` oven to `primitives` use the
`len` function instead of accessing the `witness_elements` field.

No logic change, `Witness::len()` returns `witness_elements`.
2024-10-01 14:04:01 +10:00
merge-script 12e4671810
Merge rust-bitcoin/rust-bitcoin#3388: Move `OutPoint` to `primitives`
da0795e590 primitives: Use doc links for OutPoint (Tobin C. Harding)
b079cbafee Move OutPoint to primitives (Tobin C. Harding)
f5c46cd411 Introduce OutPoint extension traits (Tobin C. Harding)
7e5bd5048d Remove docs on deprecated is_null function (Tobin C. Harding)
97b20a2316 Add additional impl block to OutPoint (Tobin C. Harding)

Pull request description:

  Just the minimal move of `OutPoint` to `primitives`.

  The last patch closes #3347

ACKs for top commit:
  apoelstra:
    ACK da0795e590 successfully ran local tests

Tree-SHA512: dced5a6d6bc6af0ce8b4ae4e52c04b45c85eb77a24bb25762ba8ab7deeab1e6b392cc4b258bb14218e8a2af999715dfed45ba94599cb16963a843995a7475917
2024-09-30 21:32:14 +00:00
merge-script 7379eba587
Merge rust-bitcoin/rust-bitcoin#3409: Improve `witness` unit tests
5fab6b178f Rename iter len unit test (Tobin C. Harding)
f6a74ef4af Refactor the serde Witness unit tests (Tobin C. Harding)
9860453b5b Improve Witness consensus encode unit test (Tobin C. Harding)
7e2899d310 Improve Witness::push unit test (Tobin C. Harding)
fe967279e5 Improve witness unit tests for single empty element (Tobin C. Harding)

Pull request description:

  In preparation for moving the `Witness` type over to `primitives` refactor and improve all the unit tests that will be moved, do not touch the ones that will stay behind.

  The first five patches are from #3406, the last is just a re-name of the test function I tried to refactor in ac6fe3a881

ACKs for top commit:
  apoelstra:
    ACK 5fab6b178f successfully ran local tests

Tree-SHA512: bc00f81e3c5cc92ae58dd2fc876d368a487ae6c08cc0735d7227c3a89287e321dbfb5b571b951d0616af0ec7cf9a0ea2d0e724645b1c419933a212ece80a0fbf
2024-09-30 20:31:31 +00:00