Commit Graph

17 Commits

Author SHA1 Message Date
Martin Habovstiak 1b0988833a Remove `ToHex`
The `ToHex` trait was replaced by either simple `Display`/`LowerHex`
where appropriate or `DisplayHex` from `bitcoin_internals` which is
faster.

This change replaces the usages and removes the trait.
2023-01-07 19:50:03 +01:00
Martin Habovstiak 089a1e452d Replace `Vec::from_hex` with `hex!`
This makes the code less noisy and is a preparation for changing it to
`const`-based literal. Because of the preparation, places that used
variables to store the hex string were changed to constants.

There are still some instances of `Vec::from_hex` left - where they
won't be changeable to `const` and where `hex!` is unavailable
(integration tests). These may be dealt with later.

See also #1189
2022-12-31 21:10:19 +01:00
Tobin C. Harding f71335f971 Add rand-std feature
Currently we enable "secp256k1/rand-std" in the "rand" feature, this is
incorrect because it means "rand" implies "std" which it does not.

Add a "rand-std" feature that turns on "seck256k1/rand-std" and make the
"rand" feature turn on "seck256k1/rand".
2022-12-23 08:32:56 +11:00
Martin Habovstiak 6acf9ac8b8 Patch hashes and update the code
This patches `bitcoin_hashes` to use the version in the repository and
fixes the code after removal of `Deref`.

This also turns off `AS_DEPENDENCY` check with the intention to refactor
it later.
2022-12-18 14:33:55 +01:00
Martin Habovstiak 8e428562cb Implemented unsized `Script`
This renames `Script` to `ScriptBuf` and adds unsized `Script` modeled
after `PathBuf`/`Path`. The change cleans up the API a bit, especially
all functions that previously accepted `&Script` now accept truly
borrowed version. Some functions that perviously accepted `&[u8]` can
now accept `&Script` because constructing it is no loger costly.
2022-12-14 23:21:27 +01:00
Tobin C. Harding 2780e6cdaa Move base58 module to crate root
In preparation for removing the `util` module move the `base58` module
to the crate root. This is likely not the final resting place for this
module but it is a step in the right direction.

Includes addition of rustfmt attribute to skip formatting the digits
array. No other changes to the `base58` module.
2022-12-01 09:56:33 +11:00
Tobin C. Harding db5c8fe61c Move the taproot module to crate root
We are trying to flatten the `util` module. The `taproot` module can
live in the crate root. If/when we create a `crypto` module/crate we may
wish to pull some stuff out of this module but for now moving it gets us
closer to removing `util` without making the directory structure any
worse.

Includes adding rustfmt attributes to skip formatting of macros.
2022-11-30 12:03:39 +11:00
Andrew Poelstra 9266b1bbe0
Merge rust-bitcoin/rust-bitcoin#1260: Create `crypto` module
2df51dae15 Create crypto module (Tobin C. Harding)

Pull request description:

  Done as part of [util flattening](https://github.com/rust-bitcoin/rust-bitcoin/issues/639).

  Create a `crypto` module and move into it (out of `util`):
  - ecdsa
  - schnorr
  - key

  After review, this PR now includes some type re-names
  - EcdsaSig -> ecdsa::Signature
  - SchnorrSig -> schnorr::Signature
  - EcdsaSigError -> ecdsa::Error
  - SchnorrSigError -> schnorr::Error
  - InvalidSchnorrSigSize -> InvalidSignatureSize  (this is an error enum variant)

ACKs for top commit:
  apoelstra:
    ACK 2df51dae15
  sanket1729:
    ACK 2df51dae15

Tree-SHA512: 7cf63d51ed5fdc737cd59767d9bb96b1e3501634e3aee855493f6a51ad5c5397ce4b25c77f9929abd70d6ceb351fc6520e835da108f4c9a46df5b9c2b52ca6b3
2022-11-29 15:33:18 +00:00
yancy f7a6d17143 Add rand feature flag to the example documentation 2022-11-28 17:10:24 +01:00
Tobin C. Harding 2df51dae15 Create crypto module
Done as part of flattening util.

Currently in `util` module we have a bunch of modules that provide
cryptography related functionality.

Create a `crypto` module and move into it the following:

- ecdsa
- schnorr
- key

To improve uniformity and ergonomics, do the following re-names while we
are at it:

- EcdsaSig -> ecdsa::Signature
- SchnorrSig -> schnorr::Signature
- EcdsaSigError -> ecdsa::Error
- SchnorrSigError -> schnorr::Error
- InvalidSchnorrSigSize -> InvalidSignatureSize  (this is an error enum variant)
2022-11-22 14:09:33 +11:00
Tobin C. Harding 408d7737fb Run cargo fmt
Run the command `cargo +nightly fmt` to fix formatting issues. No other
changes other than those introduced by `rustfmt`.
2022-11-18 13:11:07 +11:00
Tobin C. Harding 6151d4c841 base58: Rename public functions
The `base58` module is for encoding and decoding, it makes sense for the
public functions to be called `encode` and `decode`. We also have some
functions that operate on data with a checksum, for these it makes sense
to tack `check` onto the _end_ of the function name.

With this applied the public API is:

- decode
- decode_check
- encode
- encode_check
- encode_check_to_fmt
2022-10-29 10:35:08 +11:00
Tobin C. Harding c3e4399519 Remove usage of opcodes::all
We have all of the opcodes defined in a submodule called `all`, this
allows wildcard imports without bringing in the other types in the
`opcodes` module.

Use wildcard import `use crate::blockdata::opcodes::all::*` instead of
fully qualifying the path to opcodes.
2022-10-24 13:08:47 +11:00
Tobin C. Harding 7d851b42ee Move serde_string_* macros to the serde_utils module
In preparation for emptying the `internal_macros` module move the
`serde_string_impl` and `serde_struct_human_string_imp` macros to the
`serde_utils` module.

Rationale: `internal_macros` stuff can go over in the `internals` crate
now that we have one. The serde macros could go over there but we have a
`serde_utils` module that holds code for implementing serde traits,
these two macros are exactly that.
2022-10-20 06:15:57 +11: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 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 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
Renamed from src/address.rs (Browse further)