@@ -76,16 +76,6 @@ pub type KeyMap = HashMap<DescriptorPublicKey, DescriptorSecretKey>;
7676// because of traits cannot know underlying generic of Self.
7777// Thus, we must implement additional trait for translate function
7878pub trait DescriptorTrait < Pk : MiniscriptKey > {
79- /// Whether the descriptor is safe
80- /// Checks whether all the spend paths in the descriptor are possible
81- /// on the bitcoin network under the current standardness and consensus rules
82- /// Also checks whether the descriptor requires signauture on all spend paths
83- /// And whether the script is malleable.
84- /// In general, all the guarantees of miniscript hold only for safe scripts.
85- /// All the analysis guarantees of miniscript only hold safe scripts.
86- /// The signer may not be able to find satisfactions even if one exists
87- fn sanity_check ( & self ) -> Result < ( ) , Error > ;
88-
8979 /// Computes the Bitcoin address of the descriptor, if one exists
9080 /// Some descriptors like pk() don't have any address.
9181 /// Errors:
@@ -395,6 +385,26 @@ impl<Pk: MiniscriptKey> Descriptor<Pk> {
395385 Descriptor :: Tr ( ref _tr) => DescriptorType :: Tr ,
396386 }
397387 }
388+
389+ /// Checks whether the descriptor is safe.
390+ ///
391+ /// Checks whether all the spend paths in the descriptor are possible on the
392+ /// bitcoin network under the current standardness and consensus rules. Also
393+ /// checks whether the descriptor requires signatures on all spend paths and
394+ /// whether the script is malleable.
395+ ///
396+ /// In general, all the guarantees of miniscript hold only for safe scripts.
397+ /// The signer may not be able to find satisfactions even if one exists.
398+ pub fn sanity_check ( & self ) -> Result < ( ) , Error > {
399+ match * self {
400+ Descriptor :: Bare ( ref bare) => bare. sanity_check ( ) ,
401+ Descriptor :: Pkh ( _) => Ok ( ( ) ) ,
402+ Descriptor :: Wpkh ( ref wpkh) => wpkh. sanity_check ( ) ,
403+ Descriptor :: Wsh ( ref wsh) => wsh. sanity_check ( ) ,
404+ Descriptor :: Sh ( ref sh) => sh. sanity_check ( ) ,
405+ Descriptor :: Tr ( ref tr) => tr. sanity_check ( ) ,
406+ }
407+ }
398408}
399409
400410impl < P , Q > TranslatePk < P , Q > for Descriptor < P >
@@ -428,24 +438,6 @@ where
428438}
429439
430440impl < Pk : MiniscriptKey > DescriptorTrait < Pk > for Descriptor < Pk > {
431- /// Whether the descriptor is safe
432- /// Checks whether all the spend paths in the descriptor are possible
433- /// on the bitcoin network under the current standardness and consensus rules
434- /// Also checks whether the descriptor requires signauture on all spend paths
435- /// And whether the script is malleable.
436- /// In general, all the guarantees of miniscript hold only for safe scripts.
437- /// All the analysis guarantees of miniscript only hold safe scripts.
438- /// The signer may not be able to find satisfactions even if one exists
439- fn sanity_check ( & self ) -> Result < ( ) , Error > {
440- match * self {
441- Descriptor :: Bare ( ref bare) => bare. sanity_check ( ) ,
442- Descriptor :: Pkh ( ref pkh) => pkh. sanity_check ( ) ,
443- Descriptor :: Wpkh ( ref wpkh) => wpkh. sanity_check ( ) ,
444- Descriptor :: Wsh ( ref wsh) => wsh. sanity_check ( ) ,
445- Descriptor :: Sh ( ref sh) => sh. sanity_check ( ) ,
446- Descriptor :: Tr ( ref tr) => tr. sanity_check ( ) ,
447- }
448- }
449441 /// Computes the Bitcoin address of the descriptor, if one exists
450442 fn address ( & self , network : Network ) -> Result < Address , Error >
451443 where
0 commit comments