@@ -63,6 +63,26 @@ impl<Pk: MiniscriptKey> Bare<Pk> {
63
63
}
64
64
}
65
65
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
+
66
86
impl < Pk : MiniscriptKey > fmt:: Debug for Bare < Pk > {
67
87
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
68
88
write ! ( f, "{:?}" , self . ms)
@@ -126,11 +146,11 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Bare<Pk> {
126
146
Err ( Error :: BareDescriptorAddr )
127
147
}
128
148
129
- fn script_pubkey ( & self ) -> Script
149
+ fn script_pubkey ( & self ) -> Result < Script , Error >
130
150
where
131
151
Pk : ToPublicKey ,
132
152
{
133
- self . ms . encode ( )
153
+ Ok ( self . spk ( ) )
134
154
}
135
155
136
156
fn unsigned_script_sig ( & self ) -> Script
@@ -140,11 +160,11 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Bare<Pk> {
140
160
Script :: new ( )
141
161
}
142
162
143
- fn explicit_script ( & self ) -> Script
163
+ fn explicit_script ( & self ) -> Result < Script , Error >
144
164
where
145
165
Pk : ToPublicKey ,
146
166
{
147
- self . ms . encode ( )
167
+ Ok ( self . inner_script ( ) )
148
168
}
149
169
150
170
fn get_satisfaction < S > ( & self , satisfier : S ) -> Result < ( Vec < Vec < u8 > > , Script ) , Error >
@@ -163,11 +183,11 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Bare<Pk> {
163
183
Ok ( 4 * ( varint_len ( scriptsig_len) + scriptsig_len) )
164
184
}
165
185
166
- fn script_code ( & self ) -> Script
186
+ fn script_code ( & self ) -> Result < Script , Error >
167
187
where
168
188
Pk : ToPublicKey ,
169
189
{
170
- self . script_pubkey ( )
190
+ Ok ( self . ec_sighash_script_code ( ) )
171
191
}
172
192
}
173
193
@@ -227,6 +247,33 @@ impl<Pk: MiniscriptKey> Pkh<Pk> {
227
247
}
228
248
}
229
249
250
+ impl < Pk : MiniscriptKey + ToPublicKey > Pkh < Pk > {
251
+ /// Obtain the corresponding script pubkey for this descriptor
252
+ /// Non failing verion of [`DescriptorTrait::script_pubkey`] for this descriptor
253
+ pub fn spk ( & self ) -> Script {
254
+ let addr = bitcoin:: Address :: p2pkh ( & self . pk . to_public_key ( ) , bitcoin:: Network :: Bitcoin ) ;
255
+ addr. script_pubkey ( )
256
+ }
257
+
258
+ /// Obtain the corresponding script pubkey for this descriptor
259
+ /// Non failing verion of [`DescriptorTrait::address`] for this descriptor
260
+ pub fn addr ( & self , network : bitcoin:: Network ) -> bitcoin:: Address {
261
+ bitcoin:: Address :: p2pkh ( & self . pk . to_public_key ( ) , network)
262
+ }
263
+
264
+ /// Obtain the underlying miniscript for this descriptor
265
+ /// Non failing verion of [`DescriptorTrait::explicit_script`] for this descriptor
266
+ pub fn inner_script ( & self ) -> Script {
267
+ self . spk ( )
268
+ }
269
+
270
+ /// Obtain the pre bip-340 signature script code for this descriptor
271
+ /// Non failing verion of [`DescriptorTrait::script_code`] for this descriptor
272
+ pub fn ec_sighash_script_code ( & self ) -> Script {
273
+ self . spk ( )
274
+ }
275
+ }
276
+
230
277
impl < Pk : MiniscriptKey > fmt:: Debug for Pkh < Pk > {
231
278
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
232
279
write ! ( f, "pkh({:?})" , self . pk)
@@ -294,15 +341,14 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Pkh<Pk> {
294
341
where
295
342
Pk : ToPublicKey ,
296
343
{
297
- Ok ( bitcoin :: Address :: p2pkh ( & self . pk . to_public_key ( ) , network) )
344
+ Ok ( self . addr ( network) )
298
345
}
299
346
300
- fn script_pubkey ( & self ) -> Script
347
+ fn script_pubkey ( & self ) -> Result < Script , Error >
301
348
where
302
349
Pk : ToPublicKey ,
303
350
{
304
- let addr = bitcoin:: Address :: p2pkh ( & self . pk . to_public_key ( ) , bitcoin:: Network :: Bitcoin ) ;
305
- addr. script_pubkey ( )
351
+ Ok ( self . spk ( ) )
306
352
}
307
353
308
354
fn unsigned_script_sig ( & self ) -> Script
@@ -312,11 +358,11 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Pkh<Pk> {
312
358
Script :: new ( )
313
359
}
314
360
315
- fn explicit_script ( & self ) -> Script
361
+ fn explicit_script ( & self ) -> Result < Script , Error >
316
362
where
317
363
Pk : ToPublicKey ,
318
364
{
319
- self . script_pubkey ( )
365
+ Ok ( self . inner_script ( ) )
320
366
}
321
367
322
368
fn get_satisfaction < S > ( & self , satisfier : S ) -> Result < ( Vec < Vec < u8 > > , Script ) , Error >
@@ -340,11 +386,11 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Pkh<Pk> {
340
386
Ok ( 4 * ( 1 + 73 + BareCtx :: pk_len ( & self . pk ) ) )
341
387
}
342
388
343
- fn script_code ( & self ) -> Script
389
+ fn script_code ( & self ) -> Result < Script , Error >
344
390
where
345
391
Pk : ToPublicKey ,
346
392
{
347
- self . script_pubkey ( )
393
+ Ok ( self . ec_sighash_script_code ( ) )
348
394
}
349
395
}
350
396
0 commit comments