use miniscript::descriptor::DescriptorType;
use miniscript::{Descriptor, MiniscriptKey};
#[cfg_attr(
feature = "serde",
derive(Serialize, Deserialize),
serde(crate = "serde_crate", rename = "lowercase")
)]
#[derive(
Copy,
Clone,
PartialEq,
Eq,
PartialOrd,
Ord,
Debug,
Display,
Hash,
StrictEncode,
StrictDecode
)]
#[repr(u8)]
pub enum Category {
#[display("bare")]
Bare,
#[display("hashed")]
Hashed,
#[display("nested")]
Nested,
#[display("segwit")]
SegWit,
#[display("taproot")]
Taproot,
}
impl<Pk> From<Descriptor<Pk>> for Category
where
Pk: MiniscriptKey,
{
fn from(descriptor: Descriptor<Pk>) -> Self {
match descriptor.desc_type() {
DescriptorType::Bare => Category::Bare,
DescriptorType::Sh
| DescriptorType::ShSortedMulti
| DescriptorType::Pkh => Category::Hashed,
DescriptorType::Wpkh
| DescriptorType::WshSortedMulti
| DescriptorType::Wsh => Category::SegWit,
DescriptorType::ShWsh
| DescriptorType::ShWpkh
| DescriptorType::ShWshSortedMulti => Category::Nested,
}
}
}
impl Category {
#[inline]
pub fn is_witness(self) -> bool {
!matches!(self, Category::Bare | Category::Hashed)
}
}