Skip to content

Commit f7b27d5

Browse files
committed
Remove unsigned_script_sig from Descriptor trait
The `unsigned_script_sig` method is only meaningfully implemented for Sh descriptors, all the rest of the implementations just return `Script::new()`. We can simplify the code by removing this method from the `DescriptorTrait` altogether and just implementing it on `Descriptor` and the Sh descriptor directly.
1 parent 8bd09d2 commit f7b27d5

File tree

5 files changed

+21
-65
lines changed

5 files changed

+21
-65
lines changed

src/descriptor/bare.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -138,13 +138,6 @@ where
138138
}
139139

140140
impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Bare<Pk> {
141-
fn unsigned_script_sig(&self) -> Script
142-
where
143-
Pk: ToPublicKey,
144-
{
145-
Script::new()
146-
}
147-
148141
fn get_satisfaction<S>(&self, satisfier: S) -> Result<(Vec<Vec<u8>>, Script), Error>
149142
where
150143
Pk: ToPublicKey,
@@ -319,13 +312,6 @@ where
319312
}
320313

321314
impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Pkh<Pk> {
322-
fn unsigned_script_sig(&self) -> Script
323-
where
324-
Pk: ToPublicKey,
325-
{
326-
Script::new()
327-
}
328-
329315
fn get_satisfaction<S>(&self, satisfier: S) -> Result<(Vec<Vec<u8>>, Script), Error>
330316
where
331317
Pk: ToPublicKey,

src/descriptor/mod.rs

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -79,18 +79,6 @@ pub type KeyMap = HashMap<DescriptorPublicKey, DescriptorSecretKey>;
7979
// because of traits cannot know underlying generic of Self.
8080
// Thus, we must implement additional trait for translate function
8181
pub trait DescriptorTrait<Pk: MiniscriptKey> {
82-
/// Computes the scriptSig that will be in place for an unsigned
83-
/// input spending an output with this descriptor. For pre-segwit
84-
/// descriptors, which use the scriptSig for signatures, this
85-
/// returns the empty script.
86-
///
87-
/// This is used in Segwit transactions to produce an unsigned
88-
/// transaction whose txid will not change during signing (since
89-
/// only the witness data will change).
90-
fn unsigned_script_sig(&self) -> Script
91-
where
92-
Pk: ToPublicKey;
93-
9482
/// Returns satisfying non-malleable witness and scriptSig with minimum weight to spend an
9583
/// output controlled by the given descriptor if it possible to
9684
/// construct one using the satisfier S.
@@ -460,22 +448,21 @@ impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {
460448
}
461449
}
462450

463-
/// Computes the scriptSig that will be in place for an unsigned
464-
/// input spending an output with this descriptor. For pre-segwit
465-
/// descriptors, which use the scriptSig for signatures, this
466-
/// returns the empty script.
451+
/// Computes the scriptSig that will be in place for an unsigned input
452+
/// spending an output with this descriptor. For pre-segwit descriptors,
453+
/// which use the scriptSig for signatures, this returns the empty script.
467454
///
468-
/// This is used in Segwit transactions to produce an unsigned
469-
/// transaction whose txid will not change during signing (since
470-
/// only the witness data will change).
455+
/// This is used in Segwit transactions to produce an unsigned transaction
456+
/// whose txid will not change during signing (since only the witness data
457+
/// will change).
471458
pub fn unsigned_script_sig(&self) -> Script {
472459
match *self {
473-
Descriptor::Bare(ref bare) => bare.unsigned_script_sig(),
474-
Descriptor::Pkh(ref pkh) => pkh.unsigned_script_sig(),
475-
Descriptor::Wpkh(ref wpkh) => wpkh.unsigned_script_sig(),
476-
Descriptor::Wsh(ref wsh) => wsh.unsigned_script_sig(),
460+
Descriptor::Bare(_) => Script::new(),
461+
Descriptor::Pkh(_) => Script::new(),
462+
Descriptor::Wpkh(_) => Script::new(),
463+
Descriptor::Wsh(_) => Script::new(),
477464
Descriptor::Sh(ref sh) => sh.unsigned_script_sig(),
478-
Descriptor::Tr(ref tr) => tr.unsigned_script_sig(),
465+
Descriptor::Tr(_) => Script::new(),
479466
}
480467
}
481468

src/descriptor/segwitv0.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,6 @@ where
197197
}
198198

199199
impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Wsh<Pk> {
200-
fn unsigned_script_sig(&self) -> Script
201-
where
202-
Pk: ToPublicKey,
203-
{
204-
Script::new()
205-
}
206-
207200
fn get_satisfaction<S>(&self, satisfier: S) -> Result<(Vec<Vec<u8>>, Script), Error>
208201
where
209202
Pk: ToPublicKey,
@@ -436,13 +429,6 @@ where
436429
}
437430

438431
impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Wpkh<Pk> {
439-
fn unsigned_script_sig(&self) -> Script
440-
where
441-
Pk: ToPublicKey,
442-
{
443-
Script::new()
444-
}
445-
446432
fn get_satisfaction<S>(&self, satisfier: S) -> Result<(Vec<Vec<u8>>, Script), Error>
447433
where
448434
Pk: ToPublicKey,

src/descriptor/sh.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,13 +271,15 @@ impl<Pk: MiniscriptKey + ToPublicKey> Sh<Pk> {
271271
ShInner::Ms(ref ms) => ms.encode(),
272272
}
273273
}
274-
}
275274

276-
impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Sh<Pk> {
277-
fn unsigned_script_sig(&self) -> Script
278-
where
279-
Pk: ToPublicKey,
280-
{
275+
/// Computes the scriptSig that will be in place for an unsigned input
276+
/// spending an output with this descriptor. For pre-segwit descriptors,
277+
/// which use the scriptSig for signatures, this returns the empty script.
278+
///
279+
/// This is used in Segwit transactions to produce an unsigned transaction
280+
/// whose txid will not change during signing (since only the witness data
281+
/// will change).
282+
pub fn unsigned_script_sig(&self) -> Script {
281283
match self.inner {
282284
ShInner::Wsh(ref wsh) => {
283285
// wsh explicit must contain exactly 1 element
@@ -295,7 +297,9 @@ impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Sh<Pk> {
295297
ShInner::SortedMulti(..) | ShInner::Ms(..) => Script::new(),
296298
}
297299
}
300+
}
298301

302+
impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Sh<Pk> {
299303
fn get_satisfaction<S>(&self, satisfier: S) -> Result<(Vec<Vec<u8>>, Script), Error>
300304
where
301305
Pk: ToPublicKey,

src/descriptor/tr.rs

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

561561
impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Tr<Pk> {
562-
fn unsigned_script_sig(&self) -> Script
563-
where
564-
Pk: ToPublicKey,
565-
{
566-
Script::new()
567-
}
568-
569562
fn get_satisfaction<S>(&self, satisfier: S) -> Result<(Vec<Vec<u8>>, Script), Error>
570563
where
571564
Pk: ToPublicKey,

0 commit comments

Comments
 (0)