@@ -63,6 +63,26 @@ impl<Pk: MiniscriptKey> Bare<Pk> {
6363 }
6464}
6565
66+ impl < Pk : MiniscriptKey + ToPublicKey > Bare < Pk > {
67+ /// Obtain the corresponding script pubkey for this descriptor
68+ /// Non failing verion of [`DescriptorTrait::script_pubkey`] for this descriptor
69+ pub fn spk ( & self ) -> Script {
70+ self . ms . encode ( )
71+ }
72+
73+ /// Obtain the underlying miniscript for this descriptor
74+ /// Non failing verion of [`DescriptorTrait::explicit_script`] for this descriptor
75+ pub fn inner_script ( & self ) -> Script {
76+ self . spk ( )
77+ }
78+
79+ /// Obtain the pre bip-340 signature script code for this descriptor
80+ /// Non failing verion of [`DescriptorTrait::script_code`] for this descriptor
81+ pub fn ec_sighash_script_code ( & self ) -> Script {
82+ self . spk ( )
83+ }
84+ }
85+
6686impl < Pk : MiniscriptKey > fmt:: Debug for Bare < Pk > {
6787 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
6888 write ! ( f, "{:?}" , self . ms)
@@ -126,11 +146,11 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Bare<Pk> {
126146 Err ( Error :: BareDescriptorAddr )
127147 }
128148
129- fn script_pubkey ( & self ) -> Script
149+ fn script_pubkey ( & self ) -> Result < Script , Error >
130150 where
131151 Pk : ToPublicKey ,
132152 {
133- self . ms . encode ( )
153+ Ok ( self . spk ( ) )
134154 }
135155
136156 fn unsigned_script_sig ( & self ) -> Script
@@ -140,11 +160,11 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Bare<Pk> {
140160 Script :: new ( )
141161 }
142162
143- fn explicit_script ( & self ) -> Script
163+ fn explicit_script ( & self ) -> Result < Script , Error >
144164 where
145165 Pk : ToPublicKey ,
146166 {
147- self . ms . encode ( )
167+ Ok ( self . inner_script ( ) )
148168 }
149169
150170 fn get_satisfaction < S > ( & self , satisfier : S ) -> Result < ( Vec < Vec < u8 > > , Script ) , Error >
@@ -174,11 +194,11 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Bare<Pk> {
174194 Ok ( 4 * ( varint_len ( scriptsig_len) + scriptsig_len) )
175195 }
176196
177- fn script_code ( & self ) -> Script
197+ fn script_code ( & self ) -> Result < Script , Error >
178198 where
179199 Pk : ToPublicKey ,
180200 {
181- self . script_pubkey ( )
201+ Ok ( self . ec_sighash_script_code ( ) )
182202 }
183203}
184204
@@ -238,6 +258,33 @@ impl<Pk: MiniscriptKey> Pkh<Pk> {
238258 }
239259}
240260
261+ impl < Pk : MiniscriptKey + ToPublicKey > Pkh < Pk > {
262+ /// Obtain the corresponding script pubkey for this descriptor
263+ /// Non failing verion of [`DescriptorTrait::script_pubkey`] for this descriptor
264+ pub fn spk ( & self ) -> Script {
265+ let addr = bitcoin:: Address :: p2pkh ( & self . pk . to_public_key ( ) , bitcoin:: Network :: Bitcoin ) ;
266+ addr. script_pubkey ( )
267+ }
268+
269+ /// Obtain the corresponding script pubkey for this descriptor
270+ /// Non failing verion of [`DescriptorTrait::address`] for this descriptor
271+ pub fn addr ( & self , network : bitcoin:: Network ) -> bitcoin:: Address {
272+ bitcoin:: Address :: p2pkh ( & self . pk . to_public_key ( ) , network)
273+ }
274+
275+ /// Obtain the underlying miniscript for this descriptor
276+ /// Non failing verion of [`DescriptorTrait::explicit_script`] for this descriptor
277+ pub fn inner_script ( & self ) -> Script {
278+ self . spk ( )
279+ }
280+
281+ /// Obtain the pre bip-340 signature script code for this descriptor
282+ /// Non failing verion of [`DescriptorTrait::script_code`] for this descriptor
283+ pub fn ec_sighash_script_code ( & self ) -> Script {
284+ self . spk ( )
285+ }
286+ }
287+
241288impl < Pk : MiniscriptKey > fmt:: Debug for Pkh < Pk > {
242289 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
243290 write ! ( f, "pkh({:?})" , self . pk)
@@ -305,15 +352,14 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Pkh<Pk> {
305352 where
306353 Pk : ToPublicKey ,
307354 {
308- Ok ( bitcoin :: Address :: p2pkh ( & self . pk . to_public_key ( ) , network) )
355+ Ok ( self . addr ( network) )
309356 }
310357
311- fn script_pubkey ( & self ) -> Script
358+ fn script_pubkey ( & self ) -> Result < Script , Error >
312359 where
313360 Pk : ToPublicKey ,
314361 {
315- let addr = bitcoin:: Address :: p2pkh ( & self . pk . to_public_key ( ) , bitcoin:: Network :: Bitcoin ) ;
316- addr. script_pubkey ( )
362+ Ok ( self . spk ( ) )
317363 }
318364
319365 fn unsigned_script_sig ( & self ) -> Script
@@ -323,11 +369,11 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Pkh<Pk> {
323369 Script :: new ( )
324370 }
325371
326- fn explicit_script ( & self ) -> Script
372+ fn explicit_script ( & self ) -> Result < Script , Error >
327373 where
328374 Pk : ToPublicKey ,
329375 {
330- self . script_pubkey ( )
376+ Ok ( self . inner_script ( ) )
331377 }
332378
333379 fn get_satisfaction < S > ( & self , satisfier : S ) -> Result < ( Vec < Vec < u8 > > , Script ) , Error >
@@ -360,11 +406,11 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Pkh<Pk> {
360406 Ok ( 4 * ( 1 + 73 + BareCtx :: pk_len ( & self . pk ) ) )
361407 }
362408
363- fn script_code ( & self ) -> Script
409+ fn script_code ( & self ) -> Result < Script , Error >
364410 where
365411 Pk : ToPublicKey ,
366412 {
367- self . script_pubkey ( )
413+ Ok ( self . ec_sighash_script_code ( ) )
368414 }
369415}
370416
0 commit comments