@@ -76,15 +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- /// Computes the "witness script" of the descriptor, i.e. the underlying
80- /// script before any hashing is done. For `Bare`, `Pkh` and `Wpkh` this
81- /// is the scriptPubkey; for `ShWpkh` and `Sh` this is the redeemScript;
82- /// for the others it is the witness script.
83- /// For `Tr` descriptors, this will error as there is no underlying script
84- fn explicit_script ( & self ) -> Result < Script , Error >
85- where
86- Pk : ToPublicKey ;
87-
8879 /// Returns satisfying non-malleable witness and scriptSig with minimum weight to spend an
8980 /// output controlled by the given descriptor if it possible to
9081 /// construct one using the satisfier S.
@@ -429,6 +420,23 @@ impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {
429420 Descriptor :: Tr ( _) => Script :: new ( ) ,
430421 }
431422 }
423+
424+ /// Computes the the underlying script before any hashing is done. For
425+ /// `Bare`, `Pkh` and `Wpkh` this is the scriptPubkey; for `ShWpkh` and `Sh`
426+ /// this is the redeemScript; for the others it is the witness script.
427+ ///
428+ /// # Errors
429+ /// If the descriptor is a taproot descriptor.
430+ pub fn explicit_script ( & self ) -> Result < Script , Error > {
431+ match * self {
432+ Descriptor :: Bare ( ref bare) => Ok ( bare. script_pubkey ( ) ) ,
433+ Descriptor :: Pkh ( ref pkh) => Ok ( pkh. script_pubkey ( ) ) ,
434+ Descriptor :: Wpkh ( ref wpkh) => Ok ( wpkh. script_pubkey ( ) ) ,
435+ Descriptor :: Wsh ( ref wsh) => Ok ( wsh. inner_script ( ) ) ,
436+ Descriptor :: Sh ( ref sh) => Ok ( sh. inner_script ( ) ) ,
437+ Descriptor :: Tr ( _) => Err ( Error :: TrNoScriptCode ) ,
438+ }
439+ }
432440}
433441
434442impl < P , Q > TranslatePk < P , Q > for Descriptor < P >
@@ -462,26 +470,6 @@ where
462470}
463471
464472impl < Pk : MiniscriptKey > DescriptorTrait < Pk > for Descriptor < Pk > {
465- /// Computes the "witness script" of the descriptor, i.e. the underlying
466- /// script before any hashing is done. For `Bare`, `Pkh` and `Wpkh` this
467- /// is the scriptPubkey; for `ShWpkh` and `Sh` this is the redeemScript;
468- /// for the others it is the witness script.
469- /// Errors:
470- /// - When the descriptor is Tr
471- fn explicit_script ( & self ) -> Result < Script , Error >
472- where
473- Pk : ToPublicKey ,
474- {
475- match * self {
476- Descriptor :: Bare ( ref bare) => bare. explicit_script ( ) ,
477- Descriptor :: Pkh ( ref pkh) => pkh. explicit_script ( ) ,
478- Descriptor :: Wpkh ( ref wpkh) => wpkh. explicit_script ( ) ,
479- Descriptor :: Wsh ( ref wsh) => wsh. explicit_script ( ) ,
480- Descriptor :: Sh ( ref sh) => sh. explicit_script ( ) ,
481- Descriptor :: Tr ( ref tr) => tr. explicit_script ( ) ,
482- }
483- }
484-
485473 /// Returns satisfying non-malleable witness and scriptSig to spend an
486474 /// output controlled by the given descriptor if it possible to
487475 /// construct one using the satisfier S.
0 commit comments