Skip to content

Commit 9a58698

Browse files
committed
Move opcodes to primitives
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. Includes addition of a `patch` section for `primitives` in the `bitcoin/embedded` crate.
1 parent b9f1dba commit 9a58698

File tree

8 files changed

+44
-5
lines changed

8 files changed

+44
-5
lines changed

Cargo-minimal.lock

+5
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ dependencies = [
5555
"bincode",
5656
"bitcoin-internals",
5757
"bitcoin-io",
58+
"bitcoin-primitives",
5859
"bitcoin-units",
5960
"bitcoin_hashes",
6061
"bitcoinconsensus",
@@ -98,6 +99,10 @@ version = "0.1.2"
9899
[[package]]
99100
name = "bitcoin-primitives"
100101
version = "0.100.0"
102+
dependencies = [
103+
"bitcoin-internals",
104+
"serde",
105+
]
101106

102107
[[package]]
103108
name = "bitcoin-units"

Cargo-recent.lock

+5
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ dependencies = [
5454
"bincode",
5555
"bitcoin-internals",
5656
"bitcoin-io",
57+
"bitcoin-primitives",
5758
"bitcoin-units",
5859
"bitcoin_hashes",
5960
"bitcoinconsensus",
@@ -97,6 +98,10 @@ version = "0.1.2"
9798
[[package]]
9899
name = "bitcoin-primitives"
99100
version = "0.100.0"
101+
dependencies = [
102+
"bitcoin-internals",
103+
"serde",
104+
]
100105

101106
[[package]]
102107
name = "bitcoin-units"

bitcoin/Cargo.toml

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ exclude = ["tests", "contrib"]
1616
# If you change features or optional dependencies in any way please update the "# Cargo features" section in lib.rs as well.
1717
[features]
1818
default = [ "std", "secp-recovery" ]
19-
std = ["base58/std", "bech32/std", "hashes/std", "hex/std", "internals/std", "io/std", "secp256k1/std", "units/std"]
19+
std = ["base58/std", "bech32/std", "hashes/std", "hex/std", "internals/std", "io/std", "primitives/std", "secp256k1/std", "units/std"]
2020
rand-std = ["secp256k1/rand-std", "std"]
2121
rand = ["secp256k1/rand"]
22-
serde = ["actual-serde", "hashes/serde", "internals/serde", "secp256k1/serde", "units/serde"]
22+
serde = ["actual-serde", "hashes/serde", "internals/serde", "primitives/serde", "secp256k1/serde", "units/serde"]
2323
secp-lowmemory = ["secp256k1/lowmemory"]
2424
secp-recovery = ["secp256k1/recovery"]
2525
bitcoinconsensus-std = ["bitcoinconsensus/std", "std"]
@@ -31,6 +31,7 @@ hashes = { package = "bitcoin_hashes", version = "0.14.0", default-features = fa
3131
hex = { package = "hex-conservative", version = "0.2.0", default-features = false, features = ["alloc"] }
3232
internals = { package = "bitcoin-internals", version = "0.3.0", features = ["alloc"] }
3333
io = { package = "bitcoin-io", version = "0.1.1", default-features = false, features = ["alloc"] }
34+
primitives = { package = "bitcoin-primitives", version = "0.100.0", default-features = false }
3435
secp256k1 = { version = "0.29.0", default-features = false, features = ["hashes", "alloc"] }
3536
units = { package = "bitcoin-units", version = "0.1.0", default-features = false, features = ["alloc"] }
3637

bitcoin/embedded/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,8 @@ path = "../../internals"
3939
[patch.crates-io.bitcoin-io]
4040
path = "../../io"
4141

42+
[patch.crates-io.bitcoin-primitives]
43+
path = "../../primitives"
44+
4245
[patch.crates-io.bitcoin-units]
4346
path = "../../units"

bitcoin/src/blockdata/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
pub mod block;
99
pub mod constants;
1010
pub mod locktime;
11-
pub mod opcodes;
1211
pub mod script;
1312
pub mod transaction;
1413
pub mod witness;
@@ -48,6 +47,12 @@ pub mod fee_rate {
4847
}
4948
}
5049

50+
/// Bitcoin script opcodes.
51+
pub mod opcodes {
52+
/// Re-export everything from the [`primitives::opcodes`] module.
53+
pub use primitives::opcodes::*;
54+
}
55+
5156
/// Implements `Weight` and associated features.
5257
pub mod weight {
5358
/// Re-export everything from the [`units::weight`] module.

primitives/Cargo.toml

+6-1
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,14 @@ exclude = ["tests", "contrib"]
1616

1717
[features]
1818
default = ["std"]
19-
std = []
19+
std = ["internals/std"]
20+
serde = ["actual-serde", "internals/serde"]
2021

2122
[dependencies]
23+
internals = { package = "bitcoin-internals", version = "0.3.0", features = ["alloc"] }
24+
25+
# Do NOT use this as a feature! Use the `serde` feature instead.
26+
actual-serde = { package = "serde", version = "1.0.103", default-features = false, features = [ "alloc" ], optional = true }
2227

2328
[dev-dependencies]
2429

primitives/src/lib.rs

+15
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,18 @@ extern crate alloc;
2020

2121
#[cfg(feature = "std")]
2222
extern crate std;
23+
24+
#[cfg(feature = "serde")]
25+
extern crate actual_serde as serde;
26+
27+
pub mod opcodes;
28+
29+
#[rustfmt::skip]
30+
#[allow(unused_imports)]
31+
mod prelude {
32+
#[cfg(all(not(feature = "std"), not(test)))]
33+
pub use alloc::string::ToString;
34+
35+
#[cfg(any(feature = "std", test))]
36+
pub use std::string::ToString;
37+
}

bitcoin/src/blockdata/opcodes.rs primitives/src/opcodes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ impl Opcode {
424424
///
425425
/// Returns `None` if `self` is not a PUSHNUM.
426426
#[inline]
427-
pub(crate) const fn decode_pushnum(self) -> Option<u8> {
427+
pub const fn decode_pushnum(self) -> Option<u8> {
428428
const START: u8 = OP_PUSHNUM_1.code;
429429
const END: u8 = OP_PUSHNUM_16.code;
430430
match self.code {

0 commit comments

Comments
 (0)