Skip to content

Commit d9d754b

Browse files
committed
feat: turn strict encoding optional
1 parent 3525ada commit d9d754b

31 files changed

Lines changed: 607 additions & 330 deletions

Cargo.lock

Lines changed: 256 additions & 154 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,16 @@ edition = "2021"
1515
rust-version = "1.65.0" # due to let .. else
1616

1717
[workspace.dependencies]
18-
amplify = "3.14.2"
19-
strict_encoding = "0.9.0"
18+
amplify = "4.0.0"
2019
secp256k1 = { version = "0.24.3", features = ["global-context"] }
2120
bitcoin = "0.29.2"
22-
bitcoin_scripts = "0.10.0"
23-
bitcoin_blockchain = "0.10.0"
24-
bitcoin_hd = { version = "0.10.0", path = "./hd" }
25-
bitcoin_onchain = { version = "0.10.0", path = "./onchain" }
26-
descriptors = { version = "0.10.0", path = "./descriptors", default-features = false }
27-
psbt = { version = "0.10.0", path = "./psbt", default-features = false }
28-
slip132 = { version = "0.10.0", path = "./slip132" }
21+
bitcoin_scripts = { version = "0.10.0", default-features = false }
22+
bitcoin_blockchain = { version = "0.10.0", default-features = false }
23+
bitcoin_hd = { version = "0.10.1", path = "./hd", default-features = false }
24+
bitcoin_onchain = { version = "0.10.1", path = "./onchain", default-features = false }
25+
descriptors = { version = "0.10.1", path = "./descriptors", default-features = false }
26+
psbt = { version = "0.10.1", path = "./psbt", default-features = false }
27+
slip132 = { version = "0.10.1", path = "./slip132" }
2928
miniscript_crate = { package = "miniscript", version = "9.0.1" }
3029
chrono = "0.4.19"
3130

@@ -106,7 +105,6 @@ all = [
106105
]
107106
mobile = ["miniscript", "compiler", "electrum", "strict_encoding", "hot", "construct"]
108107
miniscript = [
109-
"strict_encoding_crate/miniscript",
110108
"bitcoin_hd/miniscript",
111109
"bitcoin_onchain/miniscript_descriptors",
112110
"descriptors/miniscript",
@@ -118,8 +116,15 @@ electrum = [
118116
"bitcoin_onchain/electrum"
119117
]
120118
strict_encoding = [
121-
"slip132/strict_encoding"
119+
"strict_encoding_crate/miniscript",
120+
"bitcoin_blockchain/strict_encoding",
121+
"bitcoin_hd/strict_encoding",
122+
"bitcoin_scripts/strict_encoding",
123+
"slip132/strict_encoding",
124+
"psbt/strict_encoding",
125+
"descriptors/strict_encoding",
122126
]
127+
123128
sign = ["psbt/sign"]
124129
construct = ["psbt/construct"]
125130
hot = [
@@ -152,3 +157,8 @@ serde = [
152157
"psbt/serde",
153158
"descriptors/serde"
154159
]
160+
161+
[patch.crates-io]
162+
# Remove after merge and release https://github.com/BP-WG/bitcoin_foundation/pull/20
163+
bitcoin_scripts = { git = "https://github.com/crisdut/bp-foundation", branch = "feat/bump-amplify-4" }
164+
bitcoin_blockchain = { git = "https://github.com/crisdut/bp-foundation", branch = "feat/bump-amplify-4" }

descriptors/Cargo.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ exclude = []
1515

1616
[dependencies]
1717
amplify = { workspace = true }
18-
strict_encoding = { workspace = true }
1918
bitcoin = { workspace = true }
2019
bitcoin_scripts = { workspace = true }
2120
bitcoin_blockchain = { workspace = true }
@@ -24,12 +23,14 @@ miniscript_crate = { workspace = true, features = ["compiler"], optional = true
2423
chrono = { workspace = true }
2524
serde_crate = { package = "serde", version = "1", optional = true }
2625
serde_with = { version = "2.3", features = ["hex"], optional = true }
26+
strict_encoding = { version = "0.9.0", optional = true }
2727

2828
[features]
2929
all = [
3030
"rand",
3131
"miniscript",
32-
"serde"
32+
"serde",
33+
"strict_encoding",
3334
]
3435
default = []
3536
rand = [
@@ -44,4 +45,4 @@ serde = [
4445
"serde_crate",
4546
"serde_with",
4647
"bitcoin_scripts/serde"
47-
]
48+
]

descriptors/src/descriptor.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use std::fmt::{self, Display, Formatter};
1313
use std::str::FromStr;
1414

15-
use amplify::Wrapper;
1615
use bitcoin::hashes::Hash;
1716
use bitcoin::schnorr::{TweakedPublicKey, UntweakedPublicKey};
1817
use bitcoin::secp256k1::{self, Secp256k1, Verification};
@@ -30,9 +29,11 @@ use miniscript::descriptor::DescriptorType;
3029
use miniscript::policy::compiler::CompilerError;
3130
#[cfg(feature = "miniscript")]
3231
use miniscript::{Descriptor, MiniscriptKey, Terminal};
32+
#[cfg(feature = "strict_encoding")]
33+
use strict_encoding::{self, StrictDecode, StrictEncode};
3334

3435
#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
35-
#[derive(StrictEncode, StrictDecode)]
36+
#[cfg_attr(feature = "strict_encoding", derive(StrictEncode, StrictDecode))]
3637
#[cfg_attr(
3738
feature = "serde",
3839
derive(Serialize, Deserialize),
@@ -97,7 +98,7 @@ impl DescriptorClass {
9798
#[derive(
9899
Clone, Copy, Ord, PartialOrd, Eq, PartialEq, Hash, Default, Debug, Display
99100
)]
100-
#[derive(StrictEncode, StrictDecode)]
101+
#[cfg_attr(feature = "strict_encoding", derive(StrictEncode, StrictDecode))]
101102
#[repr(u8)]
102103
pub enum SpkClass {
103104
#[display("bare")]
@@ -203,7 +204,7 @@ impl FromStr for SpkClass {
203204
serde(crate = "serde_crate")
204205
)]
205206
#[derive(Clone, Copy, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display)]
206-
#[derive(StrictEncode, StrictDecode)]
207+
#[cfg_attr(feature = "strict_encoding", derive(StrictEncode, StrictDecode))]
207208
#[repr(u8)]
208209
pub enum CompositeDescrType {
209210
#[display("bare")]
@@ -328,7 +329,7 @@ impl FromStr for CompositeDescrType {
328329
serde(crate = "serde_crate")
329330
)]
330331
#[derive(Clone, Copy, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display)]
331-
#[derive(StrictEncode, StrictDecode)]
332+
#[cfg_attr(feature = "strict_encoding", derive(StrictEncode, StrictDecode))]
332333
#[repr(u8)]
333334
pub enum OuterDescrType {
334335
#[display("bare")]
@@ -410,8 +411,8 @@ impl FromStr for OuterDescrType {
410411
derive(Serialize, Deserialize),
411412
serde(crate = "serde_crate")
412413
)]
414+
#[cfg_attr(feature = "strict_encoding", derive(StrictEncode, StrictDecode))]
413415
#[derive(Clone, Copy, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display)]
414-
#[derive(StrictEncode, StrictDecode)]
415416
#[repr(u8)]
416417
pub enum InnerDescrType {
417418
#[display("bare")]
@@ -494,7 +495,7 @@ impl FromStr for InnerDescrType {
494495
serde(crate = "serde_crate")
495496
)]
496497
#[derive(Clone, Copy, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Default)]
497-
#[derive(StrictEncode, StrictDecode)]
498+
#[cfg_attr(feature = "strict_encoding", derive(StrictEncode, StrictDecode))]
498499
#[repr(C)]
499500
pub struct DescrVariants {
500501
pub bare: bool,
@@ -566,7 +567,7 @@ impl DescrVariants {
566567
}
567568

568569
#[derive(Clone, PartialOrd, Ord, PartialEq, Eq, Hash, Debug, Display)]
569-
#[derive(StrictEncode, StrictDecode)]
570+
#[cfg_attr(feature = "strict_encoding", derive(StrictEncode, StrictDecode))]
570571
#[non_exhaustive]
571572
pub enum ScriptPubkeyDescr {
572573
#[display("bare({0})", alt = "bare({0:#})")]
@@ -663,7 +664,7 @@ impl TryFrom<PubkeyScript> for ScriptPubkeyDescr {
663664
type Error = UnsupportedScriptPubkey;
664665

665666
fn try_from(spk: PubkeyScript) -> Result<Self, Self::Error> {
666-
let script = spk.as_inner();
667+
let script = spk.clone();
667668
let bytes = script.as_bytes();
668669
match (&spk, spk.witness_version()) {
669670
(spk, _) if spk.is_p2pk() && script.len() == 67 => Ok(ScriptPubkeyDescr::Pk(
@@ -707,7 +708,7 @@ impl TryFrom<PubkeyScript> for ScriptPubkeyDescr {
707708
/// Descriptors exposing bare scripts (unlike [`miniscript::Descriptor`] which
708709
/// uses miniscript representation of the scripts).
709710
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
710-
#[derive(StrictEncode, StrictDecode)]
711+
#[cfg_attr(feature = "strict_encoding", derive(StrictEncode, StrictDecode))]
711712
#[non_exhaustive]
712713
pub enum BareDescriptor {
713714
Bare(PubkeyScript),

descriptors/src/input.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use bitcoin_blockchain::locks::{self, SeqNo};
2121
use bitcoin_hd::{DerivationSubpath, UnhardenedIndex};
2222

2323
#[derive(Clone, PartialEq, Eq, Debug)]
24-
#[derive(StrictEncode, StrictDecode)]
24+
#[cfg_attr(feature = "strict_encoding", derive(StrictEncode, StrictDecode))]
2525
pub struct InputDescriptor {
2626
pub outpoint: OutPoint,
2727
pub terminal: DerivationSubpath<UnhardenedIndex>,

descriptors/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
2323
#[macro_use]
2424
extern crate amplify;
25+
#[cfg(feature = "strict_encoding")]
2526
#[macro_use]
2627
extern crate strict_encoding;
2728
#[cfg(feature = "miniscript")]

0 commit comments

Comments
 (0)