Commit Graph

1118 Commits

Author SHA1 Message Date
Tobin C. Harding 0d9c7add4a
Remove unnecessary private extern crate
In #2278 I mistakenly left in the `use extern crate` after removing the
`pub` from it - while not incorrect it is unnecessary.
2023-12-14 08:49:44 +11:00
Andrew Poelstra 6b9f927f7f
Merge rust-bitcoin/rust-bitcoin#2278: Fully encapsulate bitcoinconsensus
43b1ed1b86 Fully encapsulate bitcoinconsensus (Tobin C. Harding)

Pull request description:

  The `bitcoinconsensus` crate is not fully under our control because it exposes code from Core, so we cannot guarantee its stability across versions. To make our semver compliance easier we can fully encapsulate the `bitcoinconsensus` crate so it does not appear in our public API.

  ### Please note that with this applied:

  - The `bitcoinconsenus` crate is no longer exported at the crate root
  - No `bitcoinconsensus` types appear in our public API

ACKs for top commit:
  Kixunil:
    ACK 43b1ed1b86
  apoelstra:
    ACK 43b1ed1b86

Tree-SHA512: 9fc4f01a35396562e980a647784b22667cbd289e45b5c122610d23a1f8bcf0fe8b9c27e33745f14ee010050d4c2d2669b679fb39c7a108e4e86d2c14fd60571a
2023-12-13 15:07:41 +00:00
Tobin C. Harding 43b1ed1b86
Fully encapsulate bitcoinconsensus
The `bitcoinconsensus` crate is not fully under our control because it
exposes code from Core, so we cannot guarantee its stability across
versions. To make our semver compliance easier we can fully encapsulate
the `bitcoinconsensus` crate so it does not appear in our public API.
However, it is useful to have the crate itself exported, here we add an
"unstable" feature and only publicly export the `bitcoinconsensus` crate
if the "unstable" feature is enabled.
2023-12-13 13:37:52 +11:00
Martin Habovstiak a92d49fe33 Implement `CompressedPublicKey`
P2WPKH requires keys to be compressed which introduces error handling
even in cases when it's statically known that a key is compressed. To
avoid it, this change introduces `CompressedPublicKey` which is similar
to `PublicKey` except it's statically known to be compressed.

This also changes relevant code to use `CompressedPublicKey` instead of
`PublicKey`.
2023-12-12 15:16:16 +01:00
Tobin C. Harding f06d12455f
bitcoin: Remove the custom sink
We have a sink in the new `io` crate, use that one and remove the one in
`bitcoin::prelude`.
2023-12-12 11:48:29 +11:00
Tobin C. Harding b503aa1544
Run the formatter
Run `cargo +nightly fmt`, no manual changes. Done separately to make
review of the last patch easier.
2023-12-12 11:48:29 +11:00
Tobin C. Harding 3ca55fb163
Remove qualifying path from Read and Write
There is no advantage in having `io::Read` as opposed to `Read` and
importing the trait. It is surprising that we do so.

Remove `io::` path from `io::Read` and `io::Write`. Some docs keep the
path, leave them as is. Add import `use io::{Read, Write}`.

Refactor only, no logic changes.
2023-12-12 11:48:29 +11:00
Tobin C. Harding ebeb21fa7a
Import fmt::Write using underscore
When we use the `fmt::Write` trait it is just to call its methods, we
can therefore, without any change to the logic, use `as _` when
importing the trait. This prevents naming conflicts.

Done in preparation for importing the `io::Write` trait.
2023-12-12 11:48:29 +11:00
Tobin C. Harding e2dbcb1d28
Use W for writer generic type
Generic types can be single letters, and a writer is conventionally, in
this codebase at least, called `W`.

Use `W` instead of `Write` with no loss of clarity.
2023-12-12 11:48:29 +11:00
Tobin C. Harding 8704d9f0ae
docs: Fix grammar 2023-12-12 11:48:29 +11:00
Andrew Poelstra 199c482b26
Merge rust-bitcoin/rust-bitcoin#1832: Remove Network from AddressInner
1ee989a3af Remove private fmt_internal function (Tobin C. Harding)
923ce7402d Remove Network from AddressInner (Tobin C. Harding)
3490433618 Return error from wpubkey_hash (Tobin C. Harding)
f7ab253ce4 Remove stale comment (Tobin C. Harding)

Pull request description:

  An `AddressInner` struct (contains `Network` field) is created when parsing address strings however address strings do not map 1:1 to `Network` because signet and testnet use the same bech32 prefix "tb".

  We can fix this by inlining the `Payload` variants into `AddressInner` and adding prefix enums for legacy addresses and an `Hrp` for bech32 addresses.

  Fix: #1819

ACKs for top commit:
  Kixunil:
    ACK 1ee989a3af
  apoelstra:
    ACK 1ee989a3af

Tree-SHA512: 1c2749dc929a1e9ad9b9feb01bec5c96b5aec07c6d646d88652deca7abe485907403116e9e29a0ab7dc06223254c4b49a384043284ec0a68fd76f9ab551e9e8a
2023-12-11 18:01:47 +00:00
Andrew Poelstra 4777ec9a90
Merge rust-bitcoin/rust-bitcoin#1225: Add `bitcoin-units` crate
396e049a7a Use InputString instead of String (Tobin C. Harding)
acacf45edf Add ParseDenominationError (Tobin C. Harding)
69e56a64ed Add bitcoin-units crate (Tobin C. Harding)
4ecb1fe7da internals: Add docs to InputString (Tobin C. Harding)
fa8d3002cd internals: Fix docs typo (Tobin C. Harding)

Pull request description:

  Create a new  `bitcoin-units` crate as described [here](https://github.com/rust-bitcoin/rust-bitcoin/issues/550#issuecomment-1012103022).

  Only the `amount` module is currently included.

  I've resolved the `Encodale/Decodable` issue by keeping the `amount` module in `bitcoin`.

ACKs for top commit:
  Kixunil:
    ACK 396e049a7a
  apoelstra:
    ACK 396e049a7a

Tree-SHA512: caf5e9da0458435ab19d00d4506896257e898525a4472d435fdac1d1a37bb747befd56993b106673f938475e5777d952a13ba04a2d3cb710d7afe7f5faebb7b8
2023-12-11 17:54:30 +00:00
Andrew Poelstra e0886e6a5f
Merge rust-bitcoin/rust-bitcoin#2263: `TaprootMerkleBranch` improvements
e1cc98986c Put `#[inline]` on trivial functions (Martin Habovstiak)
e531fa612b Move `TaprootMerkleBranch` and impl `IntoIterator` (Martin Habovstiak)
9d23c1d0a8 Implement std traits for `TaprootMerkleBranch` (Martin Habovstiak)
93b415589d Rename `inner` to `slice`/`vec` (Martin Habovstiak)
bb0f839c2f Lint with nightly (Martin Habovstiak)

Pull request description:

  This contains several improvements to `TaprootMerkleBranch` that make the API more idiomatic.

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

Tree-SHA512: b2bf52b027e7c1f8588c54e8b8d7a5fa54011dc521bd917995011d5fcc16c50a486eb89c0cdae2557a58adbe7708a4f2bc8f4c492e3d88c679f2abf85b1e7c83
2023-12-11 14:46:31 +00:00
Andrew Poelstra c53402790e
Merge rust-bitcoin/rust-bitcoin#2255: Fix: TxOut::minimal_non_dust and Script::dust_value
1b23220d10 Fix: TxOut::minimal_non_dust and Script::dust_value (Jonathan Underwood)

Pull request description:

  Fixes #2192

  TxOut::minimal_non_dust has 3 problems.

  1. There is an invisible dependency on Bitcoin Core's default minrelaytxfee value. It has been made explicit.
  2. There is an off by one error. The dust limit comparison uses < and therefore `+ 1` was not needed. It has been fixed.
  3. It was not returning 0 amount for OP_RETURN outputs.

  Script::dust_value has 2 problems.

  1. The dust amount depends on minrelaytxfee which is configurable in Bitcoin Core. This method was not configurable.
  2. The division operation was done before multiplying the byte amount, which can cause small differences when using uncommon scripts and minrelaytxfee values.

ACKs for top commit:
  Kixunil:
    ACK 1b23220d10
  apoelstra:
    ACK 1b23220d10

Tree-SHA512: eafd5112fbf773d86e094e3a69c519dd32f5074f5c9c63a8d69b1c9796579a8f2c2d11ad0995d8252c25b7fed5cd7c968ab88a70588986981a0a63649d43e197
2023-12-11 13:24:16 +00:00
Tobin C. Harding 69e56a64ed
Add bitcoin-units crate
Add a new crate `bitcoin-units`, move the `amount` module over to it and
re-export all types from `bitcoin::amount` so this as not a breaking
change.
2023-12-11 08:52:31 +11:00
Andrew Poelstra b81faab33d
Merge rust-bitcoin/rust-bitcoin#2269: Remove impossible InvalidParity error variant
c7c553ebc0 Remove impossible InvalidParity error variant (Martin Habovstiak)

Pull request description:

  Since we do `& 1`, only 0 and 1 are possible values, so the error return there can never happen. I made this explicit by manually setting the parity.

  This is a rebase of Steven's change #2163 with a rewrite of `match` to not panic.

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

Tree-SHA512: 5591fda686295f330b6da757a0052687eddec135ac947a2801343f1681bc4fd9f6cfb722ac1339ae6187a8784e7629b5f12cca32b33a81ffc8791b4407b29f85
2023-12-10 14:38:32 +00:00
Andrew Poelstra e235a80c59
Merge rust-bitcoin/rust-bitcoin#2214: Derive Debug for PrivateKey for no-std builds
3d17031725 Derive Debug for PrivateKey for no-std builds (Tobin C. Harding)

Pull request description:

  Currently we derive `impl Debug for PrivateKey` for "std" builds and manually implement an obfuscated version for "no-std" builds. Since we enable the `hashes` feature of `rust-secp` this is unnecessary because secp takes care of obfuscating the secret for us.

ACKs for top commit:
  apoelstra:
    ACK 3d17031725
  Kixunil:
    ACK 3d17031725

Tree-SHA512: 0ce394c6517c51e8964290a980cddd20186d19bcc6cbb8c71aa09b7485d6a0df373960798418184971e1c6e5a6b8f725dd44ebfa7184e31b63faf105dea69725
2023-12-10 14:29:53 +00:00
Fmt Bot 8e7afe5d4a 2023-12-10 automated rustfmt nightly 2023-12-10 00:58:56 +00:00
Andrew Poelstra aeb220ddc2
Merge rust-bitcoin/rust-bitcoin#2178: Move hash types to where they live
801c72e056 Add deprecation comment to hash_types module (Tobin C. Harding)
61351c917f Move impl_asref_push_bytes to internal_macros (Tobin C. Harding)
2b4b66dee3 Move impl_hashencode to internal_macros (Tobin C. Harding)
2a0ac1258a Move the bip158 filter hash types (Tobin C. Harding)
3107f80aac Move transaction hash types (Tobin C. Harding)
61c02ff202 Move block hash types (Tobin C. Harding)

Pull request description:

  Move hash types out of `hash_types` and into the modules where they are primarily used. Adds deprecated re-export so this is not a breaking change.

  Is an alternate solution to #2072

  Resolves: #2072

ACKs for top commit:
  apoelstra:
    ACK 801c72e056
  Kixunil:
    ACK 801c72e056

Tree-SHA512: 4ccac63553de3f7d417213429c0f5c2b7ebc3c2d77a9feb6d4a7daa233565fc62617edf6426a421d251eadc0841235a719bd7fd3f980302c7a2bf3dacb8b4a61
2023-12-10 00:18:11 +00:00
Martin Habovstiak c7c553ebc0 Remove impossible InvalidParity error variant
Since we do `& 1`, only 0 and 1 are possible values, so the error return
there can never happen. I made this explicit by manually setting the
parity.

This is a rebase of Steven's change with a rewrite of `match` to not
panic.
2023-12-09 01:27:36 +01:00
Martin Habovstiak e1cc98986c Put `#[inline]` on trivial functions
These functions either delegate to functions with identical signature or
contain condition that may be optimized-out after inlining.
2023-12-09 00:35:18 +01:00
Martin Habovstiak e531fa612b Move `TaprootMerkleBranch` and impl `IntoIterator`
Since the iterator created by `IntoIterator` should be called `IntoIter`
we move the whole `TaprootMerkleBranch` to its own module which contains
the type to avoid confusion. This has an additional benefit of reducing
the scope where the invariant could be broken. This already uncovered
that our internal code was abusing access to the private field (although
the code was correct).

To implement the iterator we simply delegate to `vec::IntoIter`,
including overriding the default method which are likely to be
implemented by `Vec` more optimally. We avoid exposing `vec::IntoIter`
directly since we may want to change the representation (e.g. to
`ArrayVec`).
2023-12-09 00:32:22 +01:00
Martin Habovstiak 9d23c1d0a8 Implement std traits for `TaprootMerkleBranch`
The type is naturally a collection of hashes so make it behave that way
by implementing `Deref`, `AsRef`, `Borrow` and their mutable versions as
well as `IntoIterator` for its reference. `IntoIterator` for itself is
not yet implemented because it's a bit more complicated.
2023-12-09 00:30:21 +01:00
Martin Habovstiak 93b415589d Rename `inner` to `slice`/`vec`
These names are more descriptive.
2023-12-08 13:22:47 +01:00
Martin Habovstiak bb0f839c2f Lint with nightly
While `clippy` now allows `TBD` to be used in `since` parameter of
`deprecated` attribute it is only available in the newest, nightly,
version. Switch `clippy` version to nightly to enable the `TBD` value.
2023-12-08 13:22:41 +01:00
Jonathan Underwood 1b23220d10
Fix: TxOut::minimal_non_dust and Script::dust_value
TxOut::minimal_non_dust has 3 problems.

1. There is an invisible dependency on Bitcoin Core's default minrelaytxfee value. It has been made explicit.
2. There is an off by one error. The dust limit comparison uses < and therefore `+ 1` was not needed. It has been fixed.
3. It was not returning 0 amount for OP_RETURN outputs.

Script::dust_value has 2 problems.

1. The dust amount depends on minrelaytxfee which is configurable in Bitcoin Core. This method was not configurable.
2. The division operation was done before multiplying the byte amount, which can cause small differences when using uncommon scripts and minrelaytxfee values.
2023-12-07 22:55:22 -07:00
Tobin C. Harding b058030384
Add deprecated bip32 types back in
In the 0.31.0 release we renamed the bip32 extended key types without
leaving the originals in there marked as deprecated. This makes for a
bad experience for devs, add them back in.
2023-12-08 06:13:46 +11:00
Andrew Poelstra db37bd27a1
Merge rust-bitcoin/rust-bitcoin#2085: Update docs on witness_mut
98ce46c009 Update docs on witness_mut (Tobin C. Harding)

Pull request description:

  Recently during the rust-bitcoin workshop at TABConf devs were thrown off by the example on `witness_mut`.  We have some work going on to add examples and a cookbook that all demonstrate usage of `witness_mut`.

  Remove the docs on `witness_mut` and direct devs to the `examples/sign-tx-*` files.

ACKs for top commit:
  apoelstra:
    ACK 98ce46c009
  Kixunil:
    ACK 98ce46c009

Tree-SHA512: e662213db4cbdaa53f6927cc1b10c1b6276f538cc6ad0d4bfff6dfcbf042f287a14bf5bfc88eeba7a32646c3d6741c5e09d11bb76666572a12a2043db55a2f38
2023-12-07 13:45:26 +00:00
Tobin C. Harding 98ce46c009
Update docs on witness_mut
Recently during the rust-bitcoin workshop at TABConf devs were thrown
off by the example on `witness_mut`.

Attempt to improve the docs on `witness_mut`.
2023-12-07 09:06:54 +11:00
Andrew Poelstra e09ef5cf12
Merge rust-bitcoin/rust-bitcoin#2156: Taproot sig on stack
0ac9ad16ce Add `taproot::SerializedSignature` (Martin Habovstiak)
dffa51e735 Move taproot module to a subdirectory (Martin Habovstiak)

Pull request description:

  Previously `taproot::Signature` could be only serialized into `Vec<u8>`
  which forced allocation. This adds a `SerializedSignature` type which
  acts like `Box<u8>` but is on stack.

  Note: the code was copied from `secp256k1::ecdsa::serialized_signature`
  with minimal changes.

ACKs for top commit:
  apoelstra:
    ACK 0ac9ad16ce
  tcharding:
    ACK 0ac9ad16ce

Tree-SHA512: e3d24f4ddd8074d477c25f5378c3f57dd266405380cc54596104effbad96e7abdb201e032b4b70cdbbaac595d9ae9c4043fca79d275ce62f9f6b221e6783956e
2023-12-06 21:52:07 +00:00
Martin Habovstiak 0ac9ad16ce Add `taproot::SerializedSignature`
Previously `taproot::Signature` could be only serialized into `Vec<u8>`
which forced allocation. This adds a `SerializedSignature` type which
acts like `Box<u8>` but is on stack.

Note: the code was copied from `secp256k1::ecdsa::serialized_signature`
with minimal changes.
2023-12-06 11:02:35 +01:00
Martin Habovstiak dffa51e735 Move taproot module to a subdirectory
This is in preparation for adding more submodules.
2023-12-06 11:02:35 +01:00
Tobin C. Harding b72f1d70e5
bitcoin: Add DO_FEATURE_MATRIX
Add a feature matrix section to the `bitcoin` CI script as we do in
`hashes`. This means:

- test with no default features
- test with all individual features
- test with all combinations of two features

Note, with this applied all features and optional dependencies are
included in `FEATURES` (excluding `secp-lowmemory`).

The feature matrix test gets run for stable and MSRV toolchains.
2023-12-06 10:09:05 +11:00
Tobin C. Harding 48879e7ad9
Remove no-std feature
Currently `bitcoin` cannot be built with no features enabled, it must
have either "no-std" or "std" enabled. This is an artifact from when
we depended on `core2` for "no-std", now that we have our own `io` crate
and we unconditionally depend on it we can remove the "no-std" feature.
2023-12-06 09:54:33 +11:00
Tobin C. Harding 801c72e056
Add deprecation comment to hash_types module
The `hash_types` module has been emptied, it now contains only
deprecated re-exports. Add a rustdoc comment stating as such.
2023-12-05 15:01:18 +11:00
Tobin C. Harding 61351c917f
Move impl_asref_push_bytes to internal_macros
We are emptying the `hash_types` module. `impl_asref_push_bytes!` is an
internal macro, as such it can live in the `internal_macros` module.

While we are at it import the macro and call it without any qualifying
path, this is typical for our usage of other internals/internal_macros
usage.
2023-12-05 15:01:17 +11:00
Tobin C. Harding 2b4b66dee3
Move impl_hashencode to internal_macros
We are emptying the `hash_types` module. `impl_hashencode!` is an
internal macro, as such it can live in the `internal_macros` module.
2023-12-05 15:01:17 +11:00
Tobin C. Harding 2a0ac1258a
Move the bip158 filter hash types
We would like all the various hash types to be defined where they
rightly live instead of in the `hash_types` module.

Move the BIP-158 filter hash types to the `bip158` module.
2023-12-05 15:01:17 +11:00
Tobin C. Harding 3107f80aac
Move transaction hash types
We would like all the various hash types to be defined where they
rightly live instead of in the `hash_types` module.

Move transaction hash types to the `transaction` module.
2023-12-05 14:57:48 +11:00
Tobin C. Harding 61c02ff202
Move block hash types
We would like all the various hash types to be defined where they
rightly live instead of in the `hash_types` module.

Move the block hash types to the `block` module. While moving, add full
stops to the rustdoc of each hash.

Re-export _all four_ types from lib.rs (previously `WitnessMerkleNode`
was not re-exported).
2023-12-05 14:57:28 +11:00
Tobin C. Harding 1ee989a3af
Remove private fmt_internal function
Just use `fmt::Display::fmt` directly since `fmt_internal` does exactly
that.

Refactor only, no logic changes.
2023-12-05 09:27:15 +11:00
Tobin C. Harding 923ce7402d
Remove Network from AddressInner
An `AddressInner` struct is created when parsing address strings however
address strings do not map 1:1 to `Network` because signet and testnet
use the same bech32 prefix "tb".

We can fix this by inlining the `Payload` variants into `AddressInner`
and adding prefix enums for legacy addresses and a `KnownHrp` for bech32
addresses.

Also enables removing the `AddressEncoding` struct as we can display the
`AddressInner` struct directly. (The `Display` impl is on `AddressInner`
and not directly on address to ignore the `NetworkValidation` wrapper,
may be able to be simplified still further.)
2023-12-05 09:27:15 +11:00
Tobin C. Harding 3490433618
Return error from wpubkey_hash
Calling `wpubkey_hash` on a key that is uncompressed is flat out an
error, really it is a programmer error at build time because a segwit
key should never be compressed, however, for historical reasons we do
not enforce this in the type system. As a step towards clarity make it
an error to call `wpubkey_hash` on a an uncompressed pubkey. This adds
documentation and potentially might assist debugging for newer devs.
2023-12-05 09:21:51 +11:00
Tobin C. Harding f7ab253ce4
Remove stale comment
This comment appears to come from before we had types for tweaked and
untweaked keys in taproot. We can remove it.
2023-12-05 09:21:51 +11:00
Tobin C. Harding 7d71fb9fdb
Re-order dependencies in manifest
Currently the feature enabling is different for "std" and "no-std",
which is again different to the order in the dependencies section. These
two things make reading the manifest harder than it needs to be.

Put the dependencies in alphabetic order in the dependencies section as
well as when enabling them.

Refactor only, no logic changes.
2023-12-04 14:21:06 +11:00
apoelstra b7604dd768 2023-12-03 automated rustfmt nightly 2023-12-03 00:58:10 +00:00
Andrew Poelstra a3f6f53d37
Merge rust-bitcoin/rust-bitcoin#2234: Inline io module in the io crate root
f764a607ac Use conventional import path for io crate (Tobin C. Harding)
5c0759a390 Inline io module in io crate root (Tobin C. Harding)
80fe9b99b2 Move public macros to a separate module (Tobin C. Harding)

Pull request description:

  Its not immediately obvious why we nest the whole `io` code in an `io` submodule within `lib.rs`. As far as I can tell we can inline it and re-export from `rust-bitcoin` same as we do for our other dependencies.

  This change would effect other users of the crate but since the `io` crate is unreleased this effects no-one except us.

  After doing this it might be because `crate::io::Foo` looks good when near `std::io::Foo`?

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

Tree-SHA512: 38888b0c23d5f2cd874f77dd332fe4fa4b9acb90e3a2dac19e62ed3d98151acd7480c719aa85434e1a3de987af2c4f565528a914a14d5fd3f0f0e410cbdf5d40
2023-11-30 19:16:17 +00:00
Tobin C. Harding f764a607ac
Use conventional import path for io crate
We have a convention in `rust-bitcoin` to use external crates directly
when importing them not via `crate::foo`.

Update all the import paths for `io` to use this form.
2023-11-29 08:48:03 +11:00
Andrew Poelstra 8d32a49ac1
Merge rust-bitcoin/rust-bitcoin#2228: Rename from_vb_const
fcc4c40a1c Rename from_vb_const (yancy)

Pull request description:

  The new function is more clear because the purpose of the function is to return a value that doesn't need to be unwrapped.  The current MSRV does not allow unwrap() in const context.

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

Tree-SHA512: 62bbd61800e9f29768d884dbe3bca14fea9b51b8f413131e0f29bfc0f0d0e20631d30489e078cc948f2dba0c5d7d9d7c229b4bb7187faef23083a88337efb6a6
2023-11-28 20:33:34 +00:00
yancy fcc4c40a1c Rename from_vb_const
The new function is more clear because the purpose of the function is to
return a value that doesn't need to be unwrapped.  The current MSRV does
not allow unwrap() in const context.
2023-11-28 09:01:03 +01:00
Tobin C. Harding 5c0759a390
Inline io module in io crate root
Its not immediately obvious why we nest the whole `io` code in an `io`
submodule within `lib.rs`. As far as I can tell we can inline it and
re-export from `rust-bitcoin` same as we do for our other dependencies.

This change would effect other users of the crate but since the `io`
crate is unreleased this effects no-one except us.
2023-11-28 14:17:14 +11:00
conduition 32eb461523 add conversions from TXIDs to merkle nodes 2023-11-27 00:12:16 +00:00
Andrew Poelstra cfa6768e79
Merge rust-bitcoin/rust-bitcoin#2221: Implement LowerHex and UpperHex for CompactTarget
58710dfb91 Implement LowerHex and UpperHex for CompactTarget (Vojtěch Toman)

Pull request description:

  closes #2219

ACKs for top commit:
  Kixunil:
    ACK 58710dfb91
  apoelstra:
    ACK 58710dfb91

Tree-SHA512: 38d8bd6573f0f033f5f0948062174f7a49db02d788a5176375a869633984451651bc738cd0588d5c6e4515f521257899bdf9f61fd4be350d80a26a96f16b19b1
2023-11-26 14:32:47 +00:00
Andrew Poelstra 4806461c75
Merge rust-bitcoin/rust-bitcoin#2188: Bump MSRV to Rust version 1.56.1
761de886be Remove imports of TryFrom and TryInto (Tobin C. Harding)
4d5415f835 Add rust-version to the workspace manifests (Tobin C. Harding)
a41e978855 Update to edition 2021 (Tobin C. Harding)
d9cc724187 Bump MSRV to Rust version 1.56.1 (Tobin C. Harding)

Pull request description:

  Rust version 1.56.0 introduced edition 2021. Shortly afterwards, on October 21 2021 Rust version 1.56.1 was released.

  Debian stable is currently shipping `rustc 1.63.0`. Our stated MSRV policy is: In Debian stable and at least 2 years old. Therefore our MSRV policy is met by Rust version 1.56.1 and we can strat to bump our MSRV org wide. Start by bumping the `rust-bitcoin` and `hashes` MSRV to Rust 1.56.1

  Start by bumping the `rust-bitcoin` and `hashes` MSRV to Rust 1.56.1, includes:

  - Update docs.
  - Update CI and remove pinning.
  - Update the build files and remove now stale cfg attributes rust_v_1_x for values less than the new MSRV.
  - Use new `IntoIterator` for arrays so we no longer need to allocate a vector to iterate.

  Links:

  - https://blog.rust-lang.org/2021/11/01/Rust-1.56.1.html
  - https://blog.rust-lang.org/2021/10/21/Rust-1.56.0.html
  - https://packages.debian.org/stable/rust/rustc

ACKs for top commit:
  Kixunil:
    ACK 761de886be
  apoelstra:
    ACK 761de886be

Tree-SHA512: 3a81c8bfa37d8cec0ec794f516f014da67ae8e437decf149c9681aa547885acac0ee07ea2c0f42e4f6bfd6f7ed1695fcf4747f53cc50e5f4e70ce3fe7bcba4e9
2023-11-26 13:48:23 +00:00
Vojtěch Toman 58710dfb91
Implement LowerHex and UpperHex for CompactTarget 2023-11-25 23:26:57 +01:00
Tobin C. Harding 761de886be
Remove imports of TryFrom and TryInto
Now that MSRV is Rust 1.56.1 we no longer need to explicitly import
`TryFrom` and `TryInto`.

No clue why clippy didn't find these for us.
2023-11-24 03:52:05 +11:00
Andrew Poelstra 71d92bdbb9
Merge rust-bitcoin/rust-bitcoin#2095: bitcoin: Add signing examples
fa104aefa5 bitcoin: Add signing examples (Tobin C. Harding)

Pull request description:

  Add two signing examples to showcase signing a simple one input two output transaction using both segwit v0 outputs and taproot outputs.

  This patch is the result of the recent rust-bitcoin TABConf workshop, with bug fix by Sanket, updated to use APIs from tip of master branch.

  This code, depending on v0.30.0 is what was added to the cookbook.

ACKs for top commit:
  realeinherjar:
    ACK fa104aefa5
  apoelstra:
    ACK fa104aefa5

Tree-SHA512: ce0d5b8291c94387c68b5e1cf740d3267fc00c997af5b96f5be525f348140d9a9af17ab66d556990f09bf081a5a812374cb633ea276100c7c21f218b85eae3fd
2023-11-22 22:08:32 +00:00
Andrew Poelstra 2664f978f3
Merge rust-bitcoin/rust-bitcoin#2213: Fix InputWeightPrediction::P2WPKH_MAX constant DER sig length
f41ebc2149 Add test for input weight predictions (conduition)
4514a80a23 Fix the InputWeightPrediction constants for DER signatures (conduition)
b5ce219c62 add weight method to InputWeightPrediction (conduition)

Pull request description:

  The `P2WPKH_MAX` constant assumed DER signatures in the witness have a max length of 73. In practice, their maximum length is 72, because [BIP62](https://github.com/bitcoin/bips/blob/master/bip-0062.mediawiki) forbids nodes from relaying transactions which contain non-canonical ECDSA signatures (i.e. TX sigs must have an $s$ value of less than $\frac{n}{2}$).

  This means $s$ is never encoded with a leading zero byte, and the signature as a whole never exceeds 72 bytes in total encoded length. The `ground_p2wpkh` function was already correct; only the constant needed to be corrected.

  Technically 73 bytes *is* the upper limit for signatures, as nothing forbids miners from including such non-standard transaction signatures in blocks, but for the purposes of fee estimation and input weight prediction, 72 is the number which 99.9% of implementations should use as their ceiling. We already use it as the ceiling for the `ground_p2wpkh` function - `ground_p2wpkh(0)` returns a prediction which uses a witness signature of length 72.

  Reference:
  - https://bitcoin.stackexchange.com/questions/77191/what-is-the-maximum-size-of-a-der-encoded-ecdsa-signature
  - https://bitcoin.stackexchange.com/questions/106435/are-high-s-ecdsa-signatures-forbidden-in-segwit-witnesses
  - https://github.com/bitcoin/bips/blob/master/bip-0062.mediawiki

  To enable testing, I added a `weight()` method to `InputWeightPrediction` and made it public but i'm not sure whether it has a use-case. Let me know if I should make it private instead.

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

Tree-SHA512: 10e837bad9881c0efebb0598eaefd4ab039f2a6ececead75a68e253d84f5e85cb30496a6069eee8dfe9714773f3aa23cfe373f5d88d1c5609e1b1be1ff142e37
2023-11-22 20:36:11 +00:00
Tobin C. Harding 4d5415f835
Add rust-version to the workspace manifests
Add `rust-version = 1.56.1` to all crates in the workspace i.e.,
including `fuzz` but excluding the various test crates.
2023-11-23 06:20:04 +11:00
Tobin C. Harding a41e978855
Update to edition 2021
We just bumped the MSRV to Rust 1.56.1 which includes edition 2021.

Update all crates in this repo to use edition 2021 and build/lint
warnings.
2023-11-23 06:20:03 +11:00
Tobin C. Harding d9cc724187
Bump MSRV to Rust version 1.56.1
Rust version 1.56.0 introduced edition 2021. Shortly afterwards, on
October 21 2021 Rust version 1.56.1 was released.

Debian stable is currently shipping `rustc 1.63.0`.

Our stated MSRV policy is: In Debian stable and at least 2 years old.

Therefore our MSRV policy is met by Rust version 1.56.1 and we can strat
to bump our MSRV org wide.

Start by bumping the `rust-bitcoin` and `hashes` MSRV to Rust 1.56.1,
includes:

- Update docs.
- Update CI and remove pinning.
- Update the build files and remove now stale cfg attributes rust_v_1_x
  for values less than the new MSRV.
- Use new `IntoIterator` for arrays so we no longer need to allocate a
  vector to iterate.

Links:

- https://blog.rust-lang.org/2021/11/01/Rust-1.56.1.html
- https://blog.rust-lang.org/2021/10/21/Rust-1.56.0.html
- https://packages.debian.org/stable/rust/rustc
2023-11-23 06:20:02 +11:00
Andrew Poelstra ba318f167a
Merge rust-bitcoin/rust-bitcoin#2093: Manually implement `JsonSchema`
75c490c60f hashes: Remove default features from schemars dep (Tobin C. Harding)
1105876423 Remove whitespace character from string (Tobin C. Harding)
a6d7d542ab bitcoin:: Remove dev dependency serde_derive (Tobin C. Harding)

Pull request description:

  Done while investigating removal of `serde_derive` dependency.

  - Patch 1: Do trivial dev-dep removal
  - Patch 2: Manually implement `JsonSchema` and remove default dependencies from "schemars" dependency (transitively depends on `serde_derive`)

ACKs for top commit:
  apoelstra:
    ACK 75c490c60f

Tree-SHA512: aab5bd622a76fc24259933af2f20f863d20c8ccf6e69e68246c374266c540e483ced8a769532582a184b922996857db7320a6b08ae9b5b95503eac752ef9d301
2023-11-22 18:55:41 +00:00
Andrew Poelstra aeac9bbd87
Merge rust-bitcoin/rust-bitcoin#2206: Add from_vb_const function
321d3923b8 Add from_vb_const function (yancy)

Pull request description:

  This function is can be used to construct a Weight type from_vb in const context.  Note I don't think it's possible to test the panic case since it's a compile time error work around currently to panic.

ACKs for top commit:
  tcharding:
    ACK 321d3923b8
  apoelstra:
    ACK 321d3923b8

Tree-SHA512: dc11409f0e3079400da261a8c9f580ef0527b77643ce1a5dda65c0975db19c2f2da46ac693e6a2bf49e0105b8b096e1ee51f09f5d1c78d634e4e274d7467ee05
2023-11-22 14:44:59 +00:00
conduition f41ebc2149 Add test for input weight predictions
Sanity checks the InputWeightPrediction against
a transaction which uses P2WPKH inputs.
2023-11-22 00:50:59 +00:00
conduition 4514a80a23 Fix the InputWeightPrediction constants for DER signatures
The P2WPKH_MAX constant assumed DER signatures in the witness have
a max length of 73. However, their maximum length in practice is 72,
because BIP62 forbids nodes from relaying transactions whose ECDSA
signatures are not canonical (i.e. all sigs must have an s value of
less than n/2). This means s is never encoded with a leading zero
byte, and the signature as a whole never exceeds 72 bytes in total
encoded length. The ground_p2wpkh function was already correct;
only the constant needed to be corrected.
2023-11-21 06:13:08 +00:00
conduition b5ce219c62 add weight method to InputWeightPrediction
This method computes the weight an InputWeightPrediction
would to a transaction, not including witness flag bytes.
2023-11-21 05:57:46 +00:00
yancy 321d3923b8 Add from_vb_const function
This function can be used to construct a Weight type from_vb in const
context.
2023-11-21 06:23:32 +01:00
Tobin C. Harding 3d17031725
Derive Debug for PrivateKey for no-std builds
Currently we derive `impl Debug for PrivateKey` for "std" builds and
manually implement an obfuscated version for "no-std" builds. Since
we enable the `hashes` feature of `rust-secp` this is unnecessary
because secp takes care of obfuscating the secret for us.
2023-11-21 14:51:05 +11:00
Andrew Poelstra 8aa5501827
Merge rust-bitcoin/rust-bitcoin#2202: Automated nightly rustfmt (2023-11-19)
f5882ef3c6 2023-11-19 automated rustfmt nightly (apoelstra)

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 f5882ef3c6

Tree-SHA512: 4efc31ae0281dc824181177b39154f4a53475367a0e83fcbdcc4ab99cf68aefa379c850e49ac1a5d11fbd5f4fc62afa6d56393e0c6286e6ff3cae7f27583fbda
2023-11-20 14:46:26 +00:00
Tobin C. Harding a6d7d542ab
bitcoin:: Remove dev dependency serde_derive
We do not need this dependency because we can get the serde derives
directly from `serde`.

diff --git a/bitcoin/Cargo.toml b/bitcoin/Cargo.toml
index 3868bd08..db7fb322 100644
--- a/bitcoin/Cargo.toml
+++ b/bitcoin/Cargo.toml
@@ -53,7 +53,6 @@ actual-serde = { package = "serde", version = "1.0.103", default-features = fals
 [dev-dependencies]
 serde_json = "1.0.0"
 serde_test = "1.0.19"
-serde_derive = "1.0.103"
 bincode = "1.3.1"

 [target.'cfg(mutate)'.dev-dependencies]
2023-11-20 15:17:30 +11:00
Andrew Poelstra 675da34127
Merge rust-bitcoin/rust-bitcoin#2066: Add a `bitcoin-io` crate
add371d263 Remove `core2` dependency entirely (Matt Corallo)
b7dd16da99 [IO] Use our own io::Error type (Matt Corallo)
c95b59327a Explicitly use `std::io::Error` when implementing `std` traits (Matt Corallo)
9e1cd372cb Use `io::Error::get_ref()` over `std::error::Error::source()` (Matt Corallo)
3caaadf9bb [IO] Replace the `io::Cursor` re-export with our own `Cursor` (Matt Corallo)
141343edb4 [IO] Move to custom `Read` trait mirroring `std::io::Read` (Matt Corallo)
7395093f94 Stop relying on `Take`'s `by_ref` method (Matt Corallo)
2364e1a877 Stop relying on blanket Read impl for all &mut Read (Matt Corallo)
6aa7ccf841 [IO] Replace `std::io::Sink` usage with our own trivial impl (Matt Corallo)
7eb5d65bda [IO] Provide a macro which implements `io::Write` for types (Matt Corallo)
ac678bb435 [IO] Move to custom `Write` trait mirroring `std::io::Write` (Matt Corallo)
5f2395ce56 Add missing `?Sized` bounds to `io::Write` parameters (Matt Corallo)
2348449d2a Stop relying on `std::io::Write`'s `&mut Write` blanket impl (Matt Corallo)
5e0209569c Use `io::sink` rather than our custom `EmptyWrite` utility (Matt Corallo)
a0ade883b6 [IO] Move io module into selected re-exports (Matt Corallo)
27c7c4e26a Add a `bitcoin_io` crate (Matt Corallo)

Pull request description:

  In order to support standard (de)serialization of structs, the
  `rust-bitcoin` ecosystem uses the standard `std::io::{Read,Write}`
  traits. This works great for environments with `std`, however sadly
  the `std::io` module has not yet been added to the `core` crate.

  Thus, in `no-std`, the `rust-bitcoin` ecosystem has historically
  used the `core2` crate to provide copies of the `std::io` module
  without any major dependencies. Sadly, its one dependency,
  `memchr`, recently broke our MSRV.

  Worse, because we didn't want to take on any excess dependencies
  for `std` builds, `rust-bitcoin` has had to have
  mutually-exclusive `std` and `no-std` builds. This breaks general
  assumptions about how features work in Rust, causing substantial
  pain for applications far downstream of `rust-bitcoin` crates.

  This is mostly done, I'm still finalizing the `io::Error` commit at the end to drop the `core2` required dep in no-std, but its getting there. Would love further feedback on the approach or code-level review on these first handful of commits.

ACKs for top commit:
  tcharding:
    ACK add371d263
  apoelstra:
    ACK add371d263
  Kixunil:
    ACK add371d263

Tree-SHA512: 18698ea8b1b65108ee0f695d5062d2562c8df2f50bf85d93442648da3b35a4184a5d5d2a493aed0adaadc83f663f0cd2ac735c34941cc9a6fa58d826e548e091
2023-11-19 14:26:19 +00:00
apoelstra f5882ef3c6 2023-11-19 automated rustfmt nightly 2023-11-19 00:58:32 +00:00
Andrew Poelstra c12debfd0c
Merge rust-bitcoin/rust-bitcoin#2172: Add `params` method to `Network`
9282cc4dad Implement standard conversions `Network`->`Params` (Martin Habovstiak)
9a8694fae5 Add `params` method to `Network` (Martin Habovstiak)

Pull request description:

  Writing `network.params()` is less annoying than `Params::network()`, so this adds it. Making it return a static could also improve performance.

  Didn't do `Params` -> `Network` conversions because of #2173

ACKs for top commit:
  tcharding:
    ACK 9282cc4dad
  apoelstra:
    ACK 9282cc4dad

Tree-SHA512: 6455956fd2c937b7212c9bab6ac7cfa05fb99b5da955f4f6690d7056cbe3902a3dadf94352c76b6866655b2e34a936191362a1cc81b33a5b252dd21dbc84d7b6
2023-11-18 18:22:07 +00:00
Andrew Poelstra c03ef3c219
Merge rust-bitcoin/rust-bitcoin#2194: Script documentation weirdness and typos
e3f2c4fa43 Fix broken link in CONTRIBUTING.md (Vojtěch Toman)
e1c4986f4a Improve Script documentation and fix typos (Vojtěch Toman)

Pull request description:

  Fixes #2193 (first commit)
  Second commit fixes broken link in `CONTRIBUTING.md`

ACKs for top commit:
  Kixunil:
    ACK e3f2c4fa43
  sanket1729:
    ACK e3f2c4fa43

Tree-SHA512: f7bd83530a071a37028c611afa1dc43de31e57b241403fa9f451be375da3db041f41dc7e07d581d770c76ab7c7a7cc68e27e68bbfc71461fe933128e7b846ae9
2023-11-16 13:25:42 +00:00
Andrew Poelstra 43cd352cf9
Merge rust-bitcoin/rust-bitcoin#2185: add input weight predictions for p2pkh outputs
c745c97e5f add input weight predictions for p2pkh outputs (conduition)

Pull request description:

  Adds input weight prediction constant and `ground_p2pkh_*` methods, mirroring those for `P2WPKH`. This seemed to be missing.

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

Tree-SHA512: 69b4484686ecf761b766d2a7d7408c784981a9ba8c4aa8abd9d8655bd9421eb882e346ece232530edf9edff602d2fe1570992a5eb7b420b928d8b13397d2f60f
2023-11-15 23:48:05 +00:00
conduition c745c97e5f add input weight predictions for p2pkh outputs
Adds missing prediction constants and const fns for
predicting the weights for P2PKH transaction inputs,
covering both compressed and uncompressed public keys.
2023-11-15 22:16:55 +00:00
Vojtěch Toman e1c4986f4a
Improve Script documentation and fix typos 2023-11-15 20:57:22 +01:00
Andrew Poelstra c0de0f7bde
Merge rust-bitcoin/rust-bitcoin#2120: Improve public re-exports
7d695f6b41 Improve public re-exports (Tobin C. Harding)
33774122e0 Remove public re-exports from private module (Tobin C. Harding)

Pull request description:

  Improve the public exports in two ways:

  1. Inline re-exports into the docs of the module that re-exports them.
  2. Separate public and private use statements

  Recently we discussed a way to separate the public and private import statements to make the code more clear and prevent `rustfmt` joining them all together.

  Separate public exports using a code block and `#[rustfmt::skip]`. Has the nice advantage of reducing the number of `#[doc(inline)]` attributes also.

  1. Modules first, as they are part of the project's structure.
  2. Private imports
  3. Public re-exports (using `rustfmt::skip` to prevent merge)

  Use the format

  ```rust
  mod xyz;
  mod abc;

  use ...;

  pub use {
      ...,
  };
  ```

  This patch introduces changes to the rendered HTML docs.

ACKs for top commit:
  apoelstra:
    ACK 7d695f6b41

Tree-SHA512: dc9121c0fe282e3035d862beadb89e2d5a374a7dab6b1c3147a9b5960f8bc2f5af49892f0f713f55c645c46f53464c32daf390c11d85c75553b3ea7e0efc8246
2023-11-15 13:51:51 +00:00
conduition 6c6c08ca50 add second test case 2023-11-10 17:19:33 +00:00
conduition 0c56131819 fix: FeeRate::checked_mul_by_weight should scale output down by 1000 2023-11-09 19:20:34 +00:00
Matt Corallo add371d263 Remove `core2` dependency entirely 2023-11-09 16:46:44 +00:00
Matt Corallo c95b59327a Explicitly use `std::io::Error` when implementing `std` traits
In the next commit, `std::io::Error` will be replaced with a
different type, and as a result `std::io::Error` must be referred
to explicitly.
2023-11-07 17:35:18 +00:00
Matt Corallo 9e1cd372cb Use `io::Error::get_ref()` over `std::error::Error::source()` 2023-11-07 17:35:18 +00:00
Matt Corallo 3caaadf9bb [IO] Replace the `io::Cursor` re-export with our own `Cursor` 2023-11-07 17:35:17 +00:00
Matt Corallo 141343edb4 [IO] Move to custom `Read` trait mirroring `std::io::Read`
In order to move towards our own I/O traits in the `rust-bitcoin`
ecosystem, we have to slowly replace our use of the `std` and
`core2` traits.

Here we take the second big step, replacing
`{std,core2}::io::Read` with our own `bitcoin_io::io::Read`. We
provide a blanket impl for our trait for all `std::io::Read`, if
the `std` feature is enabled, allowing users who use their own
streams or `std` streams to call `rust-bitcoin` methods directly.
2023-11-07 05:51:39 +00:00
Matt Corallo 7395093f94 Stop relying on `Take`'s `by_ref` method 2023-11-07 05:51:37 +00:00
Matt Corallo 2364e1a877 Stop relying on blanket Read impl for all &mut Read 2023-11-07 05:51:36 +00:00
Matt Corallo 6aa7ccf841 [IO] Replace `std::io::Sink` usage with our own trivial impl 2023-11-07 05:51:36 +00:00
Matt Corallo 5f2395ce56 Add missing `?Sized` bounds to `io::Write` parameters
Since we are no longer relying on the blanket `io::Write` impl for
`&mut io::Write`, we should now ensure that we do not require
`Sized` for our `io::Write` bounds, as its unnecessarily
restrictive and can no longer be worked around by simply adding an
`&mut`.
2023-11-07 05:50:51 +00:00
Matt Corallo 2348449d2a Stop relying on `std::io::Write`'s `&mut Write` blanket impl
`std::io::Write` is implemented for all `&mut std::io::Write`. This
makes it easy to have APIs that mix and match owned `Write`s with
mutable references to `Write`s.

However, in the next commit we add our own `Write` trait which we
intend to implement for all `std::io::Write`. Sadly, this is
mutually exclusive with a blanket implementation on our own
`&mut Write`, as that would conflict with an `std::io::Write`
blanket impl.

Thus, in order to use the `Write for all &mut Write` blanket impl
in rust-bitcoin, we'd have to bound all `Write`s by
`std::io::Write`, as we're unable to provide a blanket
`Write for &mut Write` impl.

Here we stop relying on that blanket impl in order to introduce the
new trait in the next commit.
2023-11-07 05:50:47 +00:00
Matt Corallo 5e0209569c Use `io::sink` rather than our custom `EmptyWrite` utility 2023-11-07 05:50:45 +00:00
Matt Corallo 27c7c4e26a Add a `bitcoin_io` crate
In order to support standard (de)serialization of structs, the
`rust-bitcoin` ecosystem uses the standard `std::io::{Read,Write}`
traits. This works great for environments with `std`, however sadly
the `std::io` module has not yet been added to the `core` crate.

Thus, in `no-std`, the `rust-bitcoin` ecosystem has historically
used the `core2` crate to provide copies of the `std::io` module
without any major dependencies. Sadly, its one dependency,
`memchr`, recently broke our MSRV.

Worse, because we didn't want to take on any excess dependencies
for `std` builds, `rust-bitcoin` has had to have
mutually-exclusive `std` and `no-std` builds. This breaks general
assumptions about how features work in Rust, causing substantial
pain for applications far downstream of `rust-bitcoin` crates.

Here, we add a new `bitcoin_io` crate, making it an unconditional
dependency and using its `io` module in the in-repository crates
in place of `std::io` and `core2::io`. As it is not substantial
additional code, the `hashes` io implementations are no longer
feature-gated.

This doesn't actually accomplish anything on its own, only adding
the new crate which still depends on `core2`.
2023-11-07 05:50:42 +00:00
Andrew Poelstra 966b190f23
Merge rust-bitcoin/rust-bitcoin#2168: Use network when calculating difficulty
12d615d900 Use network when calculating difficulty (Tobin C. Harding)
62af5b54f3 Improve difficulty rustdocs (Tobin C. Harding)

Pull request description:

  The difficulty is a ratio of the max and current targets, since the max is network specific the difficulty calculation is also network specific.

  We already have network specific maximum target constants, use them when calculating the difficulty.

  Patch 1 is a trival docs improvement to `block::Header::difficulty`.

ACKs for top commit:
  Kixunil:
    ACK 12d615d900
  apoelstra:
    ACK 12d615d900

Tree-SHA512: 8b414c975306667309b0918109b3e5e8774496fc4c0f3413709e95ad7499bebf1a017def4c180a2bb5f1750c69bb505d94c738a28525b7ccc8b36e5e42514000
2023-11-06 14:38:00 +00:00
Andrew Poelstra 7b6de6a22b
Merge rust-bitcoin/rust-bitcoin#2170: Remove deprecated since NEXT-RELEASE
01e2233f6c Remove deprecated since NEXT-RELEASE (Tobin C. Harding)

Pull request description:

  Not sure what happened here but our release job didn't catch this? We should have updated this to "since = 0.31.0" before release. Since we only deprecate for one release lets go ahead and remove this.

ACKs for top commit:
  apoelstra:
    ACK 01e2233f6c
  clarkmoody:
    ACK 01e2233f6c
  Kixunil:
    ACK 01e2233f6c

Tree-SHA512: ad362058371e5e8ac7b577c3e32a0c65ce29e5723ff5efbccbcc57684fd61364f3caf7a4c8f0ee8c24bcb7a765bad2539a862860a902e5cec495ed9972379c2d
2023-11-06 14:04:47 +00:00
Andrew Poelstra 9f602a613b
Merge rust-bitcoin/rust-bitcoin#1979: Make `Payload` and `AddressEncoding` private
7f75447c1d Make Payload private and inline functionality (Tobin C. Harding)
b12bf07232 Make the AddressEncoding type private (Tobin C. Harding)

Pull request description:

  The `AddressEncoding` and `Payload` types are implementation details and should never have been public.    Make them private.

  Fix: #1908

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

Tree-SHA512: 37083bc759f32e5187126c4f8d39c9c9cb39bd80a92b2479128da39f4db7672fe0be24a58756a387fe944c63efb4ffacc58c1dac071f3314e882ed0f0e9f5a23
2023-11-06 13:56:56 +00:00
Tobin C. Harding 7f75447c1d
Make Payload private and inline functionality
Currently we have functions on `Address` that call through to a public
`Payload` type. The `Payload` type is an implementation detail and
should never have been public. In preparation for modifying the
`AddressInner` and removing `Payload` altogether lets move all the
functionality from `Payload` into `Address` - this is basically just
code moves so it is feasible to review with some confidence.

This is an API breaking change because it makes `Payload` private and
also removes from the pubic `Address` API functions that accept and
return `Payload`. Apart from that the changes can be seen as
refactoring.
2023-11-06 16:09:11 +11:00
Tobin C. Harding b12bf07232
Make the AddressEncoding type private
The `AddressEncoding` type exists solely to assist us in implementing
`Display` on `Address`, it may have been used in the past by alt-coins
back when we had a more tolerant outlook on supporting them. Nowadays
we explicitly do not support alts.
2023-11-06 16:09:07 +11:00
Martin Habovstiak 9282cc4dad Implement standard conversions `Network`->`Params` 2023-11-05 19:58:15 +01:00
Martin Habovstiak 9a8694fae5 Add `params` method to `Network`
Writing `network.params()` is less annoying than `Params::network()`, so
this adds it. Making it return a static could also improve performance.
2023-11-05 19:57:47 +01:00
Tobin C. Harding 2c33744baa
Remove code deprecated since v0.31.0
We only deprecate for a single release.

Remove all code deprecated since `v0.31.0`.
2023-11-04 12:14:54 +11:00
Tobin C. Harding 01e2233f6c
Remove deprecated since NEXT-RELEASE
Not sure what happened here but our release job didn't catch this? We
should have updated this to "since = 0.31.0" before release. Since we
only deprecate for one release lets go ahead and remove this.
2023-11-04 09:52:52 +11:00
Tobin C. Harding 12d615d900
Use network when calculating difficulty
The difficulty is a ratio  of the max and current targets, since the
max is network specific the difficulty calculation is also network
specific.

We already have network specific maximum target constants, use them when
calculating the difficulty.
2023-11-03 12:05:23 +11:00
Tobin C. Harding 62af5b54f3
Improve difficulty rustdocs
Copy a sentence from the `pow::Target::difficulty` function onto the
`block:Header::difficulty` function.
2023-11-03 11:58:02 +11:00
Andrew Poelstra 071208ccdd
Merge rust-bitcoin/rust-bitcoin#2042: Split Prevouts errors out into specific error types
e21ee381bc Split Prevouts errors out into specific error types (Tobin C. Harding)

Pull request description:

  Done as part of the great error clean up.

  Currently we are returning a general `Error` from `Prevouts` functions, this is un-informative, we can do better by returning specific types that indicate the exact error path.

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

Tree-SHA512: 2a4900f9e31584ad2b6faafa17ea98742fff9206ee1bf77ed29624e0c7b05e655b3b6bf3710e2da26b0b2b8bd5eb36fdd81decbb1f55b41f153f0fbcc4a9165e
2023-11-01 14:20:24 +00:00
Andrew Poelstra df28e2f679
Merge rust-bitcoin/rust-bitcoin#2151: Do trivial docs fixes
d6298fe711 Use capital B for Bitcoin in rustdoc (Tobin C. Harding)
bcfabc3556 Fix typo, missing word (Tobin C. Harding)

Pull request description:

  In an effort to make review merge quicker push these two changes up as a separate PR.

  Totally trivial.

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

Tree-SHA512: 34635ecd87c918f106694a81f50e69dda233000ac616557744466eb58422a2742f35cadbb059f0f81449efd2f61a37ceb71840bf216009914ba2162834e13fc6
2023-10-31 14:30:58 +00:00
Andrew Poelstra 0b1fe094e4
Merge rust-bitcoin/rust-bitcoin#2146: Create uniform build script
fde6479c6a Create uniform build script (yancy)

Pull request description:

  Previously, each unique compiler cfg attribute that appeared in the codebase was hard coded and emitted to stdout at compile time.  This meant keeping the file up to date as different compiler cfg attributes changed.  It's inconsequential to emit a compiler version that's not used, so this change just emits all possibilities to reduce the maintenance burden of the build script.

  Note that there is a bit of diff noise in one of the `build.rs` since I simply did a copy of one to the other to make them uniform.

ACKs for top commit:
  Kixunil:
    ACK fde6479c6a
  tcharding:
    ACK fde6479c6a
  apoelstra:
    ACK fde6479c6a

Tree-SHA512: 401134c168a604a092b72c3980fae6d20adda761273ea47a887cf4c01838536241a45f310cbc2b5941311d533e1d10c848062198af70c0ed619a57973e842840
2023-10-31 14:04:19 +00:00
Tobin C. Harding 7d695f6b41
Improve public re-exports
Improve the public exports in two ways:

1. Inline re-exports into the docs of the module that re-exports them.
2. Separate public and private use statements

Recently we discussed a way to separate the public and private import
statements to make the code more clear and prevent `rustfmt` joining
them all together.

Separate public exports using a code block and `#[rustfmt::skip]`. Has
the nice advantage of reducing the number of `#[doc(inline)]` attributes
also.

1. Modules first, as they are part of the project's structure.
2. Private imports
3. Public re-exports (using `rustfmt::skip` to prevent merge)

Use the format

```rust
mod xyz;
mod abc;

use ...;

pub use {
    ...,
};
```

This patch introduces changes to the rendered HTML docs.
2023-10-31 15:16:47 +11:00
Tobin C. Harding 33774122e0
Remove public re-exports from private module
The `crypto::taproot` module is private, public re-exports are
inaccessible, remove them.
2023-10-31 15:16:47 +11:00
Tobin C. Harding e21ee381bc
Split Prevouts errors out into specific error types
Done as part of the great error clean up.

Currently we are returning a general `Error` from `Prevouts` functions,
this is un-informative, we can do better by returning specific types
that indicate the exact error path.
2023-10-31 14:21:24 +11:00
Tobin C. Harding fa104aefa5
bitcoin: Add signing examples
Add two signing examples to showcase signing a simple one input two
output transaction using both segwit v0 outputs and taproot outputs.

This patch is the result of the recent rust-bitcoin TABConf workshop,
wit bug fix by Sanket, updated to use APIs from tip of master branch.

This code, depending on v0.30.0 is what is being introduced to the
cookbook at the moment.
2023-10-31 10:11:48 +11:00
Tobin C. Harding d6298fe711
Use capital B for Bitcoin in rustdoc
As we do in another part of this file use capital 'B' for Bitcoin.
2023-10-31 08:37:11 +11:00
Tobin C. Harding bcfabc3556
Fix typo, missing word
Add a 'by' to fix the grammar in sentence.
2023-10-31 08:36:09 +11:00
yancy fde6479c6a Create uniform build script
Previously, each unique compiler cfg attribute that appeared in the
codebase was hard coded and emitted to stdout at compile time. This
meant keeping the file up to date as different compiler cfg attributes
changed. It's inconsequential to emit a compiler version that's not
used, so this change just emits all possibilities to reduce the
maintenance burden of the build script.
2023-10-30 14:40:41 +01:00
Tobin C. Harding efedf862b0
bitcoin: Bump version number to v0.31.0
In preparation for release of v0.31.0 bump the version number.

The changelog is already up to date because we have done two RC
releases.
2023-10-28 08:32:30 +11:00
Andrew Poelstra 7246585588
Merge rust-bitcoin/rust-bitcoin#2096: Move psbt macro to the psbt test module
2ecab31f94 Remove stale comment and map_err (yancy)
b166442fb0 Replace hex_psbt macro with test helper function (yancy)
9e4a784b8b Move psbt macro to the psbt test module (yancy)

Pull request description:

  Remove `#[cfg(test)]` and the macro `psbt_with_values` from macros.rs and place it in the tests module for psbt.

ACKs for top commit:
  apoelstra:
    ACK 2ecab31f94
  tcharding:
    ACK 2ecab31f94

Tree-SHA512: 06a55056e864befac8b33968bf4e469c3c7bc20e651ad5bb3b80aa76749169af1266e1d4101d3e9e9bbffe7c860e8b9fcd675a78ca7ae67dc09892c75fba0dd0
2023-10-27 13:17:07 +00:00
lateminer 2a891e0be8
Add a missing link to #2006 in 'bitcoin/CHANGELOG.md' 2023-10-26 21:06:48 +02:00
Andrew Poelstra 1eb6e0c7d8
Merge rust-bitcoin/rust-bitcoin#2134: Add clippy exceptions for needless_question_mark lint
875545517d Add clippy exceptions for needless_question_mark lint (Steven Roose)

Pull request description:

  This lint forces you to write semantically different code that is in most cases inferior, just to save you 5 characters.

  The reason why the code is inferior is because it doesn't do error conversion so it would break when either of the two function signatures changes while in the original code using the `?` operator, nothing would break if the inner error can be converted into the outer error.

ACKs for top commit:
  apoelstra:
    ACK 875545517d
  tcharding:
    ACK 875545517d

Tree-SHA512: 8429e0fb7d759a3d19231e7bcaed61b0988172d931e758a9522d7c994854fd403408bb93b06778a5c09746cd38b6a96d3d2e0a862fb4516f2dbfffffe8735ce0
2023-10-24 01:17:32 +00:00
Steven Roose 875545517d
Add clippy exceptions for needless_question_mark lint 2023-10-23 16:45:52 +01:00
Steven Roose 750ee2ba56
Remove unnecessary clippy attribute on is_sighash_single_bug 2023-10-23 01:41:44 +01:00
Steven Roose f522a0290c
Remove unnecessary clippy attribute on relative::LockTime 2023-10-23 01:37:50 +01:00
Steven Roose b7f11d4493
Remove unnecessary clippy attribute on absolute::LockTime
I ran the clippy locally without it and it doesn't seem to be necessary
anymore.
2023-10-23 01:36:19 +01:00
Andrew Poelstra e436b5b900
Merge rust-bitcoin/rust-bitcoin#2132: Replace helper macro with helper function
b163d9b59a Replace hex_script macro with a helper function (yancy)
7f26439e20 Add track_caller to test helper functions (yancy)
bf08ee4499 Replace helper macro with helper function (yancy)

Pull request description:

  Remove the macro hex_psbt and replace with a function.  Using track_caller to accurately report the test name and line number during a panic is used in place of a macro.

  This is a refactor commit to the test suit.

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

Tree-SHA512: 6955c966d1c37020515ae990e5e0ec154f591ce025321dee71264e4e53cbab38afdb681ca193e626efdb7be4b4e84763cd8baf41b2a1258d34c38acd58713254
2023-10-22 13:16:42 +00:00
yancy b163d9b59a Replace hex_script macro with a helper function
Remove the macro hex_script and replace with a function.  Using
track_caller to accuretly report the test name and line number
during a panic is used in place of a macro.
2023-10-20 10:20:23 +02:00
yancy 7f26439e20 Add track_caller to test helper functions
The test helper files can panic when calling hex_psbt().  hex_psbt()
will report the calling function, instead of the offending test.  Adding
track_caller to functions that call hex_psbt will report the line number
of the failing test.
2023-10-20 09:41:50 +02:00
yancy bf08ee4499 Replace helper macro with helper function
Remove the macro hex_psbt and replace with a function.  Using
track_caller to accuretly report the test name and line number
during a panic is used in place of a macro.
2023-10-20 09:25:00 +02:00
Andrew Poelstra fe07c13bcc
Merge rust-bitcoin/rust-bitcoin#2131: encode: Implement encoding traits on Vec<BlockHeader>
10c1f7b9c6 encode: Implement encoding traits on Vec<BlockHeader> (Steven Roose)

Pull request description:

ACKs for top commit:
  clarkmoody:
    ACK 10c1f7b9c6
  apoelstra:
    ACK 10c1f7b9c6
  vincenzopalazzo:
    ACK 10c1f7b9c6

Tree-SHA512: 32182f4b18a2e4aee20efc4c649827be4e2f61991fae48d7e1360e2c8224bcd98ef89391b50ec2d4e12a720daf7350ca0beb23094153313b668a54cee9cda278
2023-10-19 15:38:54 +00:00
Andrew Poelstra 3a95365f46
Merge rust-bitcoin/rust-bitcoin#2124: Tracking PR for `v0.31.0-rc2` release
38960ab5a5 Bump version to 0.31.0-rc2 (Tobin C. Harding)
79dfe8d270 justfile: Add update-lock-files command (Tobin C. Harding)
178069c13e Add changelog entries for v0.31.0 (Tobin C. Harding)

Pull request description:

  Prepare for the v0.31.0-rc2 release.

  - Add changlog entries
  - Add a `just update-lock-files` command
  - Bump the version ready for next RC release

ACKs for top commit:
  apoelstra:
    ACK 38960ab5a5
  clarkmoody:
    ACK 38960ab5a5

Tree-SHA512: d2d459666117992689ea2bde2ba4a5d9a9cd36a85c5f0df443ceca3bf9d4ec351baffb4be09fbe25bf0767145d11a59b97031e7c8f9182fa9348a6883420b8fe
2023-10-19 13:32:03 +00:00
Steven Roose 10c1f7b9c6
encode: Implement encoding traits on Vec<BlockHeader> 2023-10-18 23:34:56 +01:00
Tobin C. Harding 38960ab5a5
Bump version to 0.31.0-rc2
In preparation for doing the next RC release bump the version.
2023-10-18 13:52:49 +11:00
Tobin C. Harding 178069c13e
Add changelog entries for v0.31.0
Add the remaining changelog entries for the v0.31.0 release. Includes
everything released in v0.31.0-rc1
2023-10-18 13:46:42 +11:00
Andrew Poelstra 37daf4620c
Merge rust-bitcoin/rust-bitcoin#2126: Implement manual fmt::Debug for BlockHeader to include block hash
b108ffa2ec Implement manual fmt::Debug for BlockHeader to include block hash (Steven Roose)

Pull request description:

  I think it makes sense for a block header to have the block hash shown in the debug print.

ACKs for top commit:
  tcharding:
    ACK b108ffa2ec
  vincenzopalazzo:
    ACK b108ffa2ec
  apoelstra:
    ACK b108ffa2ec

Tree-SHA512: 37b77f8b2d8da3903bc5ff329abd45dcb5f189ba2ac38fc309fa477b0eb569b01dd85c41f160e073bb56b4a599b7c4774fbfbd8da4b82ddb41540d60bfeafea3
2023-10-17 23:41:07 +00:00
Steven Roose b108ffa2ec
Implement manual fmt::Debug for BlockHeader to include block hash 2023-10-17 02:00:42 +01:00
yancy 2ecab31f94 Remove stale comment and map_err
The current MSRV is greater than rustc 0.29.
2023-10-16 14:48:14 +02:00
yancy b166442fb0 Replace hex_psbt macro with test helper function
hex_psbt was added as a macro so that a panic would reveal the line
number of the failing test by expanding the macro at the test location.
However, a stack trace can be used to reveal  the test that caused the
failure using RUST_BACKTRACE=1.  Furthermore, the track_caller macro is
added to the helper methods which will reveal the line number of the
calling function (the offending test). More detailed information for
debugging has been added to hex_psbt() so that the offending string
will be included in the panic message.
2023-10-16 14:48:00 +02:00
yancy 9e4a784b8b Move psbt macro to the psbt test module
The macro psbt_with_values is used by the psbt test module.  Since
there is no pre-processing required, there is no reason to use
metaprogramming here, so this commit moves the logic from a
macro to common function in the test module.
2023-10-16 11:31:01 +02:00
Tobin C. Harding 6731e85dc1
bitcoin: Bump version to 0.31.0-rc1
In preparation for the first rc release; bump the version number.
2023-10-13 08:34:46 +11:00
Andrew Poelstra e0ddead255
Merge rust-bitcoin/rust-bitcoin#2107: Use `Target` as type for `pow_limit`
38005f6aa7 Use Target for pow_limit (Tobin C. Harding)

Pull request description:

  The `Params::pow_limit` field is currently a `Work` type, this is incorrect. The proof of work limit is the highest _target_ not the lowest work (even though these have a relationship).

  Note that we use the highest _attainable_ target, this differs from Bitcoin Core and the reasoning is already documented in the code.

  Add new consts and document where they came from as well as how they differ to Core.

  Use the new consts in the various network specific `Params` types.

  Fix: #2106

ACKs for top commit:
  junderw:
    ACK 38005f6aa7
  apoelstra:
    ACK 38005f6aa7

Tree-SHA512: 5e71f69cdd555fd95a52fc1479e27b5e11226772f6432758c1364107a068bd1271486da6db1ece694da0287ce10cfbc18d28d6e3dbb0b9d387ff968eea43ab18
2023-10-12 15:05:51 +00:00
Tobin C. Harding 38005f6aa7
Use Target for pow_limit
The `Params::pow_limit` field is currently a `Work` type, this is
incorrect. The proof of work limit is the highest _target_ not the
lowest work (even though these have a relationship).

Note that we use the highest _attainable_ target, this differs from
Bitcoin Core and the reasoning is already documented in the code.

Add new consts and document where they came from as well as how they
differ to Core.

Use the new consts in the various network specific `Params` types.
2023-10-11 08:50:42 +11:00
Tobin C. Harding 678eee8d73
Use Message::from_digest
We have a new API function available with recent version of `secp256k1`
to create a `Message` directly from a sighash byte array.

Use `Message::from_digest(sighash.to_byte_array())` to construct
messages ready to sign.
2023-10-11 08:16:25 +11:00
Tobin C. Harding 6f30ac9d02
Upgrade the secp dependency
Upgrade the `secp256k1` dependency to the newly released `v0.28.0`.

FTR this includes two simple changes:
- Use `Message::from_digest_slice` instead of `Message::from_slice`.
- Use `secp256k1::Keypair` instead of `secp256k1::KeyPair`.
2023-10-10 10:04:31 +11:00
Tobin C. Harding 818a3c5424
Use Keypair instead of KeyPair in identifiers
In preparation for updating the secp dependency to v0.28.0, which
includes a change of `KeyPair` to `Keypair`, change our identifier usage
to indicate that "keypair" is a single word.

Deprecate the old forms.
2023-10-10 10:02:09 +11:00
Tobin C. Harding 33ee49f8e5
Update bech32 dependency
Update the `bech32` dependency to use the newly release beta version.

The main fix here is silent, a bug fix in `bech32` that was being hit by
our fuzzing suite.
2023-10-10 06:47:58 +11:00
Andrew Poelstra 342a35b4c4
Merge rust-bitcoin/rust-bitcoin#2109: ci: bump rustc to 1.60 for fuzz test
6b5d06f23e ci: fix the byteorder to 1.4.3 for edition 2018 (Vincenzo Palazzo)
98513ef151 clippy: more worning fixes (Vincenzo Palazzo)
05d3dc5d72 Remove redundant guard (Tobin C. Harding)
4537634e7e ci: bump rustc to 1.60 for fuzz test (Vincenzo Palazzo)

Pull request description:

  Ci looks like broken, so this should fix
  it

ACKs for top commit:
  apoelstra:
    ACK 6b5d06f23e

Tree-SHA512: bfa0eaf8cbc02a671237d99221db8c21264ce9df91301818c95c41dcc5ad4935e91254b0b3fa8f36738a9d71b6541fb8784ac8280d67057960a3d20e385a9f17
2023-10-07 16:40:36 +00:00
Vincenzo Palazzo 98513ef151
clippy: more worning fixes
error[E0308]: mismatched types
  --> bitcoin/src/psbt/raw.rs:87:24
   |
87 |               return Err(encode::Error::OversizedVectorAllocation {
   |  ________________________^
88 | |                 requested: key_byte_size as usize,
89 | |                 max: MAX_VEC_SIZE,
90 | |             });
   | |_____________^ expected enum `psbt::error::Error`, found enum `consensus::encode::Error`
   |
help: try wrapping the expression in `psbt::error::Error::ConsensusEncoding`
   |
87 ~             return Err(psbt::error::Error::ConsensusEncoding(encode::Error::OversizedVectorAllocation {
88 |                 requested: key_byte_size as usize,
89 |                 max: MAX_VEC_SIZE,
90 ~             }));
   |

----

  Compiling bitcoin v0.30.0 (/home/vincent/github/work/rust-btc/rust-bitcoin/bitcoin)
    Checking bitcoin-fuzz v0.0.1 (/home/vincent/github/work/rust-btc/rust-bitcoin/fuzz)
error: redundant clone
   --> bitcoin/examples/taproot-psbt.rs:453:77
    |
453 |             witness_utxo: { Some(TxOut { value, script_pubkey: script_pubkey.clone() }) },
    |                                                                             ^^^^^^^^ help: remove this
    |
    = note: `-D clippy::redundant-clone` implied by `-D warnings`
note: this value is dropped without further use
   --> bitcoin/examples/taproot-psbt.rs:453:64
    |
453 |             witness_utxo: { Some(TxOut { value, script_pubkey: script_pubkey.clone() }) },
    |                                                                ^^^^^^^^^^^^^
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone

error: could not compile `bitcoin` due to previous error
warning: build failed, waiting for other jobs to finish...
error: redundant clone
    --> bitcoin/src/psbt/mod.rs:1095:13
     |
1095 |             .clone()
     |             ^^^^^^^^ help: remove this
     |
     = note: `-D clippy::redundant-clone` implied by `-D warnings`
note: this value is dropped without further use
    --> bitcoin/src/psbt/mod.rs:1094:17
     |
1094 |           assert!(psbt
     |  _________________^
1095 | |             .clone()
     | |____________^
     = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_clone

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2023-10-07 11:40:44 +02:00
Tobin C. Harding 05d3dc5d72 Remove redundant guard
Clippy warns: redundant guard

As suggested, remove the redundant guard.
2023-10-07 11:19:47 +02:00
Andrew Poelstra eab9f89779
Merge rust-bitcoin/rust-bitcoin#1986: Remove private hex test macro
8eff4d0385 Remove private hex test macro (Tobin C. Harding)

Pull request description:

  We have this macro in `hex-conservative` now, remove the version here.

  This patch does not change the public API and only touches test code.

ACKs for top commit:
  apoelstra:
    ACK 8eff4d0385
  clarkmoody:
    ACK 8eff4d0385

Tree-SHA512: 93a08fff778930071cd1a28c19202e4a94ca8881b2e873538de2e942b71c2cd6184ed6364c572538a8a699295a71761c6f836accaf251a15683138b71f148fab
2023-10-06 22:14:12 +00:00
Andrew Poelstra 3743f2743b
Merge rust-bitcoin/rust-bitcoin#2101: Audit error types code base wide
10374af75c Make error types uniform (Tobin C. Harding)
43d3306822 Use explicit error::Error impl instead of the default (Tobin C. Harding)
2512dbafc2 Remove impl_std_error macro (Tobin C. Harding)
6933ca4fc2 Add suffix to HiddenNodes error type (Tobin C. Harding)
2b40ea24fb Add suffix to IncompleteBuilder error type (Tobin C. Harding)
f41416a0ea Add suffix to UnknownMagic error type (Tobin C. Harding)
5658dac024 Add suffix to UnknownChainHash error type (Tobin C. Harding)
2fb71dd943 Move p2p error types to bottom of file (Tobin C. Harding)
39314ad52f Move error code to match conventional layout (Tobin C. Harding)

Pull request description:

  PR aims to achieve two things:
  - Make error code brain dead easy to read
  - Get error code closer to being ready for v1.0

  The first 8 patches are pretty basic, and are broken up into really small changes. The last patch is much bigger, it has a long git log to explain it but reviewing should not take too much brain power.

  This PR does not introduce anything new, it just applies what we have been doing recently with errors. Before v1.0.0 others will likely want to re go over all the error types. As such I believe this PR can be merged under the one ack carve-out.

  ### TODOs (future PRs)

  We have a few errors that still need splitting up:

  - Split up `merkle_tree::block::MerkleBlockError`
  - Split up `psbt::error::Error`
  - Split up `IncompleteBuilderError`

  Also, all error From's should probably have `#[inline]`, I noticed late in the process and did not have the heart to visit every error again.

ACKs for top commit:
  apoelstra:
    ACK 10374af75c
  clarkmoody:
    ACK 10374af75c

Tree-SHA512: 4f4f3533f42dc11af8e7978f3272752bb56d12a68199752ed4af0c02a46a87892b55c695b7007bc3d0bdf389493068d068e2be1780e8c3008815efec3a02eedf
2023-10-06 14:19:39 +00:00
Andrew Poelstra b549faa1ca
Merge rust-bitcoin/rust-bitcoin#2102: rand-std should enable std
a1538a42c1 rand-std should enable std (sanket1729)

Pull request description:

ACKs for top commit:
  realeinherjar:
    ACK a1538a42c1
  apoelstra:
    ACK a1538a42c1
  tcharding:
    ACK a1538a42c1

Tree-SHA512: 5a1f9b6f40bfc24bc1f9a21dce4b8d91e5f4066170096443694068788def23653759bca30a36b60016ca81ba6196b8a6b5badea0d3ce654ecfbd8981c65d53f5
2023-10-05 12:23:39 +00:00
Tobin C. Harding be8aee6968
Remove stale link 2023-10-05 15:19:33 +11:00
Tobin C. Harding 7d54cd3485
Fix typo in docs 2023-10-05 15:13:09 +11:00
sanket1729 a1538a42c1
rand-std should enable std
Users should not need to specify both.
2023-10-03 23:10:23 -07:00
Tobin C. Harding 10374af75c
Make error types uniform
On our way to v1.0.0 we are defining a standard for our error types,
this includes:

- Uses the following derives (unless not possible, usually because of `io::Error`)

  `#[derive(Debug, Clone, PartialEq, Eq)]`

- Has `non_exhaustive` unless we really know we can commit to not adding
  anything.

Furthermore, we are trying to make the codebase easy to read. Error code
is write-once-read-many (well it should be) so if we make all the error
code super uniform the users can flick to an error and quickly see what
it includes. In an effort to achieve this I have made up a style and
over recent times have change much of the error code to that new style,
this PR audits _all_ error types in the code base and enforces the
style, specifically:

- Is layed out: definition, [impl block], Display impl, error::Error impl, From impls
- `error::Error` impl matches on enum even if it returns `None` for all variants
- Display/Error impls import enum variants locally
- match uses *self and `ref e`
- error::Error variants that return `Some` come first, `None` after

Re: non_exhaustive

To make dev and review easier I have added `non_exhaustive` to _every_
error type. We can then remove it error by error as we see fit. This is
because it takes a bit of thinking to do and review where as this patch
should not take much brain power to review.
2023-10-04 15:15:52 +11:00
Tobin C. Harding 43d3306822
Use explicit error::Error impl instead of the default
In a further effort to make the code brain-dead easy to read; use an
explicit implementation of `std::error::Error` that returns `None`
instead of relying on the default trait implementation.
2023-10-04 15:15:43 +11:00
Tobin C. Harding 2512dbafc2
Remove impl_std_error macro
We would like the codebase to be optimized for readability not ease of
development, as such code that is write-once-read-many should not use
macros.

Currently we use the `impl_std_error` macro to implement
`std::error::Error` for struct error types. This makes the code harder
to read at a glance because one has to think what the macro does.

Remove the `impl_std_error` macro and write the code explicitly.
2023-10-04 15:15:34 +11:00
Tobin C. Harding 6933ca4fc2
Add suffix to HiddenNodes error type
By convention we always include the suffix "Error" on our error types.

Rename the error type `HiddenNodes` to `HiddenNodesError`.
2023-10-04 15:15:21 +11:00
Tobin C. Harding 2b40ea24fb
Add suffix to IncompleteBuilder error type
By convention we always include the suffix "Error" on our error types.

Rename the error type `IncompleteBuilder` to `IncompleteBuilderError`.
2023-10-04 15:14:45 +11:00
Tobin C. Harding f41416a0ea
Add suffix to UnknownMagic error type
By convention we always include the suffix "Error" on our error types.

Rename the error type `UnknownMagic` to `UnknownMagicError`.
2023-10-04 12:29:05 +11:00
Tobin C. Harding 5658dac024
Add suffix to UnknownChainHash error type
By convention we always include the suffix "Error" on our error types.

Rename the error type `UnknownChainHash` to `UnknownChainHashError`.
2023-10-04 12:28:05 +11:00
Tobin C. Harding 2fb71dd943
Move p2p error types to bottom of file
Move the p2p error types to the bottom of the file next to the various
impls for these types.

Code move only, no other changes.
2023-10-04 12:28:05 +11:00
Tobin C. Harding 39314ad52f
Move error code to match conventional layout
We typically layout error code as: definition, [impl block], `Display` impl,
`error::Error` impl, from imlps.

Code move only, no other changes.
2023-10-04 12:11:07 +11:00
Andrew Poelstra fcd4ad51ef
Merge rust-bitcoin/rust-bitcoin#1389: Add `PartialMerkleTree::calc_tree_height` method
752adff9d1 Add method calc_height (Tobin C. Harding)
46f5588646 Add unit test for calc_tree_width (Tobin C. Harding)

Pull request description:

  Add a private `PartialMerkleTree::calc_tree_width` function and a unit test to test it.

ACKs for top commit:
  apoelstra:
    ACK 752adff9d1
  clarkmoody:
    ACK 752adff9d1

Tree-SHA512: 9c4ad9f6ff47d8faad1c7c1e977427f1528af2712ceffd05357d0c9117b5fdb7b2783afc00a75cb19b853bfbd7b3895baa3a3563bdc496593cc9b06ce80dbbf8
2023-10-03 13:55:45 +00:00
Andrew Poelstra bd9c4125cf
Merge rust-bitcoin/rust-bitcoin#2082: example: Modify `taproot-psbt.rs` to make the use of prevouts clearer.
3b60ad5567 example: Modify `taproot-psbt.rs` to make the use of prevouts clearer. (S. Santos)

Pull request description:

  The `taroot-psbt.rs` example uses only one input, and therefore the current code may not make it clear that the number of prevout items must correspond to the number of transaction inputs, since the prevout slice is built within a loop.

  This PR aims to make this clear to any user who wants to reuse the logic from the example code.

ACKs for top commit:
  tcharding:
    ACK 3b60ad5567
  apoelstra:
    ACK 3b60ad5567

Tree-SHA512: afad63782b0e8a459de6cf69712d31fdab860c0d4cf9f3a51c3d85544a067bd50f4febc10ec4046e3a37d9ca518bbf2460c2599f1569549701c07f8a267dfd05
2023-10-01 15:12:25 +00:00
S. Santos 3b60ad5567 example: Modify `taproot-psbt.rs` to make the use of prevouts clearer. 2023-09-29 20:19:32 -03:00
Tobin C. Harding 8eff4d0385
Remove private hex test macro
We have this macro in `hex-conservative` now, remove the version here.

This patch does not change the public API and only touches test code.
2023-09-30 06:22:52 +10:00
Andrew Poelstra a0540bdb21
Merge rust-bitcoin/rust-bitcoin#2064: Feature: Psbt fee checks
dac627cc09 Feature: Psbt fee checks (junderw)

Pull request description:

  Closes #2061

  These new methods on Psbt will add checks for high fees by default. The threshold for "high fees" is currently set to 25000 sat/vbyte, which is about 20x higher than the highest next block fees seen on the "Mempool" website.

  The primary goal of this change is to prevent users of the library from accidentally sending absurd amounts of fees.

  (ie. Recently in September 2023 there was a transaction that sent an absurd amount of fees and made news in the Bitcoin world. Luckily the mining pool gave it back, but some might not be so lucky.)

  There are variants of the method that allow for users to set their own "absurd" threshold using a `FeeRate` value. And there is a method that performs no checks, and the method name is alarming enough to draw attention in a review, so at least developers will be aware of the concept.

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

Tree-SHA512: ae0beafdb50339ba3efc44a48ba19c0aeeb0a2671eb43867c1e02b807677ce99fb6b4c47b74a9ed2999f827b3edc00a8871fa4730dd12a4cb265be99437c13db
2023-09-29 17:13:30 +00:00
junderw dac627cc09
Feature: Psbt fee checks 2023-09-28 00:11:33 -07:00
Andrew Poelstra 0de8ec5b19
Merge rust-bitcoin/rust-bitcoin#2076: Re-write the weight/size API
c34e3cc7cc Re-write size/weight API (Tobin C. Harding)
73f7fbf520 Add code comments to transaction serialization (Tobin C. Harding)
29f20c1d0b Add segwit serialization constants (Tobin C. Harding)

Pull request description:

  Audit and re-write the weight/size API for `Block` and `Transaction`. First two patches are trivial, patch 3 contains justification and explanation for this work, copied here:

  ```
      Recently we introduced a bug in the weight/size code, while
      investigating I found that our `Transaction`/`Block` weight/size APIs
      were in a total mess because:

      - The docs were stale
      - The concept of weight (weight units) and size (bytes) were mixed up

      I audited all the API functions, read some bips (141, 144) and re-wrote
      the API with the following goals:

      - Use terminology from the bips
      - Use abstractions that mirror the bips where possible
  ```

  Please note, this PR introduces panics if a sciptPubkey overflows the calculation `weight = spk.size() * 4`.

  Fix #2049

ACKs for top commit:
  apoelstra:
    ACK c34e3cc7cc
  sanket1729:
    ACK c34e3cc7cc.

Tree-SHA512: 4944f652e6e362a282a5731140a9438a82d243a4c646b4627d9046a9f9cf13c476881750d432cfbc6b5fe5de1f0c4c9c44ed4569dac4bc11b55a5db28793803c
2023-09-26 20:08:56 +00:00
Andrew Poelstra 1c29dd97ce
Merge rust-bitcoin/rust-bitcoin#2084: Add `Witness::p2wpkh` constructor
5901d35095 Add push_p2wpkh function on Witness (Tobin C. Harding)
8cd409d561 Deprecate push_bitcoin_signature (Tobin C. Harding)

Pull request description:

  In order to create the witness to spend p2wpkh output one must create a `Witness` that includes the signature and the pubkey, we should have a function for this.

  ## Notes
  The PR originally added a `push_p2wphk` method, this is now instead a constrcutor `Witness:p2wpkh` (after review discussion below).

  - Patch 1 changes `push_bitcoin_signature` to take an `ecdsa::Sigtnture` instead of an `ecdsa::SerializedSignature`
  - Patch 2 takes a `secp256k1::PublicKey` removing the need for an error path (discussed below).

ACKs for top commit:
  sanket1729:
    ACK 5901d35095
  apoelstra:
    ACK 5901d35095

Tree-SHA512: 646014d97daafbf0909106d8990debaf481ac6f3578f0ddf232d739c3e2d55ae1d0275abe5a4a1db1c5c192c8c5f0b5546fc65aac37b91a3729db881c5ad3dec
2023-09-26 13:08:56 +00:00
Tobin C. Harding 5901d35095
Add push_p2wpkh function on Witness
In order to create the witness to spend p2wpkh output one must push the
signature and the pubkey, we should have a function for this.
2023-09-26 10:14:23 +10:00
Andrew Poelstra c31b933c10
Merge rust-bitcoin/rust-bitcoin#1952: Add changelog entries
24e5e19ed0 Add changelog entries (Tobin C. Harding)
79f2157311 bitcoin: Grab changelog entry from 0.30.1 release (Tobin C. Harding)

Pull request description:

  Gearing up for the next release add changelog entries for everything merged upto July 24.

ACKs for top commit:
  apoelstra:
    ACK 24e5e19ed0
  clarkmoody:
    ACK 24e5e19ed0

Tree-SHA512: 12761623f3d61fea77b5dfe4c505dcdb5041ec4473ae05524b818eb2d4e3cbc3b039b8f1400022916c9f2d1ee97fcccd7e7b6da0bb5f868a1b77bdcfade3d7ed
2023-09-25 19:53:42 +00:00
Tobin C. Harding c34e3cc7cc
Re-write size/weight API
Recently we introduced a bug in the weight/size code, while
investigating I found that our `Transaction`/`Block` weight/size APIs
were in a total mess because:

- The docs were stale
- The concept of weight (weight units) and size (bytes) were mixed up

I audited all the API functions, read some bips (141, 144) and re-wrote
the API with the following goals:

- Use terminology from the bips
- Use abstractions that mirror the bips where possible
2023-09-25 08:25:49 +10:00
Tobin C. Harding 24e5e19ed0
Add changelog entries
Add changelog entries to `bitcoin` after going through all merged PRs
upto July 24 (Sydney time).
2023-09-25 07:44:26 +10:00
Tobin C. Harding 79f2157311
bitcoin: Grab changelog entry from 0.30.1 release
In preparation for adding a 0.31.0 changelog entry grab the changelog
entry from the 0.30.1 tagged release branch so it does not get lost.
2023-09-25 07:43:53 +10:00
Tobin C. Harding 8cd409d561
Deprecate push_bitcoin_signature
The `Witness::push_bitcoin_signature` method is old and a bit stale.
Bitcoin has taproot signatures now so the name is stale, also we have
the `crate::ecdsa::Signature` type that holds the secp sig and the hash
type so we can use that instead of having two separate parameters.

Add a new, up to date, `Witness::push_ecdsa_signature` function and
deprecate the `push_bitcoin_signature` one.
2023-09-25 07:21:20 +10:00
Tobin C. Harding f31fb08651
Remove default impl from transaction version
There is no logical default for the transaction version number, there is
only pre-bip68 (v1) and post-bip68 (v2). Uses should specify the version
they want not rely on us making the choice.

(I originally added this impl to support testing, this was in hindsight
the wrong thing to do, props to Sanket for noticing.)
2023-09-25 05:51:24 +10:00
Clark Moody 72a7280d7d
Merge pull request #2006 from tcharding/08-18-tx-version
Add transaction::Version data type
2023-09-23 13:13:52 -05:00
Tobin C. Harding 73f7fbf520
Add code comments to transaction serialization
In an attempt to help super new devs add code comments about transaction
serialization formats pre and post segwit.
2023-09-23 14:38:25 +10:00
Tobin C. Harding 29f20c1d0b
Add segwit serialization constants
One of our stated aims is to make it possible to learn bitcoin by using
our library. To help with this aim add to private consts for the segwit
transaction marker and flag serialization fields.
2023-09-23 14:38:25 +10:00
Andrew Poelstra 141d805ddc
Merge rust-bitcoin/rust-bitcoin#2073: Feature: Count sigops for Transaction
158ba26a8a Feature: Count sigops for Transaction (junderw)

Pull request description:

  I copied over the sigop counting logic from Bitcoin Core, but I made a few adjustments.

  1. I removed 2 consensus flags that checked for P2SH and SegWit activation. This code assumes both are activated. If we were to include that, what would be a good way to go about it? (ie. If I run this method on a transaction from the 1000th block and it just so happened to have a P2SH-like input, Bitcoin Core wouldn't accidentally count those sigops because the consensus flag will stop them from running the P2SH logic. Same goes for SegWit)
  3. Since there's no guarantee that we have an index from which we can get the prevout scripts, I made it into a generic closure that looks up the prevout script for us. If the caller doesn't provide it, We can only count sigops directly in the scriptSig and scriptPubkey (no P2SH or SegWit).

  ## TODO
  - [x] Write tests for transaction sigop counting

  ~~Edit: The test changes are just to get the 1.48 tests passing. I'll remove them and replace them with whatever solution that is agreed upon in another PR etc.~~

  Edit 2: This is the code I used as a guide:

  8105bce5b3/src/consensus/tx_verify.cpp (L147-L166)

  Edit 3: I found a subtle bug in the implementation of `count_sigops` (https://github.com/rust-bitcoin/rust-bitcoin/pull/2073#issuecomment-1722403687)

ACKs for top commit:
  apoelstra:
    ACK 158ba26a8a
  tcharding:
    ACK 158ba26a8a

Tree-SHA512: 2b8a0c50b9390bfb914da1ba687e8599b957c75c511f764a2f3ed3414580150ce3aa2ac7aed97a4f7587d3fbeece269444c65c7449b88f1bdb02e573e6f6febd
2023-09-22 17:12:29 +00:00
Andrew Poelstra 675fd54c95
Merge rust-bitcoin/rust-bitcoin#1951: Use newly released bech32 API
e4c7e01a6f Use the new bech32 iterator API (Tobin C. Harding)

Pull request description:

  Depend on the newly released version of `bech32`, BOOM!

ACKs for top commit:
  apoelstra:
    ACK e4c7e01a6f
  clarkmoody:
    ACK e4c7e01a6f

Tree-SHA512: 91675a830cf67f8dcabd42e7dc1b70d80b669330be5244bb8102e0ec5d1a206d5ead07f73b328a158b761c328bc78d573185af8d31f14183ccc17318d752c02b
2023-09-21 22:26:51 +00:00
junderw 158ba26a8a
Feature: Count sigops for Transaction
Co-authored-by: Tobin C. Harding <me@tobin.cc>
2023-09-21 14:50:23 -07:00
Andrew Poelstra c32c7d1611
Merge rust-bitcoin/rust-bitcoin#2026: Use valid Psbt for serde regression test
95b7a95fc2 test: correct psbt used for regression test (Subhradeep Chakraborty)

Pull request description:

  The `unknown` key used in the `Psbt` (in `serde_regression_psbt` test) is not really unknown. Also the `preimages` in the `Input` don't seem to be valid. Though they don't affect the tests because of the `serde::serialize`, the `Psbt` itself is invalid and hence this PR.

ACKs for top commit:
  tcharding:
    ACK 95b7a95fc2
  apoelstra:
    ACK 95b7a95fc2

Tree-SHA512: 275320bb273163364640351e55a3f16c34c1eef06e9dde79b72bf40187d313f037edb5e4544f4dce32fb8a7cc552504aa2e4d22a646c89a3dec022f917539219
2023-09-21 18:53:54 +00:00
Andrew Poelstra f71948a778
Merge rust-bitcoin/rust-bitcoin#2021: Move and rename `XpubIdentifier`
b2a7d7023c Rename XpubIdentifier to XKeyIdentifier (Tobin C. Harding)
ffd2466ad1 Move XpubIdentifier to the bip32 module (Tobin C. Harding)

Pull request description:

  - Patch 1: Move the hash to the `bip32` module where it is used, as we have done with other hashes recently (and re-export it at crate root).
  - Patch 2: Rename the hash to `XKeyIdentifier` as discussed in #2014

  Fix: #2014

ACKs for top commit:
  apoelstra:
    ACK b2a7d7023c

Tree-SHA512: 5efa9fc857c71e506263bf6adee3b4294f22838d5b119177c9108c69191d545338c11a4796bc95e956a67f3418010725f3d12c06d2c4c3bb5cf038d59976ae0f
2023-09-21 17:55:31 +00:00
Andrew Poelstra eda7e7df0d
Merge rust-bitcoin/rust-bitcoin#2068: Fixes #2011: Customize Debug implementation of `absolute::LockTime`
71a5fe2b54 Customize Debug implementation of absolute::LockTime (Subhradeep Chakraborty)

Pull request description:

  Fixes https://github.com/rust-bitcoin/rust-bitcoin/issues/2011.

  This PR aims to make the "pretty print" of `absolute::LockTime` prettier by printing `X blocks` and `X seconds` for `Blocks` and `Seconds` respectively instead of the default Enum printing.

ACKs for top commit:
  apoelstra:
    ACK 71a5fe2b54
  tcharding:
    ACK 71a5fe2b54

Tree-SHA512: 79baad5ee0ba1aa892cb38588dae6a24977b8e42356208d6cc9adb007d1f8371e61dc82e35bb4dac9961216d68c56907f0db376c5c6fbb5a406728b8f7c3f5ad
2023-09-21 17:03:59 +00:00
Andrew Poelstra 36805b5283
Merge rust-bitcoin/rust-bitcoin#1994: Remove redundant segwit version from function names
bc398204bf Remove redundant segwit version from function names (Tobin C. Harding)

Pull request description:

  A P2TR output does not need to be clarified with version 1, it is implicit. As with p2wpkh/p2wsh and version 0.

  Remove redundant version identifiers from function names, deprecating the originals.

ACKs for top commit:
  apoelstra:
    ACK bc398204bf

Tree-SHA512: 49806c564badca25ce02161445b2b41497b565f2002aa1edfc0cf0c57b38683480deec0d9b682e18dc7e59c22128e0b641abcccc2cbedd0b5603cbcbf2fd26df
2023-09-21 16:10:50 +00:00
Andrew Poelstra f80ec98f35
Merge rust-bitcoin/rust-bitcoin#2002: Remove unnecessary reference
f17bb0d18f Remove unnecessary reference (Tobin C. Harding)

Pull request description:

  `T` is a generic that implements`AsRef<PushBytes>`, it should not be a reference. This is inline with other usages of `AsRef<PushBytes>` for example in `Builder::push_slice`.

  Found while working on #2003

ACKs for top commit:
  apoelstra:
    ACK f17bb0d18f

Tree-SHA512: 6f6ae0ba5d5010db53d9c2af107df84bc058277b2b7cc35800f4e6ed93d351838b7f101284b7d80345bee639615d27d76a2e5c4c784782c5b3e5090444defe29
2023-09-21 14:23:50 +00:00
Subhradeep Chakraborty 95b7a95fc2 test: correct psbt used for regression test 2023-09-21 11:45:18 +05:30
Tobin C. Harding e4c7e01a6f
Use the new bech32 iterator API
Use the new bech32 iterator API that Andrew and I wrote.
2023-09-21 15:10:57 +10:00
Tobin C. Harding c950ef4bbd
Add transaction::Version data type
BIP-68 activated a fair while ago (circa 2019) and since then only
transaction versions 1 and 2 have been considered standard.

Currently in our `Transaction` struct we use an `i32`, this means users
can construct a non-standard transaction if they do not first look up
what the value should be. We can help folk out here by abstracting over
the version number.

Since the version number only governs standardness elect to make the
inner `i32` public (ie., not an invariant). The aim of the type is to
make life easy not restrict what versions are used.

Add transaction::Version data type that simply provides two consts `ONE`
and `TWO`.

Add a `Default` impl on `Version` that returns `Version::TWO`.

In tests that used version 0, instead use `Version::default` because the
test obviously does not care.
2023-09-21 15:02:02 +10:00
Andrew Poelstra a2a4efbe6a
Merge rust-bitcoin/rust-bitcoin#1975: Prepare for using new bech32 release
52f2332383 Remove docs from witness version conversion functions (Tobin C. Harding)
47d6d785cb Remove bip 173/350 test vectors (Tobin C. Harding)
e0eaeaad99 Split ParseError out of Error (Tobin C. Harding)
0f536e86dc Add new UnknownAddressTypeError for parsing address type (Tobin C. Harding)
e2014cba1b Import error variants within dislay impl (Tobin C. Harding)
9d7791fcd6 Remove unnecessary self:: from error import (Tobin C. Harding)
b2e485ed51 Split the address error code out into a separate module (Tobin C. Harding)
f34ca0c52b Move address.rs to address/mod.rs (Tobin C. Harding)

Pull request description:

  In preparation for depending on the recently released version of `rust-bech32` do a bunch of preparatory fixes.

  1. Improve `address` module error handling as we are doing else where at the moment
  2. Remove bip 173 and 350 test vector tests, these are fully covered in bech32
  3. Trim down the docs on `WitnessVersion`

  This PR is the first 8 patches of https://github.com/rust-bitcoin/rust-bitcoin/pull/1951

ACKs for top commit:
  sanket1729:
    ACK 52f2332383
  apoelstra:
    ACK 52f2332383

Tree-SHA512: 67a4ea4020b4e5c9c8396e4195e06dbd1d11335788f9e52f60abbc0b399e37e5dacc9bb7fa4e88221670322fa3c3407ade059d5c709f96e2df97240f4524e08c
2023-09-20 19:54:36 +00:00
Andrew Poelstra 3b9bc9a063
Merge rust-bitcoin/rust-bitcoin#2038: Re-export Opcode
ccdcffe69c Re-export Opcode (Tobin C. Harding)

Pull request description:

  We recently rename `opcodes::All` to `Opcode` but did not re-export it from the crate root. Since it now has a nice clear name we can do so.

  Found while hacking up the `rust-bitcoincore-rpc` dependency upgrade for upcoming release `bitcoin v0.31.0`.

ACKs for top commit:
  apoelstra:
    ACK ccdcffe69c

Tree-SHA512: 8acac90d01f14245f93edc10f3483d8aa9865aca59b6ef42ab744b875558fca8ad74894ad95a83637f0cec7a2a353d74d4d6f7ee5f1d1276cc0fc3dcb6983362
2023-09-20 17:33:53 +00:00
Andrew Poelstra f4c83b4d8e
Merge rust-bitcoin/rust-bitcoin#2078: Script helper to classify bare multisig
acbf23aaa5 Add `is_multisig` helper to Script type (Clark Moody)

Pull request description:

  A new `is_multisig` helper method to classify bare multisig output scripts.

  The form of a valid multisig script is:
  - Pushnum `M`
  - &lt;N&gt; pubkeys
  - Pushnum `N`
  - `OP_CHECKMULTISIG`

  `N` must equal the number of pushed pubkeys, and `M` must be less than or equal to `N`.

  I've tested this against the RPC output of Core at the block level, checking that the total number of multisig outputs matches.

  ```
  Block 350338, 89 multisig
  Block 350340, 29 multisig
  Block 350341, 4 multisig
  Block 350343, 579 multisig
  Block 350344, 48 multisig
  Block 350346, 11 multisig
  Block 350347, 404 multisig
  Block 350350, 127 multisig
  Block 350351, 1 multisig
  Block 350353, 40 multisig
  Block 350356, 13 multisig
  Block 350357, 2 multisig
  Block 350358, 1 multisig
  ```

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

Tree-SHA512: b8feeaa8725ac63a658897dac3b303fc8b3d56674d796b14569548124928329993bea45482928d9ce85231f1b5837922af8c0a77b2601a92f88b5e2a9394e97f
2023-09-20 16:38:33 +00:00
Andrew Poelstra 6e6847a263
Merge rust-bitcoin/rust-bitcoin#2075: Bugfix: Script::count_sigops should not return a Result
026a55809e Fix: Script::count_sigops parsing should not return a Result (junderw)

Pull request description:

  When implementing some tests for the Transaction PR, I noticed that there were coinbase transactions that would pass Bitcoin Core parsing and fail my code.

  It turns out that the Script parsing for sigops calls `break`  to exit the loop and returns the current n value whenever there is an EarlyEndOfScript error.

  See this comment: https://github.com/rust-bitcoin/rust-bitcoin/pull/2073#issuecomment-1722403687 for some links to the relevant source.

ACKs for top commit:
  apoelstra:
    ACK 026a55809e
  tcharding:
    ACK 026a55809e

Tree-SHA512: 57c1b88add5e1c9ef9245fcec0e471db55c2f9b1b0b0f8ebd471f1bede0ca5eeb8492d8c75dea1fd43f1343037df44969c9b9fde26a7de9ac68a26dca899e47f
2023-09-20 15:53:30 +00:00
junderw cd15c746cb
Feature: Instruction can read the script number 2023-09-19 21:08:17 -07:00
Tobin C. Harding 52f2332383
Remove docs from witness version conversion functions
These docs do not add that much value, we do not typically bother
documenting `From` and `TryFrom` implementations because they are super
well known and its obvious from the function signature what is going on.
2023-09-20 13:13:56 +10:00
Tobin C. Harding 47d6d785cb
Remove bip 173/350 test vectors
The BIP-173 and BIP-350 test vectors are implemented in `rust-bech32`,
no need to duplicate those tests here.
2023-09-20 13:13:56 +10:00
Tobin C. Harding e0eaeaad99
Split ParseError out of Error
The `address::Error` is module level general, we can make the code
easier to maintain and easier to stabalize by splitting the parse error
out of the general error.

Create a `ParseError` that is returned by `FromStr for Address`. Remove
the now unused variants from the general `address::Error`.
2023-09-20 13:13:56 +10:00
Tobin C. Harding 0f536e86dc
Add new UnknownAddressTypeError for parsing address type
There is no need to use the general `address::Error` when parsing an
address type, there is only one error path.
2023-09-20 13:13:56 +10:00
Tobin C. Harding e2014cba1b
Import error variants within dislay impl
In an effort to reduce the number of lines of code import the error
variants locally within the `Display` impl on `Error`.

Refactor only, no logic changes.
2023-09-20 13:13:55 +10:00
Tobin C. Harding 9d7791fcd6
Remove unnecessary self:: from error import
`Error` is in this file, no need for `self::Error`.
2023-09-20 13:13:55 +10:00