Skip to content

Commit 67d7c0e

Browse files
committed
Remove unsigned_script_sig from DescriptorTrait
In preparation for removing the `DescriptorTrait` move the `unsigned_script_sig` trait methods onto each individual descriptor as required (`Sh` only). All the other trait method implementations just return `Script::new()`, just call `new` directly from the implantation of `unsigned_script_sig` on `Descriptor`.
1 parent e08f833 commit 67d7c0e

File tree

5 files changed

+28
-75
lines changed

5 files changed

+28
-75
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 explicit_script(&self) -> Result<Script, Error>
149142
where
150143
Pk: ToPublicKey,
@@ -326,13 +319,6 @@ where
326319
}
327320

328321
impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Pkh<Pk> {
329-
fn unsigned_script_sig(&self) -> Script
330-
where
331-
Pk: ToPublicKey,
332-
{
333-
Script::new()
334-
}
335-
336322
fn explicit_script(&self) -> Result<Script, Error>
337323
where
338324
Pk: ToPublicKey,

src/descriptor/mod.rs

Lines changed: 18 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -76,18 +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 scriptSig that will be in place for an unsigned
80-
/// input spending an output with this descriptor. For pre-segwit
81-
/// descriptors, which use the scriptSig for signatures, this
82-
/// returns the empty script.
83-
///
84-
/// This is used in Segwit transactions to produce an unsigned
85-
/// transaction whose txid will not change during signing (since
86-
/// only the witness data will change).
87-
fn unsigned_script_sig(&self) -> Script
88-
where
89-
Pk: ToPublicKey;
90-
9179
/// Computes the "witness script" of the descriptor, i.e. the underlying
9280
/// script before any hashing is done. For `Bare`, `Pkh` and `Wpkh` this
9381
/// is the scriptPubkey; for `ShWpkh` and `Sh` this is the redeemScript;
@@ -423,6 +411,24 @@ impl<Pk: MiniscriptKey + ToPublicKey> Descriptor<Pk> {
423411
Descriptor::Tr(ref tr) => tr.script_pubkey(),
424412
}
425413
}
414+
415+
/// Computes the scriptSig that will be in place for an unsigned input
416+
/// spending an output with this descriptor. For pre-segwit descriptors,
417+
/// which use the scriptSig for signatures, this returns the empty script.
418+
///
419+
/// This is used in Segwit transactions to produce an unsigned transaction
420+
/// whose txid will not change during signing (since only the witness data
421+
/// will change).
422+
pub fn unsigned_script_sig(&self) -> Script {
423+
match *self {
424+
Descriptor::Bare(_) => Script::new(),
425+
Descriptor::Pkh(_) => Script::new(),
426+
Descriptor::Wpkh(_) => Script::new(),
427+
Descriptor::Wsh(_) => Script::new(),
428+
Descriptor::Sh(ref sh) => sh.unsigned_script_sig(),
429+
Descriptor::Tr(_) => Script::new(),
430+
}
431+
}
426432
}
427433

428434
impl<P, Q> TranslatePk<P, Q> for Descriptor<P>
@@ -456,28 +462,6 @@ where
456462
}
457463

458464
impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Descriptor<Pk> {
459-
/// Computes the scriptSig that will be in place for an unsigned
460-
/// input spending an output with this descriptor. For pre-segwit
461-
/// descriptors, which use the scriptSig for signatures, this
462-
/// returns the empty script.
463-
///
464-
/// This is used in Segwit transactions to produce an unsigned
465-
/// transaction whose txid will not change during signing (since
466-
/// only the witness data will change).
467-
fn unsigned_script_sig(&self) -> Script
468-
where
469-
Pk: ToPublicKey,
470-
{
471-
match *self {
472-
Descriptor::Bare(ref bare) => bare.unsigned_script_sig(),
473-
Descriptor::Pkh(ref pkh) => pkh.unsigned_script_sig(),
474-
Descriptor::Wpkh(ref wpkh) => wpkh.unsigned_script_sig(),
475-
Descriptor::Wsh(ref wsh) => wsh.unsigned_script_sig(),
476-
Descriptor::Sh(ref sh) => sh.unsigned_script_sig(),
477-
Descriptor::Tr(ref tr) => tr.unsigned_script_sig(),
478-
}
479-
}
480-
481465
/// Computes the "witness script" of the descriptor, i.e. the underlying
482466
/// script before any hashing is done. For `Bare`, `Pkh` and `Wpkh` this
483467
/// is the scriptPubkey; for `ShWpkh` and `Sh` this is the redeemScript;

src/descriptor/segwitv0.rs

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

198198
impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Wsh<Pk> {
199-
fn unsigned_script_sig(&self) -> Script
200-
where
201-
Pk: ToPublicKey,
202-
{
203-
Script::new()
204-
}
205-
206199
fn explicit_script(&self) -> Result<Script, Error>
207200
where
208201
Pk: ToPublicKey,
@@ -438,13 +431,6 @@ where
438431
}
439432

440433
impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Wpkh<Pk> {
441-
fn unsigned_script_sig(&self) -> Script
442-
where
443-
Pk: ToPublicKey,
444-
{
445-
Script::new()
446-
}
447-
448434
fn explicit_script(&self) -> Result<Script, Error>
449435
where
450436
Pk: ToPublicKey,

src/descriptor/sh.rs

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

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

303+
impl<Pk: MiniscriptKey> DescriptorTrait<Pk> for Sh<Pk> {
300304
fn explicit_script(&self) -> Result<Script, Error>
301305
where
302306
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 unsigned_script_sig(&self) -> Script
558-
where
559-
Pk: ToPublicKey,
560-
{
561-
Script::new()
562-
}
563-
564557
fn explicit_script(&self) -> Result<Script, Error>
565558
where
566559
Pk: ToPublicKey,

0 commit comments

Comments
 (0)