Commit Graph

928 Commits

Author SHA1 Message Date
Andrew Poelstra 6101d8d31a
Merge rust-bitcoin/rust-bitcoin#1277: Try to fix up sighash export mess
2001f44e46 Try to fix up sighash export mess (Tobin C. Harding)

Pull request description:

  Recently we moved a few types from `transaction` to `sighash`, while doing so I erroneously annotated code with the `deprecated` attribute hoping it would give downstream users a gentle upgrade experience. It turns out `deprecated` only works on functions.

  During that same work, we re-exported from the crate root a bunch of types from the `sighash` module that probably should not have been re-exported. We are currently trying to create a nice clean API surface, in an effort to move in the right direction we should remove the re-exports and just re-export the `sighash` module.

  Try to clean up the sighash export mess by doing:

  - Remove the re-exports from the `transaction` module
  - Remove crate level re-exports of `sighash` module types
  - Re-export `sighash` module

  Note, this patch is a breaking API change, justified by the fact that there is no good way to gently lead downstream when moving types since types cannot be deprecated with the `deprecated` attribute.

ACKs for top commit:
  apoelstra:
    ACK 2001f44e46
  Kixunil:
    ACK 2001f44e46

Tree-SHA512: 42a08bc15bacd4cf7c3fec002ddb29afe5b1be3c4eb74fbd8c63a9333c0d45cbc8493027532f5db6a3930d49b1e83048826371e0ed7d4ac3dc611e5885540bce
2022-09-24 13:04:42 +00:00
Andrew Poelstra b1869803bf
Merge rust-bitcoin/rust-bitcoin#1208: Move bip32 module to crate root
8bed2ddffe Run formmater on bip32 (Tobin C. Harding)
34113c9558 Move bip32 module to crate root (Tobin C. Harding)

Pull request description:

  We are attempting to flatten the `util` module.

  Move the `bip32` module to the crate root out of `util`.

  Currently `src/util/` is ignored by the formatter so this move requires `bip32` module to be formatted. Formatting is done as a separate patch so reviewers can run `cargo +nightly fmt` and compare the diffs if so desired.

ACKs for top commit:
  apoelstra:
    ACK 8bed2ddffe
  Kixunil:
    ACK 8bed2ddffe

Tree-SHA512: dadea31be0459fd10e71927bd21dc44b59428f695a6df7093052ca7257b6590d5dd5b1343a89869ac9f4d7805dbca7558b475048ea9387c36265f14246cc6852
2022-09-21 16:46:05 +00:00
Andrew Poelstra a0899eb8e4
Merge rust-bitcoin/rust-bitcoin#1258: Add API method `absolute::LockTime::is_satisfied_by_lock`
8aa94bd0b2 Improve docs on is_implied_by (Tobin C. Harding)
b8721bf244 Add method relative::LockTime::is_implied_by (Tobin C. Harding)
d5492b8a25 Add absolute::LockTime::is_implied_by method (Tobin C. Harding)
98cbdb5a5c Increment lock value (Tobin C. Harding)

Pull request description:

  Patch 1 is a docs improvement.

  Patch 2 commit log:

  When implementing the absolute lock time API we decided on _not_
  supporting checking lock satisfaction with another lock, instead we
  provided a pattern in the docs for doing so. Fast forward a months and
  I, the primary author, then forgot to use the correct pattern when using
  the API in `rust-miniscript` - this is a sure sign that the API is too
  hard to use. In this time we worked on the relative lock API and came up
  with a `is_satisfied_by_lock` method - this is identical to the required
  use case in the absolute lock time module.

  Add a method on `absolute::LockTime` for checking a lock against another
  lock, add rustdoc comment explaining the methods function in filtering
  prospective lock time values (how we use it in `rust-miniscript`).

ACKs for top commit:
  Kixunil:
    ACK 8aa94bd0b2
  apoelstra:
    ACK 8aa94bd0b2

Tree-SHA512: 5c7efa1727a846248783c9e6044bf8b0a7550d298ca1b5d3274ef325cf82efa33392ad14ef7e3e9aa91423ba56e8a3e7f4a38a966be38f673dccefd46465ad51
2022-09-20 17:19:49 +00:00
Tobin C. Harding f429c22599 Remove user_enum macro
The `user_enum` macro is only used a single time. The macro includes
custom serde logic which can be trivially derived instead.

Remove the `user_enum` macro and just implement `Network` the old
fashioned way. Doing so simplifies the code.
2022-09-20 16:53:38 +10:00
Tobin C. Harding ad29084582 Add Network serde roundtrip test
In preparation for patching the `Network` serde impls; add a roundtrip
test for `serde` (de)serializing  the `Network` type.
2022-09-20 15:29:55 +10:00
Tobin C. Harding 8bed2ddffe Run formmater on bip32
Run the formmater on the newly moved `bip32` module. No changes other
than those introduced by `cargo +nightly fmt`.
2022-09-20 14:22:01 +10:00
Tobin C. Harding 34113c9558 Move bip32 module to crate root
We are attempting to flatten the `util` module; move the `bip32` module
to the crate root out of `util`.
Currently `src/util/` is ignored by the formatter, this patch does not
do formatting, will be done later.
2022-09-20 14:21:11 +10:00
Tobin C. Harding 8aa94bd0b2 Improve docs on is_implied_by
The lock time methods are a source of endless confusion; make an attempt
at improving further the documentation on the two `is_implied_by`
methods (one on absolute lock time and one on relative).
2022-09-20 08:41:12 +10:00
Tobin C. Harding b8721bf244 Add method relative::LockTime::is_implied_by
As we just did for `absolute::LockTime` add a method `is_implied_by` and
deprecate `is_satisfied_by_lock`.

Reasoning: it is odd to think of a lock satisfying another lock but it
is clear to see that satisfaction of one lock can imply satisfaction of
another.
2022-09-20 08:40:35 +10:00
Tobin C. Harding 2001f44e46 Try to fix up sighash export mess
Recently we moved a few types from `transaction` to `sighash`, while
doing so I erroneously annotated code with the `deprecated` attribute
hoping it would give downstream users a gentle upgrade experience. It
turns out `deprecated` only works on functions.

During that same work, we re-exported from the crate root a bunch of
types from the `sighash` module that probably should not have been
re-exported. We are currently trying to create a nice clean API surface,
in an effort to move in the right direction we should remove the
re-exports and just re-export the `sighash` module.

Try to clean up the sighash export mess by doing:

- Remove the re-exports from the `transaction` module
- Remove crate level re-exports of `sighash` module types
- Re-export `sighash` module

Note, this patch is a breaking API change, justified by the fact that
there is no good way to gently lead downstream when moving types since
types cannot be deprecated with the `deprecated` attribute.
2022-09-19 16:46:02 +10:00
Tobin C. Harding e24c91e9ca sign_message: Run cargo fmt
We just renamed and moved the `util::misc` module to
`crate::sign_message`, doing so prevents `rustfmt` from ignoring it.

run `cargo +nighly fmt`.
2022-09-19 16:44:05 +10:00
Tobin C. Harding 041d6a8097 Move and deprecate script_find_and_remove
Done as part of flattening the `util` module.

We have a function in `util::misc` that operates on scripts, it is an
implementation of `FindAndDelete` from Bitcoin Core and is primarily
useful for supporting `CODESEPARATOR`, which we do not support.

Move the public `script_find_and_remove` function out of `util/misc.rs` and into
`util/mod.rs`, delete the testing and deprecate the function.
2022-09-19 16:44:04 +10:00
Andrew Poelstra aeacbe763d
Merge rust-bitcoin/rust-bitcoin#1286: Make `ChainHash::using_genesis_block` constant
92ef41b663 Make `ChainHash::using_genesis_block` constant (Jeffrey Czyz)

Pull request description:

  ChainHash::using_genesis_block can't be `const` if it uses a `match` expression prior to Rust 1.46. Use an array mapping to work around this limitation.

  Follow-up suggested in [#1283](https://github.com/rust-bitcoin/rust-bitcoin/pull/1283#issuecomment-1249418809).

ACKs for top commit:
  apoelstra:
    ACK 92ef41b663
  Kixunil:
    ACK 92ef41b663

Tree-SHA512: 71f95877c8e5335012ad0339e1f8691e3b33344fa02ecc24c3d4d728232cb7b0de62aec20eb1855b23eeccfbc2eeab920b21ee2243d95c6c89fa8ad5bc846975
2022-09-16 22:21:08 +00:00
Jeffrey Czyz 92ef41b663
Make `ChainHash::using_genesis_block` constant
ChainHash::using_genesis_block can't be `const` if it uses a `match`
expression prior to Rust 1.46. Use an array mapping to work around this
limitation.
2022-09-16 13:49:50 -05:00
Andrew Poelstra ccf9c3a172
Merge rust-bitcoin/rust-bitcoin#1285: Implement From for hash types
96dfcdf3b7 Implement From for hash types (Noah)

Pull request description:

  Reopening #1280 on the right branch + implemented `From` for references of types that were done in #1280.

ACKs for top commit:
  Kixunil:
    ACK 96dfcdf3b7
  apoelstra:
    ACK 96dfcdf3b7

Tree-SHA512: ad762032390f060b87cdd24033a5fc13a4c5297c55d7091ed89c5ca240be2f57998c0be084f40f9b04833920756b93a3ca4576a2ef944872354d1b3607734228
2022-09-16 18:05:09 +00:00
Andrew Poelstra 51df1c4024
Merge rust-bitcoin/rust-bitcoin#1282: Remove code deprecated last release
7a1aa2098a Remove code deprecated last release (Tobin C. Harding)

Pull request description:

  We give one release cycle for deprecating old code so as to make the upgrade path easier for downstream users.

  Remove code deprecated during the last release (v0.29.0).

  (Check out my diff stats - all red ;)

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

Tree-SHA512: d4b9c65d0d8a0aac31cf94d826e8a6084d4f5427a26da2ad5a3973c7f5931fa10695214dc602261e9079e1c06c6dc3f5b5dcdb8d20b5c39eaadd9a33d23746dd
2022-09-16 17:36:22 +00:00
Noah 96dfcdf3b7 Implement From for hash types 2022-09-16 22:29:05 +10:00
Duncan Dean 1a89d5230c
examples: Add taproot-psbt workflow example
This example shows how to use the PSBT API for taproot transactions.
We have a simple BIP86-style spend and an example of an inheritance
timelock that can be spent either by the beneficiary via the script
path after a timelock, or via the key path by the benefactor so that
they can refresh the timelock at any time.
2022-09-16 09:00:27 +02:00
Jeffrey Czyz b1d85160ba
Add constants to `ChainHash` for each `Network`
`ChainHash::using_genesis_block` can't be made `const` because it uses a
`match` expression, which is only valid in Rust 1.46. Add individual
constants as a workaround so that `ChainHash` can be used in `const`
contexts.
2022-09-15 20:03:57 -05:00
Tobin C. Harding 7a1aa2098a Remove code deprecated last release
We give one release cycle for deprecating old code so as to make the
upgrade path easier for downstream users.

Remove code deprecated during the last release (v0.29.0).
2022-09-16 08:08:53 +10:00
Tobin C. Harding 3f275f7f2b Remove code deprecated in v0.28.0
I believe we said we'd keep deprecated code around for two release
cycles so this code can  all be deleted now.
2022-09-15 13:29:02 +10:00
Tobin C. Harding c4eb218cd0 schnorr:: Remove incorrect deprecated
Currently we attempt to have deprecated key types in the `schnorr`
module. The `deprecated` attribute does not work on types, only on
functions.

Remove the broken deprecation logic and re-export key types instead of
using type alias', this allows a bunch of qualified paths to be
simplified also.

Add `pub use` re-exports of all secp256k1 types that are part of the
public API of the `schnorr` module. This makes the module more ergonomic
to use.
2022-09-15 12:34:51 +10:00
Tobin C. Harding d5492b8a25 Add absolute::LockTime::is_implied_by method
When filtering it is necessary to check two lock times against each
other, we currently provide a patter for doing so in the docs but we can
do better.

It was observed that satisfaction of a lock time 'implies' satisfaction
of another lock time if the lock times are the same unit and one locks
value is less than the others - this is exactly the code pattern we
suggest for filtering.

Add a method on `absolute::LockTime` for checking a lock against another
lock, add rustdoc comment explaining the methods function in filtering
prospective lock time values (how we use it in `rust-miniscript`).
2022-09-15 09:21:13 +10:00
Tobin C. Harding 98cbdb5a5c Increment lock value
Currently in one of the rustdoc examples showing lock satisfaction we
use two locks with the same value, this obfuscates which lock is doing
the satisfying and which lock is being satisfied.

Increment the value in one of the locks so it is obvious which lock is
which.
2022-09-14 10:24:22 +10:00
Martin Habovstiak 4d54b161e7 Fix serde versions
`Cargo.toml` claimed that this crate works with very old versions of
`serde` which wasn't the case. This commit changes the versions to
minimal known-to-work values.
2022-09-13 16:19:07 +02:00
Tobin C. Harding 834bbf461f Introduce bitcoin-internals crate
Add a new crate `bitcoin-internals` to be used for internal code needed
by multiple soon-to-be-created crates.

Add the `write_err` macro to `bitcoin-internals`, nothing else.

This patch uses a `path` dependency which means `rust-bitcoin` cannot be
released in its current state, will need to be changed once we release
the `bitcoin-internals` crate on `crates.io`.
2022-09-13 08:59:57 +10:00
Tobin C. Harding 12c5fb042e Refactor import statements
Refactor import statements to adhere to core/other/crate with white
space between groups.

Refactor only, no logic changes.
2022-09-13 08:44:57 +10:00
Tobin C. Harding 022730bd8d Add a workspace to the top level directory.
Create a directory `bitcoin` and move into it the following as is with
no code changes:

- src
- Cargo.toml
- contrib
- test_data
- examples

Then do:

- Add a workspace to the repository root directory.
- Add the newly created `bitcoin` crate to the workspace.
- Exclude `fuzz` and `embedded` crates from the workspace.
- Add a contrib/test.sh script that runs contrib/test.sh in each
  sub-crate
- Fix the bitcoin/contrib/test.sh script
2022-09-13 08:44:57 +10:00