Skip to content

Commit

Permalink
feat: add strict_encoding optional
Browse files Browse the repository at this point in the history
  • Loading branch information
crisdut committed Oct 26, 2023
1 parent 3525ada commit da2abbd
Show file tree
Hide file tree
Showing 18 changed files with 305 additions and 150 deletions.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ electrum = [
"bitcoin_onchain/electrum"
]
strict_encoding = [
"slip132/strict_encoding"
"slip132/strict_encoding",
"psbt/strict_encoding",
"descriptors/strict_encoding",
]
sign = ["psbt/sign"]
construct = ["psbt/construct"]
Expand Down
5 changes: 3 additions & 2 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 = { workspace = true, optional = true }

[features]
all = [
"rand",
"miniscript",
"serde"
"serde",
"strict_encoding"
]
default = []
rand = [
Expand Down
19 changes: 9 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 @@ -32,7 +31,7 @@ use miniscript::policy::compiler::CompilerError;
use miniscript::{Descriptor, MiniscriptKey, Terminal};

#[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 +96,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 +202,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 +327,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 +409,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 +493,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 +565,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 +662,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 +706,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
1 change: 0 additions & 1 deletion descriptors/src/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ use bitcoin_blockchain::locks::{self, SeqNo};
use bitcoin_hd::{DerivationSubpath, UnhardenedIndex};

#[derive(Clone, PartialEq, Eq, Debug)]
#[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

0 comments on commit da2abbd

Please sign in to comment.