Skip to content

Commit 8bd09d2

Browse files
committed
Remove explicit_script() from DescriptorTrait
Now that `Descriptor` no longer implements `DesciptorTrait` we can remove the `explicit_script` method from the trait entirely, instead just implementing a method of the same name on `Descriptor` that calls through to the required underlying method.
1 parent df70352 commit 8bd09d2

File tree

5 files changed

+13
-67
lines changed

5 files changed

+13
-67
lines changed

src/descriptor/bare.rs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Bare<Pk> {
7575
self.ms.encode()
7676
}
7777

78-
/// Obtain the underlying miniscript for this descriptor
79-
/// Non failing verion of [`DescriptorTrait::explicit_script`] for this descriptor
78+
/// Obtains the underlying miniscript for this descriptor.
8079
pub fn inner_script(&self) -> Script {
8180
self.script_pubkey()
8281
}
@@ -146,13 +145,6 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Bare<Pk> {
146145
Script::new()
147146
}
148147

149-
fn explicit_script(&self) -> Result<Script, Error>
150-
where
151-
Pk: ToPublicKey,
152-
{
153-
Ok(self.inner_script())
154-
}
155-
156148
fn get_satisfaction<S>(&self, satisfier: S) -> Result<(Vec<Vec<u8>>, Script), Error>
157149
where
158150
Pk: ToPublicKey,
@@ -256,8 +248,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Pkh<Pk> {
256248
Address::p2pkh(&self.pk.to_public_key(), network)
257249
}
258250

259-
/// Obtain the underlying miniscript for this descriptor
260-
/// Non failing verion of [`DescriptorTrait::explicit_script`] for this descriptor
251+
/// Obtains the underlying miniscript for this descriptor.
261252
pub fn inner_script(&self) -> Script {
262253
self.script_pubkey()
263254
}
@@ -335,13 +326,6 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Pkh<Pk> {
335326
Script::new()
336327
}
337328

338-
fn explicit_script(&self) -> Result<Script, Error>
339-
where
340-
Pk: ToPublicKey,
341-
{
342-
Ok(self.inner_script())
343-
}
344-
345329
fn get_satisfaction<S>(&self, satisfier: S) -> Result<(Vec<Vec<u8>>, Script), Error>
346330
where
347331
Pk: ToPublicKey,

src/descriptor/mod.rs

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,6 @@ pub trait DescriptorTrait<Pk: MiniscriptKey> {
9191
where
9292
Pk: ToPublicKey;
9393

94-
/// Computes the "witness script" of the descriptor, i.e. the underlying
95-
/// script before any hashing is done. For `Bare`, `Pkh` and `Wpkh` this
96-
/// is the scriptPubkey; for `ShWpkh` and `Sh` this is the redeemScript;
97-
/// for the others it is the witness script.
98-
/// For `Tr` descriptors, this will error as there is no underlying script
99-
fn explicit_script(&self) -> Result<Script, Error>
100-
where
101-
Pk: ToPublicKey;
102-
10394
/// Returns satisfying non-malleable witness and scriptSig with minimum weight to spend an
10495
/// output controlled by the given descriptor if it possible to
10596
/// construct one using the satisfier S.
@@ -492,16 +483,17 @@ impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {
492483
/// script before any hashing is done. For `Bare`, `Pkh` and `Wpkh` this
493484
/// is the scriptPubkey; for `ShWpkh` and `Sh` this is the redeemScript;
494485
/// for the others it is the witness script.
495-
/// Errors:
496-
/// - When the descriptor is Tr
486+
///
487+
/// # Errors
488+
/// If the descriptor is a taproot descriptor.
497489
pub fn explicit_script(&self) -> Result<Script, Error> {
498490
match *self {
499-
Descriptor::Bare(ref bare) => bare.explicit_script(),
500-
Descriptor::Pkh(ref pkh) => pkh.explicit_script(),
501-
Descriptor::Wpkh(ref wpkh) => wpkh.explicit_script(),
502-
Descriptor::Wsh(ref wsh) => wsh.explicit_script(),
503-
Descriptor::Sh(ref sh) => sh.explicit_script(),
504-
Descriptor::Tr(ref tr) => tr.explicit_script(),
491+
Descriptor::Bare(ref bare) => Ok(bare.script_pubkey()),
492+
Descriptor::Pkh(ref pkh) => Ok(pkh.script_pubkey()),
493+
Descriptor::Wpkh(ref wpkh) => Ok(wpkh.script_pubkey()),
494+
Descriptor::Wsh(ref wsh) => Ok(wsh.inner_script()),
495+
Descriptor::Sh(ref sh) => Ok(sh.inner_script()),
496+
Descriptor::Tr(_) => Err(Error::TrNoScriptCode),
505497
}
506498
}
507499

src/descriptor/segwitv0.rs

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Wsh<Pk> {
101101
}
102102
}
103103

104-
/// Obtain the underlying miniscript for this descriptor
105-
/// Non failing verion of [`DescriptorTrait::explicit_script`] for this descriptor
104+
/// Obtains the underlying miniscript for this descriptor.
106105
pub fn inner_script(&self) -> Script {
107106
match self.inner {
108107
WshInner::SortedMulti(ref smv) => smv.encode(),
@@ -205,13 +204,6 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Wsh<Pk> {
205204
Script::new()
206205
}
207206

208-
fn explicit_script(&self) -> Result<Script, Error>
209-
where
210-
Pk: ToPublicKey,
211-
{
212-
Ok(self.inner_script())
213-
}
214-
215207
fn get_satisfaction<S>(&self, satisfier: S) -> Result<(Vec<Vec<u8>>, Script), Error>
216208
where
217209
Pk: ToPublicKey,
@@ -368,8 +360,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Wpkh<Pk> {
368360
.expect("Rust Miniscript types don't allow uncompressed pks in segwit descriptors")
369361
}
370362

371-
/// Obtain the underlying miniscript for this descriptor
372-
/// Non failing verion of [`DescriptorTrait::explicit_script`] for this descriptor
363+
/// Obtains the underlying miniscript for this descriptor.
373364
pub fn inner_script(&self) -> Script {
374365
self.script_pubkey()
375366
}
@@ -452,13 +443,6 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Wpkh<Pk> {
452443
Script::new()
453444
}
454445

455-
fn explicit_script(&self) -> Result<Script, Error>
456-
where
457-
Pk: ToPublicKey,
458-
{
459-
Ok(self.inner_script())
460-
}
461-
462446
fn get_satisfaction<S>(&self, satisfier: S) -> Result<(Vec<Vec<u8>>, Script), Error>
463447
where
464448
Pk: ToPublicKey,

src/descriptor/sh.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,6 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Sh<Pk> {
296296
}
297297
}
298298

299-
fn explicit_script(&self) -> Result<Script, Error>
300-
where
301-
Pk: ToPublicKey,
302-
{
303-
Ok(self.inner_script())
304-
}
305-
306299
fn get_satisfaction<S>(&self, satisfier: S) -> Result<(Vec<Vec<u8>>, Script), Error>
307300
where
308301
Pk: ToPublicKey,

src/descriptor/tr.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -566,13 +566,6 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Tr<Pk> {
566566
Script::new()
567567
}
568568

569-
fn explicit_script(&self) -> Result<Script, Error>
570-
where
571-
Pk: ToPublicKey,
572-
{
573-
Err(Error::TrNoScriptCode)
574-
}
575-
576569
fn get_satisfaction<S>(&self, satisfier: S) -> Result<(Vec<Vec<u8>>, Script), Error>
577570
where
578571
Pk: ToPublicKey,

0 commit comments

Comments
 (0)