Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Turn strict_encoding optional #75

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
410 changes: 256 additions & 154 deletions Cargo.lock

Large diffs are not rendered by default.

32 changes: 21 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@ edition = "2021"
rust-version = "1.65.0" # due to let .. else

[workspace.dependencies]
amplify = "3.14.2"
strict_encoding = "0.9.0"
amplify = "4.0.0"
secp256k1 = { version = "0.24.3", features = ["global-context"] }
bitcoin = "0.29.2"
bitcoin_scripts = "0.10.0"
bitcoin_blockchain = "0.10.0"
bitcoin_hd = { version = "0.10.0", path = "./hd" }
bitcoin_onchain = { version = "0.10.0", path = "./onchain" }
descriptors = { version = "0.10.0", path = "./descriptors", default-features = false }
psbt = { version = "0.10.0", path = "./psbt", default-features = false }
slip132 = { version = "0.10.0", path = "./slip132" }
bitcoin_scripts = { version = "0.10.0", default-features = false }
bitcoin_blockchain = { version = "0.10.0", default-features = false }
bitcoin_hd = { version = "0.10.1", path = "./hd", default-features = false }
bitcoin_onchain = { version = "0.10.1", path = "./onchain", default-features = false }
descriptors = { version = "0.10.1", path = "./descriptors", default-features = false }
psbt = { version = "0.10.1", path = "./psbt", default-features = false }
slip132 = { version = "0.10.1", path = "./slip132" }
miniscript_crate = { package = "miniscript", version = "9.0.1" }
chrono = "0.4.19"

Expand Down Expand Up @@ -106,7 +105,6 @@ all = [
]
mobile = ["miniscript", "compiler", "electrum", "strict_encoding", "hot", "construct"]
miniscript = [
"strict_encoding_crate/miniscript",
"bitcoin_hd/miniscript",
"bitcoin_onchain/miniscript_descriptors",
"descriptors/miniscript",
Expand All @@ -118,8 +116,15 @@ electrum = [
"bitcoin_onchain/electrum"
]
strict_encoding = [
"slip132/strict_encoding"
"strict_encoding_crate/miniscript",
"bitcoin_blockchain/strict_encoding",
"bitcoin_hd/strict_encoding",
"bitcoin_scripts/strict_encoding",
"slip132/strict_encoding",
"psbt/strict_encoding",
"descriptors/strict_encoding",
]

sign = ["psbt/sign"]
construct = ["psbt/construct"]
hot = [
Expand Down Expand Up @@ -152,3 +157,8 @@ serde = [
"psbt/serde",
"descriptors/serde"
]

[patch.crates-io]
# Remove after merge and release https://github.com/BP-WG/bitcoin_foundation/pull/20
bitcoin_scripts = { git = "https://github.com/crisdut/bp-foundation", branch = "feat/bump-amplify-4" }
bitcoin_blockchain = { git = "https://github.com/crisdut/bp-foundation", branch = "feat/bump-amplify-4" }
7 changes: 4 additions & 3 deletions descriptors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ exclude = []

[dependencies]
amplify = { workspace = true }
strict_encoding = { workspace = true }
bitcoin = { workspace = true }
bitcoin_scripts = { workspace = true }
bitcoin_blockchain = { workspace = true }
Expand All @@ -24,12 +23,14 @@ miniscript_crate = { workspace = true, features = ["compiler"], optional = true
chrono = { workspace = true }
serde_crate = { package = "serde", version = "1", optional = true }
serde_with = { version = "2.3", features = ["hex"], optional = true }
strict_encoding = { version = "0.9.0", optional = true }

[features]
all = [
"rand",
"miniscript",
"serde"
"serde",
"strict_encoding",
]
default = []
rand = [
Expand All @@ -44,4 +45,4 @@ serde = [
"serde_crate",
"serde_with",
"bitcoin_scripts/serde"
]
]
21 changes: 11 additions & 10 deletions descriptors/src/descriptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
use std::fmt::{self, Display, Formatter};
use std::str::FromStr;

use amplify::Wrapper;
use bitcoin::hashes::Hash;
use bitcoin::schnorr::{TweakedPublicKey, UntweakedPublicKey};
use bitcoin::secp256k1::{self, Secp256k1, Verification};
Expand All @@ -30,9 +29,11 @@ use miniscript::descriptor::DescriptorType;
use miniscript::policy::compiler::CompilerError;
#[cfg(feature = "miniscript")]
use miniscript::{Descriptor, MiniscriptKey, Terminal};
#[cfg(feature = "strict_encoding")]
use strict_encoding::{self, StrictDecode, StrictEncode};

#[derive(Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
#[derive(StrictEncode, StrictDecode)]
#[cfg_attr(feature = "strict_encoding", derive(StrictEncode, StrictDecode))]
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
Expand Down Expand Up @@ -97,7 +98,7 @@ impl DescriptorClass {
#[derive(
Clone, Copy, Ord, PartialOrd, Eq, PartialEq, Hash, Default, Debug, Display
)]
#[derive(StrictEncode, StrictDecode)]
#[cfg_attr(feature = "strict_encoding", derive(StrictEncode, StrictDecode))]
#[repr(u8)]
pub enum SpkClass {
#[display("bare")]
Expand Down Expand Up @@ -203,7 +204,7 @@ impl FromStr for SpkClass {
serde(crate = "serde_crate")
)]
#[derive(Clone, Copy, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display)]
#[derive(StrictEncode, StrictDecode)]
#[cfg_attr(feature = "strict_encoding", derive(StrictEncode, StrictDecode))]
#[repr(u8)]
pub enum CompositeDescrType {
#[display("bare")]
Expand Down Expand Up @@ -328,7 +329,7 @@ impl FromStr for CompositeDescrType {
serde(crate = "serde_crate")
)]
#[derive(Clone, Copy, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display)]
#[derive(StrictEncode, StrictDecode)]
#[cfg_attr(feature = "strict_encoding", derive(StrictEncode, StrictDecode))]
#[repr(u8)]
pub enum OuterDescrType {
#[display("bare")]
Expand Down Expand Up @@ -410,8 +411,8 @@ impl FromStr for OuterDescrType {
derive(Serialize, Deserialize),
serde(crate = "serde_crate")
)]
#[cfg_attr(feature = "strict_encoding", derive(StrictEncode, StrictDecode))]
#[derive(Clone, Copy, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Display)]
#[derive(StrictEncode, StrictDecode)]
#[repr(u8)]
pub enum InnerDescrType {
#[display("bare")]
Expand Down Expand Up @@ -494,7 +495,7 @@ impl FromStr for InnerDescrType {
serde(crate = "serde_crate")
)]
#[derive(Clone, Copy, Ord, PartialOrd, Eq, PartialEq, Hash, Debug, Default)]
#[derive(StrictEncode, StrictDecode)]
#[cfg_attr(feature = "strict_encoding", derive(StrictEncode, StrictDecode))]
#[repr(C)]
pub struct DescrVariants {
pub bare: bool,
Expand Down Expand Up @@ -566,7 +567,7 @@ impl DescrVariants {
}

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

fn try_from(spk: PubkeyScript) -> Result<Self, Self::Error> {
let script = spk.as_inner();
let script = spk.clone();
let bytes = script.as_bytes();
match (&spk, spk.witness_version()) {
(spk, _) if spk.is_p2pk() && script.len() == 67 => Ok(ScriptPubkeyDescr::Pk(
Expand Down Expand Up @@ -707,7 +708,7 @@ impl TryFrom<PubkeyScript> for ScriptPubkeyDescr {
/// Descriptors exposing bare scripts (unlike [`miniscript::Descriptor`] which
/// uses miniscript representation of the scripts).
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[derive(StrictEncode, StrictDecode)]
#[cfg_attr(feature = "strict_encoding", derive(StrictEncode, StrictDecode))]
#[non_exhaustive]
pub enum BareDescriptor {
Bare(PubkeyScript),
Expand Down
2 changes: 1 addition & 1 deletion descriptors/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use bitcoin_blockchain::locks::{self, SeqNo};
use bitcoin_hd::{DerivationSubpath, UnhardenedIndex};

#[derive(Clone, PartialEq, Eq, Debug)]
#[derive(StrictEncode, StrictDecode)]
#[cfg_attr(feature = "strict_encoding", derive(StrictEncode, StrictDecode))]
pub struct InputDescriptor {
pub outpoint: OutPoint,
pub terminal: DerivationSubpath<UnhardenedIndex>,
Expand Down
1 change: 1 addition & 0 deletions descriptors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#[macro_use]
extern crate amplify;
#[cfg(feature = "strict_encoding")]
#[macro_use]
extern crate strict_encoding;
#[cfg(feature = "miniscript")]
Expand Down
Loading
Loading