[keys] impl ToDescriptorKey
for &str
This commit is contained in:
parent
7e90657ee1
commit
713411ea5d
@ -278,15 +278,20 @@ macro_rules! apply_modifier {
|
|||||||
/// cannot be grouped together. For instance, a descriptor fragment like `sdv:older(144)` has to be
|
/// cannot be grouped together. For instance, a descriptor fragment like `sdv:older(144)` has to be
|
||||||
/// broken up to `s:d:v:older(144)`.
|
/// broken up to `s:d:v:older(144)`.
|
||||||
///
|
///
|
||||||
|
/// The `pk()`, `pk_k()` and `pk_h()` operands can take as argument any type that implements
|
||||||
|
/// [`ToDescriptorKey`]. This means that keys can also be written inline as strings, but in that
|
||||||
|
/// case they must be wrapped in quotes, which is another difference compared to the standard
|
||||||
|
/// descriptor syntax.
|
||||||
|
///
|
||||||
|
/// [`ToDescriptorKey`]: crate::keys::ToDescriptorKey
|
||||||
|
///
|
||||||
/// ## Example
|
/// ## Example
|
||||||
///
|
///
|
||||||
/// Signature plus timelock, equivalent to: `sh(wsh(and_v(v:pk(...), older(...))))`
|
/// Signature plus timelock descriptor:
|
||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
/// # use std::str::FromStr;
|
/// # use std::str::FromStr;
|
||||||
/// let my_key = bitcoin::PublicKey::from_str("02e96fe52ef0e22d2f131dd425ce1893073a3c6ad20e8cac36726393dfb4856a4c")?;
|
/// let (my_descriptor, my_keys_map, networks) = bdk::descriptor!(sh(wsh(and_v(v:pk("cVt4o7BGAig1UXywgGSmARhxMdzP5qvQsxKkSsc1XEkw3tDTQFpy"),older(50)))))?;
|
||||||
/// let my_timelock = 50;
|
|
||||||
/// let (my_descriptor, my_keys_map, networks) = bdk::descriptor!(sh(wsh(and_v(v:pk(my_key),older(my_timelock)))))?;
|
|
||||||
/// # Ok::<(), Box<dyn std::error::Error>>(())
|
/// # Ok::<(), Box<dyn std::error::Error>>(())
|
||||||
/// ```
|
/// ```
|
||||||
///
|
///
|
||||||
|
@ -28,6 +28,7 @@ use std::any::TypeId;
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
use bitcoin::secp256k1;
|
use bitcoin::secp256k1;
|
||||||
|
|
||||||
@ -661,6 +662,14 @@ impl<Ctx: ScriptContext> ToDescriptorKey<Ctx> for DescriptorSecretKey {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<Ctx: ScriptContext> ToDescriptorKey<Ctx> for &'_ str {
|
||||||
|
fn to_descriptor_key(self) -> Result<DescriptorKey<Ctx>, KeyError> {
|
||||||
|
DescriptorSecretKey::from_str(self)
|
||||||
|
.map_err(|e| KeyError::Message(e.to_string()))?
|
||||||
|
.to_descriptor_key()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<Ctx: ScriptContext> ToDescriptorKey<Ctx> for PrivateKey {
|
impl<Ctx: ScriptContext> ToDescriptorKey<Ctx> for PrivateKey {
|
||||||
fn to_descriptor_key(self) -> Result<DescriptorKey<Ctx>, KeyError> {
|
fn to_descriptor_key(self) -> Result<DescriptorKey<Ctx>, KeyError> {
|
||||||
DescriptorSecretKey::SinglePriv(DescriptorSinglePriv {
|
DescriptorSecretKey::SinglePriv(DescriptorSinglePriv {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user