Merge rust-bitcoin/rust-bitcoin#2989: Move opcodes to `primitives`

9a586987d1 Move opcodes to primitives (Tobin C. Harding)

Pull request description:

  Move the `opcodes` module to the new `primitives` crate. This is pretty straight forward, some things to note:

  - Are we ok with the public wildcard re-export from `blockdata`? I think so because the whole `blockdata` module should, IMO, be deleted after everything in it is moved to `primitives`.

  - `decode_pushnum` becomes public.

ACKs for top commit:
  Kixunil:
    ACK 9a586987d1
  apoelstra:
    ACK 9a586987d1

Tree-SHA512: ee9fa0ae4265f54ff7784dc873abc12572852c32ff24456e34cd6a8a004f9e1f932e01c80d3448107fca76507db4bdaa3dfff6b5a80de0707d59a033e582fb9e
This commit is contained in:
merge-script 2024-07-10 16:32:52 +00:00
commit bcfc9dcb20
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
8 changed files with 44 additions and 5 deletions

View File

@ -55,6 +55,7 @@ dependencies = [
"bincode",
"bitcoin-internals",
"bitcoin-io",
"bitcoin-primitives",
"bitcoin-units",
"bitcoin_hashes",
"bitcoinconsensus",
@ -98,6 +99,10 @@ version = "0.1.2"
[[package]]
name = "bitcoin-primitives"
version = "0.100.0"
dependencies = [
"bitcoin-internals",
"serde",
]
[[package]]
name = "bitcoin-units"

View File

@ -54,6 +54,7 @@ dependencies = [
"bincode",
"bitcoin-internals",
"bitcoin-io",
"bitcoin-primitives",
"bitcoin-units",
"bitcoin_hashes",
"bitcoinconsensus",
@ -97,6 +98,10 @@ version = "0.1.2"
[[package]]
name = "bitcoin-primitives"
version = "0.100.0"
dependencies = [
"bitcoin-internals",
"serde",
]
[[package]]
name = "bitcoin-units"

View File

@ -16,10 +16,10 @@ exclude = ["tests", "contrib"]
# If you change features or optional dependencies in any way please update the "# Cargo features" section in lib.rs as well.
[features]
default = [ "std", "secp-recovery" ]
std = ["base58/std", "bech32/std", "hashes/std", "hex/std", "internals/std", "io/std", "secp256k1/std", "units/std"]
std = ["base58/std", "bech32/std", "hashes/std", "hex/std", "internals/std", "io/std", "primitives/std", "secp256k1/std", "units/std"]
rand-std = ["secp256k1/rand-std", "std"]
rand = ["secp256k1/rand"]
serde = ["actual-serde", "hashes/serde", "internals/serde", "secp256k1/serde", "units/serde"]
serde = ["actual-serde", "hashes/serde", "internals/serde", "primitives/serde", "secp256k1/serde", "units/serde"]
secp-lowmemory = ["secp256k1/lowmemory"]
secp-recovery = ["secp256k1/recovery"]
bitcoinconsensus-std = ["bitcoinconsensus/std", "std"]
@ -31,6 +31,7 @@ hashes = { package = "bitcoin_hashes", version = "0.14.0", default-features = fa
hex = { package = "hex-conservative", version = "0.2.0", default-features = false, features = ["alloc"] }
internals = { package = "bitcoin-internals", version = "0.3.0", features = ["alloc"] }
io = { package = "bitcoin-io", version = "0.1.1", default-features = false, features = ["alloc"] }
primitives = { package = "bitcoin-primitives", version = "0.100.0", default-features = false }
secp256k1 = { version = "0.29.0", default-features = false, features = ["hashes", "alloc"] }
units = { package = "bitcoin-units", version = "0.1.0", default-features = false, features = ["alloc"] }

View File

@ -39,5 +39,8 @@ path = "../../internals"
[patch.crates-io.bitcoin-io]
path = "../../io"
[patch.crates-io.bitcoin-primitives]
path = "../../primitives"
[patch.crates-io.bitcoin-units]
path = "../../units"

View File

@ -8,7 +8,6 @@
pub mod block;
pub mod constants;
pub mod locktime;
pub mod opcodes;
pub mod script;
pub mod transaction;
pub mod witness;
@ -48,6 +47,12 @@ pub mod fee_rate {
}
}
/// Bitcoin script opcodes.
pub mod opcodes {
/// Re-export everything from the [`primitives::opcodes`] module.
pub use primitives::opcodes::*;
}
/// Implements `Weight` and associated features.
pub mod weight {
/// Re-export everything from the [`units::weight`] module.

View File

@ -16,9 +16,14 @@ exclude = ["tests", "contrib"]
[features]
default = ["std"]
std = []
std = ["internals/std"]
serde = ["actual-serde", "internals/serde"]
[dependencies]
internals = { package = "bitcoin-internals", version = "0.3.0", features = ["alloc"] }
# Do NOT use this as a feature! Use the `serde` feature instead.
actual-serde = { package = "serde", version = "1.0.103", default-features = false, features = [ "alloc" ], optional = true }
[dev-dependencies]

View File

@ -20,3 +20,18 @@ extern crate alloc;
#[cfg(feature = "std")]
extern crate std;
#[cfg(feature = "serde")]
extern crate actual_serde as serde;
pub mod opcodes;
#[rustfmt::skip]
#[allow(unused_imports)]
mod prelude {
#[cfg(all(not(feature = "std"), not(test)))]
pub use alloc::string::ToString;
#[cfg(any(feature = "std", test))]
pub use std::string::ToString;
}

View File

@ -424,7 +424,7 @@ impl Opcode {
///
/// Returns `None` if `self` is not a PUSHNUM.
#[inline]
pub(crate) const fn decode_pushnum(self) -> Option<u8> {
pub const fn decode_pushnum(self) -> Option<u8> {
const START: u8 = OP_PUSHNUM_1.code;
const END: u8 = OP_PUSHNUM_16.code;
match self.code {