@@ -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 ecdsa_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)
@@ -130,7 +150,7 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Bare<Pk> {
130
150
where
131
151
Pk : ToPublicKey ,
132
152
{
133
- self . ms . encode ( )
153
+ 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 >
@@ -174,11 +194,11 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Bare<Pk> {
174
194
Ok ( 4 * ( varint_len ( scriptsig_len) + scriptsig_len) )
175
195
}
176
196
177
- fn script_code ( & self ) -> Script
197
+ fn script_code ( & self ) -> Result < Script , Error >
178
198
where
179
199
Pk : ToPublicKey ,
180
200
{
181
- self . script_pubkey ( )
201
+ Ok ( self . ecdsa_sighash_script_code ( ) )
182
202
}
183
203
}
184
204
@@ -238,6 +258,33 @@ impl<Pk: MiniscriptKey> Pkh<Pk> {
238
258
}
239
259
}
240
260
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 ecdsa_sighash_script_code ( & self ) -> Script {
284
+ self . spk ( )
285
+ }
286
+ }
287
+
241
288
impl < Pk : MiniscriptKey > fmt:: Debug for Pkh < Pk > {
242
289
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
243
290
write ! ( f, "pkh({:?})" , self . pk)
@@ -305,15 +352,14 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Pkh<Pk> {
305
352
where
306
353
Pk : ToPublicKey ,
307
354
{
308
- Ok ( bitcoin :: Address :: p2pkh ( & self . pk . to_public_key ( ) , network) )
355
+ Ok ( self . addr ( network) )
309
356
}
310
357
311
358
fn script_pubkey ( & self ) -> Script
312
359
where
313
360
Pk : ToPublicKey ,
314
361
{
315
- let addr = bitcoin:: Address :: p2pkh ( & self . pk . to_public_key ( ) , bitcoin:: Network :: Bitcoin ) ;
316
- addr. script_pubkey ( )
362
+ self . spk ( )
317
363
}
318
364
319
365
fn unsigned_script_sig ( & self ) -> Script
@@ -323,11 +369,11 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Pkh<Pk> {
323
369
Script :: new ( )
324
370
}
325
371
326
- fn explicit_script ( & self ) -> Script
372
+ fn explicit_script ( & self ) -> Result < Script , Error >
327
373
where
328
374
Pk : ToPublicKey ,
329
375
{
330
- self . script_pubkey ( )
376
+ Ok ( self . inner_script ( ) )
331
377
}
332
378
333
379
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> {
360
406
Ok ( 4 * ( 1 + 73 + BareCtx :: pk_len ( & self . pk ) ) )
361
407
}
362
408
363
- fn script_code ( & self ) -> Script
409
+ fn script_code ( & self ) -> Result < Script , Error >
364
410
where
365
411
Pk : ToPublicKey ,
366
412
{
367
- self . script_pubkey ( )
413
+ Ok ( self . ecdsa_sighash_script_code ( ) )
368
414
}
369
415
}
370
416
0 commit comments