@@ -113,16 +113,6 @@ pub trait DescriptorTrait<Pk: MiniscriptKey> {
113113 /// scriptSig and witness stack length.
114114 /// Returns Error when the descriptor is impossible to safisfy (ex: sh(OP_FALSE))
115115 fn max_satisfaction_weight ( & self ) -> Result < usize , Error > ;
116-
117- /// Get the `scriptCode` of a transaction output.
118- ///
119- /// The `scriptCode` is the Script of the previous transaction output being serialized in the
120- /// sighash when evaluating a `CHECKSIG` & co. OP code.
121- /// Errors:
122- /// - When the descriptor is Tr
123- fn script_code ( & self ) -> Result < Script , Error >
124- where
125- Pk : ToPublicKey ;
126116}
127117
128118/// Script descriptor
@@ -437,6 +427,24 @@ impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {
437427 Descriptor :: Tr ( _) => Err ( Error :: TrNoScriptCode ) ,
438428 }
439429 }
430+
431+ /// Computes the `scriptCode` of a transaction output.
432+ ///
433+ /// The `scriptCode` is the Script of the previous transaction output being
434+ /// serialized in the sighash when evaluating a `CHECKSIG` & co. OP code.
435+ ///
436+ /// # Errors
437+ /// If the descriptor is a taproot descriptor.
438+ pub fn script_code ( & self ) -> Result < Script , Error > {
439+ match * self {
440+ Descriptor :: Bare ( ref bare) => Ok ( bare. ecdsa_sighash_script_code ( ) ) ,
441+ Descriptor :: Pkh ( ref pkh) => Ok ( pkh. ecdsa_sighash_script_code ( ) ) ,
442+ Descriptor :: Wpkh ( ref wpkh) => Ok ( wpkh. ecdsa_sighash_script_code ( ) ) ,
443+ Descriptor :: Wsh ( ref wsh) => Ok ( wsh. ecdsa_sighash_script_code ( ) ) ,
444+ Descriptor :: Sh ( ref sh) => Ok ( sh. ecdsa_sighash_script_code ( ) ) ,
445+ Descriptor :: Tr ( _) => Err ( Error :: TrNoScriptCode ) ,
446+ }
447+ }
440448}
441449
442450impl < P , Q > TranslatePk < P , Q > for Descriptor < P >
@@ -520,25 +528,6 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
520528 Descriptor :: Tr ( ref tr) => tr. max_satisfaction_weight ( ) ,
521529 }
522530 }
523-
524- /// Get the `scriptCode` of a transaction output.
525- ///
526- /// The `scriptCode` is the Script of the previous transaction output being serialized in the
527- /// sighash when evaluating a `CHECKSIG` & co. OP code.
528- /// Returns Error for Tr descriptors
529- fn script_code ( & self ) -> Result < Script , Error >
530- where
531- Pk : ToPublicKey ,
532- {
533- match * self {
534- Descriptor :: Bare ( ref bare) => bare. script_code ( ) ,
535- Descriptor :: Pkh ( ref pkh) => pkh. script_code ( ) ,
536- Descriptor :: Wpkh ( ref wpkh) => wpkh. script_code ( ) ,
537- Descriptor :: Wsh ( ref wsh) => wsh. script_code ( ) ,
538- Descriptor :: Sh ( ref sh) => sh. script_code ( ) ,
539- Descriptor :: Tr ( ref tr) => tr. script_code ( ) ,
540- }
541- }
542531}
543532
544533impl < Pk : MiniscriptKey > ForEachKey < Pk > for Descriptor < Pk > {
0 commit comments