Skip to content

Commit 0f3a639

Browse files
committed
Expose descriptor function
1 parent d60e820 commit 0f3a639

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/descriptor/mod.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,27 @@ impl<Pk: MiniscriptKey> Descriptor<Pk> {
384384
)),
385385
}
386386
}
387+
388+
/// Whether the descriptor is safe
389+
/// Checks whether all the spend paths in the descriptor are possible
390+
/// on the bitcoin network under the current standardness and consensus rules
391+
/// Also checks whether the descriptor requires signauture on all spend paths
392+
/// And whether the script is malleable.
393+
/// In general, all the guarantees of miniscript hold only for safe scripts.
394+
/// All the analysis gurantees of miniscript only hold safe scripts.
395+
/// The signer may not be able to find satisfactions even if one exists
396+
pub fn check_safety(&self) -> Result<(), Error> {
397+
match *self {
398+
Descriptor::Bare(ref ms) => ms.check_safety()?,
399+
Descriptor::Pk(ref _pk)
400+
| Descriptor::Pkh(ref _pk)
401+
| Descriptor::Wpkh(ref _pk)
402+
| Descriptor::ShWpkh(ref _pk) => {}
403+
Descriptor::Wsh(ref ms) | Descriptor::ShWsh(ref ms) => ms.check_safety()?,
404+
Descriptor::Sh(ref ms) => ms.check_safety()?,
405+
}
406+
Ok(())
407+
}
387408
}
388409

389410
impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {

0 commit comments

Comments
 (0)