Skip to content

Commit c6884fc

Browse files
committed
Remove explicit_script from DescriptorTrait
In preparation for removing the `DescriptorTrait` remove the `explicit_script` trait method. Implement the same logic on `Descriptor` directly but call through to `inner_script` or `script_pubkey` for each descriptor as required.
1 parent 67d7c0e commit c6884fc

File tree

7 files changed

+18
-78
lines changed

7 files changed

+18
-78
lines changed

examples/parse.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use std::str::FromStr;
1818

1919
use miniscript::descriptor::DescriptorType;
20-
use miniscript::{Descriptor, DescriptorTrait};
20+
use miniscript::Descriptor;
2121

2222
fn main() {
2323
let desc = miniscript::Descriptor::<bitcoin::PublicKey>::from_str(

src/descriptor/bare.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ impl<Pk: MiniscriptKey + ToPublicKey> Bare<Pk> {
7575
}
7676

7777
/// Obtain the underlying miniscript for this descriptor
78-
/// Non failing verion of [`DescriptorTrait::explicit_script`] for this descriptor
7978
pub fn inner_script(&self) -> Script {
8079
self.script_pubkey()
8180
}
@@ -138,13 +137,6 @@ where
138137
}
139138

140139
impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Bare<Pk> {
141-
fn explicit_script(&self) -> Result<Script, Error>
142-
where
143-
Pk: ToPublicKey,
144-
{
145-
Ok(self.inner_script())
146-
}
147-
148140
fn get_satisfaction<S>(&self, satisfier: S) -> Result<(Vec<Vec<u8>>, Script), Error>
149141
where
150142
Pk: ToPublicKey,
@@ -248,7 +240,6 @@ impl<Pk: MiniscriptKey + ToPublicKey> Pkh<Pk> {
248240
}
249241

250242
/// Obtain the underlying miniscript for this descriptor
251-
/// Non failing verion of [`DescriptorTrait::explicit_script`] for this descriptor
252243
pub fn inner_script(&self) -> Script {
253244
self.script_pubkey()
254245
}
@@ -319,13 +310,6 @@ where
319310
}
320311

321312
impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Pkh<Pk> {
322-
fn explicit_script(&self) -> Result<Script, Error>
323-
where
324-
Pk: ToPublicKey,
325-
{
326-
Ok(self.inner_script())
327-
}
328-
329313
fn get_satisfaction<S>(&self, satisfier: S) -> Result<(Vec<Vec<u8>>, Script), Error>
330314
where
331315
Pk: ToPublicKey,

src/descriptor/mod.rs

Lines changed: 17 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,6 @@ pub type KeyMap = HashMap<DescriptorPublicKey, DescriptorSecretKey>;
7676
// because of traits cannot know underlying generic of Self.
7777
// Thus, we must implement additional trait for translate function
7878
pub trait DescriptorTrait<Pk: MiniscriptKey> {
79-
/// Computes the "witness script" of the descriptor, i.e. the underlying
80-
/// script before any hashing is done. For `Bare`, `Pkh` and `Wpkh` this
81-
/// is the scriptPubkey; for `ShWpkh` and `Sh` this is the redeemScript;
82-
/// for the others it is the witness script.
83-
/// For `Tr` descriptors, this will error as there is no underlying script
84-
fn explicit_script(&self) -> Result<Script, Error>
85-
where
86-
Pk: ToPublicKey;
87-
8879
/// Returns satisfying non-malleable witness and scriptSig with minimum weight to spend an
8980
/// output controlled by the given descriptor if it possible to
9081
/// construct one using the satisfier S.
@@ -429,6 +420,23 @@ impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {
429420
Descriptor::Tr(_) => Script::new(),
430421
}
431422
}
423+
424+
/// Computes the the underlying script before any hashing is done. For
425+
/// `Bare`, `Pkh` and `Wpkh` this is the scriptPubkey; for `ShWpkh` and `Sh`
426+
/// this is the redeemScript; for the others it is the witness script.
427+
///
428+
/// # Errors
429+
/// If the descriptor is a taproot descriptor.
430+
pub fn explicit_script(&self) -> Result<Script, Error> {
431+
match *self {
432+
Descriptor::Bare(ref bare) => Ok(bare.script_pubkey()),
433+
Descriptor::Pkh(ref pkh) => Ok(pkh.script_pubkey()),
434+
Descriptor::Wpkh(ref wpkh) => Ok(wpkh.script_pubkey()),
435+
Descriptor::Wsh(ref wsh) => Ok(wsh.inner_script()),
436+
Descriptor::Sh(ref sh) => Ok(sh.inner_script()),
437+
Descriptor::Tr(_) => Err(Error::TrNoScriptCode),
438+
}
439+
}
432440
}
433441

434442
impl<P, Q> TranslatePk<P, Q> for Descriptor<P>
@@ -462,26 +470,6 @@ where
462470
}
463471

464472
impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
465-
/// Computes the "witness script" of the descriptor, i.e. the underlying
466-
/// script before any hashing is done. For `Bare`, `Pkh` and `Wpkh` this
467-
/// is the scriptPubkey; for `ShWpkh` and `Sh` this is the redeemScript;
468-
/// for the others it is the witness script.
469-
/// Errors:
470-
/// - When the descriptor is Tr
471-
fn explicit_script(&self) -> Result<Script, Error>
472-
where
473-
Pk: ToPublicKey,
474-
{
475-
match *self {
476-
Descriptor::Bare(ref bare) => bare.explicit_script(),
477-
Descriptor::Pkh(ref pkh) => pkh.explicit_script(),
478-
Descriptor::Wpkh(ref wpkh) => wpkh.explicit_script(),
479-
Descriptor::Wsh(ref wsh) => wsh.explicit_script(),
480-
Descriptor::Sh(ref sh) => sh.explicit_script(),
481-
Descriptor::Tr(ref tr) => tr.explicit_script(),
482-
}
483-
}
484-
485473
/// Returns satisfying non-malleable witness and scriptSig to spend an
486474
/// output controlled by the given descriptor if it possible to
487475
/// construct one using the satisfier S.

src/descriptor/segwitv0.rs

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ impl<Pk: MiniscriptKey + ToPublicKey> Wsh<Pk> {
100100
}
101101

102102
/// Obtain the underlying miniscript for this descriptor
103-
/// Non failing verion of [`DescriptorTrait::explicit_script`] for this descriptor
104103
pub fn inner_script(&self) -> Script {
105104
match self.inner {
106105
WshInner::SortedMulti(ref smv) => smv.encode(),
@@ -196,13 +195,6 @@ where
196195
}
197196

198197
impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Wsh<Pk> {
199-
fn explicit_script(&self) -> Result<Script, Error>
200-
where
201-
Pk: ToPublicKey,
202-
{
203-
Ok(self.inner_script())
204-
}
205-
206198
fn get_satisfaction<S>(&self, satisfier: S) -> Result<(Vec<Vec<u8>>, Script), Error>
207199
where
208200
Pk: ToPublicKey,
@@ -355,7 +347,6 @@ impl<Pk: MiniscriptKey + ToPublicKey> Wpkh<Pk> {
355347
}
356348

357349
/// Obtain the underlying miniscript for this descriptor
358-
/// Non failing verion of [`DescriptorTrait::explicit_script`] for this descriptor
359350
pub fn inner_script(&self) -> Script {
360351
self.script_pubkey()
361352
}
@@ -431,13 +422,6 @@ where
431422
}
432423

433424
impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Wpkh<Pk> {
434-
fn explicit_script(&self) -> Result<Script, Error>
435-
where
436-
Pk: ToPublicKey,
437-
{
438-
Ok(self.inner_script())
439-
}
440-
441425
fn get_satisfaction<S>(&self, satisfier: S) -> Result<(Vec<Vec<u8>>, Script), Error>
442426
where
443427
Pk: ToPublicKey,

src/descriptor/sh.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,6 @@ impl<Pk: MiniscriptKey + ToPublicKey> Sh<Pk> {
249249
}
250250

251251
/// Obtain the underlying miniscript for this descriptor
252-
/// Non failing verion of [`DescriptorTrait::explicit_script`] for this descriptor
253252
pub fn inner_script(&self) -> Script {
254253
match self.inner {
255254
ShInner::Wsh(ref wsh) => wsh.inner_script(),
@@ -301,13 +300,6 @@ impl<Pk: MiniscriptKey + ToPublicKey> Sh<Pk> {
301300
}
302301

303302
impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Sh<Pk> {
304-
fn explicit_script(&self) -> Result<Script, Error>
305-
where
306-
Pk: ToPublicKey,
307-
{
308-
Ok(self.inner_script())
309-
}
310-
311303
fn get_satisfaction<S>(&self, satisfier: S) -> Result<(Vec<Vec<u8>>, Script), Error>
312304
where
313305
Pk: ToPublicKey,

src/descriptor/tr.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -554,13 +554,6 @@ impl<Pk: MiniscriptKey> Liftable<Pk> for Tr<Pk> {
554554
}
555555

556556
impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Tr<Pk> {
557-
fn explicit_script(&self) -> Result<Script, Error>
558-
where
559-
Pk: ToPublicKey,
560-
{
561-
Err(Error::TrNoScriptCode)
562-
}
563-
564557
fn get_satisfaction<S>(&self, satisfier: S) -> Result<(Vec<Vec<u8>>, Script), Error>
565558
where
566559
Pk: ToPublicKey,

src/psbt/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1152,7 +1152,6 @@ mod tests {
11521152
use bitcoin::{OutPoint, TxIn, TxOut, XOnlyPublicKey};
11531153

11541154
use super::*;
1155-
use crate::descriptor::DescriptorTrait;
11561155
use crate::Miniscript;
11571156

11581157
#[test]

0 commit comments

Comments
 (0)