Skip to content
Open
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
2 changes: 1 addition & 1 deletion bitcoind-tests/tests/test_desc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ fn test_plan_satisfy(

let plan = definite_desc
.clone()
.plan(&assets)
.into_plan(&assets)
.expect("plan creation failed");

let mut unsigned_tx = Transaction {
Expand Down
34 changes: 10 additions & 24 deletions src/descriptor/bare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use core::fmt;
use bitcoin::script::{self, PushBytes};
use bitcoin::{Address, Network, ScriptBuf, Weight};

use crate::descriptor::{write_descriptor, DefiniteDescriptorKey};
use crate::descriptor::write_descriptor;
use crate::expression::{self, FromTree};
use crate::miniscript::context::{ScriptContext, ScriptContextError};
use crate::miniscript::satisfy::{Placeholder, Satisfaction, Witness};
Expand Down Expand Up @@ -138,25 +138,19 @@ impl<Pk: MiniscriptKey + ToPublicKey> Bare<Pk> {
}
}

impl Bare<DefiniteDescriptorKey> {
impl<Pk: MiniscriptKey + ToPublicKey> Bare<Pk> {
/// Returns a plan if the provided assets are sufficient to produce a non-malleable satisfaction
pub fn plan_satisfaction<P>(
&self,
provider: &P,
) -> Satisfaction<Placeholder<DefiniteDescriptorKey>>
pub fn plan_satisfaction<P>(&self, provider: &P) -> Satisfaction<Placeholder<Pk>>
where
P: AssetProvider<DefiniteDescriptorKey>,
P: AssetProvider<Pk>,
{
self.ms.build_template(provider)
}

/// Returns a plan if the provided assets are sufficient to produce a malleable satisfaction
pub fn plan_satisfaction_mall<P>(
&self,
provider: &P,
) -> Satisfaction<Placeholder<DefiniteDescriptorKey>>
pub fn plan_satisfaction_mall<P>(&self, provider: &P) -> Satisfaction<Placeholder<Pk>>
where
P: AssetProvider<DefiniteDescriptorKey>,
P: AssetProvider<Pk>,
{
self.ms.build_template_mall(provider)
}
Expand Down Expand Up @@ -316,16 +310,11 @@ impl<Pk: MiniscriptKey + ToPublicKey> Pkh<Pk> {
{
self.get_satisfaction(satisfier)
}
}

impl Pkh<DefiniteDescriptorKey> {
/// Returns a plan if the provided assets are sufficient to produce a non-malleable satisfaction
pub fn plan_satisfaction<P>(
&self,
provider: &P,
) -> Satisfaction<Placeholder<DefiniteDescriptorKey>>
pub fn plan_satisfaction<P>(&self, provider: &P) -> Satisfaction<Placeholder<Pk>>
where
P: AssetProvider<DefiniteDescriptorKey>,
P: AssetProvider<Pk>,
{
let stack = if provider.provider_lookup_ecdsa_sig(&self.pk) {
let stack = vec![
Expand All @@ -341,12 +330,9 @@ impl Pkh<DefiniteDescriptorKey> {
}

/// Returns a plan if the provided assets are sufficient to produce a malleable satisfaction
pub fn plan_satisfaction_mall<P>(
&self,
provider: &P,
) -> Satisfaction<Placeholder<DefiniteDescriptorKey>>
pub fn plan_satisfaction_mall<P>(&self, provider: &P) -> Satisfaction<Placeholder<Pk>>
where
P: AssetProvider<DefiniteDescriptorKey>,
P: AssetProvider<Pk>,
{
self.plan_satisfaction(provider)
}
Expand Down
34 changes: 29 additions & 5 deletions src/descriptor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,14 +552,26 @@ impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {
}
}

impl Descriptor<DefiniteDescriptorKey> {
impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {
/// Returns a plan if the provided assets are sufficient to produce a non-malleable satisfaction
///
/// If the assets aren't sufficient for generating a Plan, the descriptor is returned
#[deprecated(since = "TBD", note = "use into_plan instead")]
#[allow(clippy::result_large_err)] // our "error type" is the original descriptor
pub fn plan<P>(self, provider: &P) -> Result<Plan<Pk>, Self>
where
P: AssetProvider<Pk>,
{
self.into_plan(provider)
}

/// Returns a plan if the provided assets are sufficient to produce a non-malleable satisfaction
///
/// If the assets aren't sufficient for generating a Plan, the descriptor is returned
#[allow(clippy::result_large_err)] // our "error type" is the original descriptor
pub fn plan<P>(self, provider: &P) -> Result<Plan, Self>
pub fn into_plan<P>(self, provider: &P) -> Result<Plan<Pk>, Self>
where
P: AssetProvider<DefiniteDescriptorKey>,
P: AssetProvider<Pk>,
{
let satisfaction = match self {
Descriptor::Bare(ref bare) => bare.plan_satisfaction(provider),
Expand All @@ -582,13 +594,25 @@ impl Descriptor<DefiniteDescriptorKey> {
}
}

/// Returns a plan if the provided assets are sufficient to produce a malleable satisfaction
///
/// If the assets aren't sufficient for generating a Plan, the descriptor is returned
#[deprecated(since = "TBD", note = "use into_plan_mall instead")]
#[allow(clippy::result_large_err)] // our "error type" is the original descriptor
pub fn plan_mall<P>(self, provider: &P) -> Result<Plan<Pk>, Self>
where
P: AssetProvider<Pk>,
{
self.into_plan_mall(provider)
}

/// Returns a plan if the provided assets are sufficient to produce a malleable satisfaction
///
/// If the assets aren't sufficient for generating a Plan, the descriptor is returned
#[allow(clippy::result_large_err)] // our "error type" is the original descriptor
pub fn plan_mall<P>(self, provider: &P) -> Result<Plan, Self>
pub fn into_plan_mall<P>(self, provider: &P) -> Result<Plan<Pk>, Self>
where
P: AssetProvider<DefiniteDescriptorKey>,
P: AssetProvider<Pk>,
{
let satisfaction = match self {
Descriptor::Bare(ref bare) => bare.plan_satisfaction_mall(provider),
Expand Down
34 changes: 9 additions & 25 deletions src/descriptor/segwitv0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use core::fmt;

use bitcoin::{Address, Network, ScriptBuf, Weight};

use crate::descriptor::{write_descriptor, DefiniteDescriptorKey};
use crate::descriptor::write_descriptor;
use crate::expression::{self, FromTree};
use crate::miniscript::context::{ScriptContext, ScriptContextError};
use crate::miniscript::limits::MAX_PUBKEYS_PER_MULTISIG;
Expand Down Expand Up @@ -159,27 +159,19 @@ impl<Pk: MiniscriptKey + ToPublicKey> Wsh<Pk> {
let script_sig = ScriptBuf::new();
Ok((witness, script_sig))
}
}

impl Wsh<DefiniteDescriptorKey> {
/// Returns a plan if the provided assets are sufficient to produce a non-malleable satisfaction
pub fn plan_satisfaction<P>(
&self,
provider: &P,
) -> Satisfaction<Placeholder<DefiniteDescriptorKey>>
pub fn plan_satisfaction<P>(&self, provider: &P) -> Satisfaction<Placeholder<Pk>>
where
P: AssetProvider<DefiniteDescriptorKey>,
P: AssetProvider<Pk>,
{
self.ms.build_template(provider)
}

/// Returns a plan if the provided assets are sufficient to produce a malleable satisfaction
pub fn plan_satisfaction_mall<P>(
&self,
provider: &P,
) -> Satisfaction<Placeholder<DefiniteDescriptorKey>>
pub fn plan_satisfaction_mall<P>(&self, provider: &P) -> Satisfaction<Placeholder<Pk>>
where
P: AssetProvider<DefiniteDescriptorKey>,
P: AssetProvider<Pk>,
{
if let Terminal::SortedMulti(..) = self.ms.node {
self.ms.build_template(provider)
Expand Down Expand Up @@ -363,16 +355,11 @@ impl<Pk: MiniscriptKey + ToPublicKey> Wpkh<Pk> {
{
self.get_satisfaction(satisfier)
}
}

impl Wpkh<DefiniteDescriptorKey> {
/// Returns a plan if the provided assets are sufficient to produce a non-malleable satisfaction
pub fn plan_satisfaction<P>(
&self,
provider: &P,
) -> Satisfaction<Placeholder<DefiniteDescriptorKey>>
pub fn plan_satisfaction<P>(&self, provider: &P) -> Satisfaction<Placeholder<Pk>>
where
P: AssetProvider<DefiniteDescriptorKey>,
P: AssetProvider<Pk>,
{
let stack = if provider.provider_lookup_ecdsa_sig(&self.pk) {
let stack = vec![
Expand All @@ -388,12 +375,9 @@ impl Wpkh<DefiniteDescriptorKey> {
}

/// Returns a plan if the provided assets are sufficient to produce a malleable satisfaction
pub fn plan_satisfaction_mall<P>(
&self,
provider: &P,
) -> Satisfaction<Placeholder<DefiniteDescriptorKey>>
pub fn plan_satisfaction_mall<P>(&self, provider: &P) -> Satisfaction<Placeholder<Pk>>
where
P: AssetProvider<DefiniteDescriptorKey>,
P: AssetProvider<Pk>,
{
self.plan_satisfaction(provider)
}
Expand Down
18 changes: 5 additions & 13 deletions src/descriptor/sh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use bitcoin::script::PushBytes;
use bitcoin::{script, Address, Network, ScriptBuf, Weight};

use super::{Wpkh, Wsh};
use crate::descriptor::{write_descriptor, DefiniteDescriptorKey};
use crate::descriptor::write_descriptor;
use crate::expression::{self, FromTree};
use crate::miniscript::context::ScriptContext;
use crate::miniscript::limits::MAX_PUBKEYS_PER_MULTISIG;
Expand Down Expand Up @@ -377,16 +377,11 @@ impl<Pk: MiniscriptKey + ToPublicKey> Sh<Pk> {
_ => self.get_satisfaction(satisfier),
}
}
}

impl Sh<DefiniteDescriptorKey> {
/// Returns a plan if the provided assets are sufficient to produce a non-malleable satisfaction
pub fn plan_satisfaction<P>(
&self,
provider: &P,
) -> Satisfaction<Placeholder<DefiniteDescriptorKey>>
pub fn plan_satisfaction<P>(&self, provider: &P) -> Satisfaction<Placeholder<Pk>>
where
P: AssetProvider<DefiniteDescriptorKey>,
P: AssetProvider<Pk>,
{
match &self.inner {
ShInner::Wsh(ref wsh) => wsh.plan_satisfaction(provider),
Expand All @@ -396,12 +391,9 @@ impl Sh<DefiniteDescriptorKey> {
}

/// Returns a plan if the provided assets are sufficient to produce a malleable satisfaction
pub fn plan_satisfaction_mall<P>(
&self,
provider: &P,
) -> Satisfaction<Placeholder<DefiniteDescriptorKey>>
pub fn plan_satisfaction_mall<P>(&self, provider: &P) -> Satisfaction<Placeholder<Pk>>
where
P: AssetProvider<DefiniteDescriptorKey>,
P: AssetProvider<Pk>,
{
match &self.inner {
ShInner::Wsh(ref wsh) => wsh.plan_satisfaction_mall(provider),
Expand Down
17 changes: 4 additions & 13 deletions src/descriptor/tr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use bitcoin::{opcodes, Address, Network, ScriptBuf, Weight};
use sync::Arc;

use super::checksum;
use crate::descriptor::DefiniteDescriptorKey;
use crate::expression::{self, FromTree};
use crate::miniscript::satisfy::{Placeholder, Satisfaction, SchnorrSigType, Witness};
use crate::miniscript::Miniscript;
Expand Down Expand Up @@ -318,27 +317,19 @@ impl<Pk: MiniscriptKey + ToPublicKey> Tr<Pk> {
Err(Error::CouldNotSatisfy)
}
}
}

impl Tr<DefiniteDescriptorKey> {
/// Returns a plan if the provided assets are sufficient to produce a non-malleable satisfaction
pub fn plan_satisfaction<P>(
&self,
provider: &P,
) -> Satisfaction<Placeholder<DefiniteDescriptorKey>>
pub fn plan_satisfaction<P>(&self, provider: &P) -> Satisfaction<Placeholder<Pk>>
where
P: AssetProvider<DefiniteDescriptorKey>,
P: AssetProvider<Pk>,
{
best_tap_spend(self, provider, false /* allow_mall */)
}

/// Returns a plan if the provided assets are sufficient to produce a malleable satisfaction
pub fn plan_satisfaction_mall<P>(
&self,
provider: &P,
) -> Satisfaction<Placeholder<DefiniteDescriptorKey>>
pub fn plan_satisfaction_mall<P>(&self, provider: &P) -> Satisfaction<Placeholder<Pk>>
where
P: AssetProvider<DefiniteDescriptorKey>,
P: AssetProvider<Pk>,
{
best_tap_spend(self, provider, true /* allow_mall */)
}
Expand Down
4 changes: 2 additions & 2 deletions src/miniscript/satisfy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ mod tests {
let descriptor =
Descriptor::<crate::DefiniteDescriptorKey>::from_str(&descriptor_str).unwrap();
// Compute plan and confirm the timelock is correct.
let plan = descriptor.plan(&satisfier).unwrap();
let plan = descriptor.into_plan(&satisfier).unwrap();
assert_eq!(plan.absolute_timelock, Some(absolute::LockTime::from_height(144).unwrap()),);

// Same descriptor as above, except that now we use a time-based timelock rather than a
Expand All @@ -642,7 +642,7 @@ mod tests {
let descriptor =
Descriptor::<crate::DefiniteDescriptorKey>::from_str(&descriptor_str).unwrap();

let plan = descriptor.plan(&satisfier).unwrap();
let plan = descriptor.into_plan(&satisfier).unwrap();
assert_eq!(
plan.absolute_timelock,
Some(absolute::LockTime::from_time(1000000000).unwrap()),
Expand Down
Loading
Loading