Skip to content

Commit 1409d49

Browse files
committed
descriptor: Update the docs around spk method
A few of the descriptor types define a helper method `spk` to get the scriptPukey. Currently the docs appear to be stale because `Descriptor::script_pubkey` does not return an error. Leave the API as it is and make an effort to document the code as it is written.
1 parent 161978e commit 1409d49

File tree

4 files changed

+44
-43
lines changed

4 files changed

+44
-43
lines changed

src/descriptor/bare.rs

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,20 @@ impl<Pk: MiniscriptKey> Bare<Pk> {
6464
}
6565

6666
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
67+
/// Obtains the corresponding script pubkey for this descriptor.
68+
/// Called by [`DescriptorTrait::script_pubkey`] for this descriptor.
6969
pub fn spk(&self) -> Script {
7070
self.ms.encode()
7171
}
7272

73-
/// Obtain the underlying miniscript for this descriptor
74-
/// Non failing verion of [`DescriptorTrait::explicit_script`] for this descriptor
73+
/// Obtains the underlying miniscript for this descriptor.
74+
/// Equivalent to [`DescriptorTrait::script_pubkey`] for this descriptor.
7575
pub fn inner_script(&self) -> Script {
7676
self.spk()
7777
}
7878

79-
/// Obtain the pre bip-340 signature script code for this descriptor
80-
/// Non failing verion of [`DescriptorTrait::script_code`] for this descriptor
79+
/// Obtains the pre bip-340 signature script code for this descriptor.
80+
/// Equivalent to [`DescriptorTrait::script_pubkey`] for this descriptor.
8181
pub fn ecdsa_sighash_script_code(&self) -> Script {
8282
self.spk()
8383
}
@@ -259,27 +259,28 @@ impl<Pk: MiniscriptKey> Pkh<Pk> {
259259
}
260260

261261
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
262+
/// Obtains the corresponding script pubkey for this descriptor.
263+
/// Called by [`DescriptorTrait::script_pubkey`] for this descriptor.
264264
pub fn spk(&self) -> Script {
265265
let addr = Address::p2pkh(&self.pk.to_public_key(), Network::Bitcoin);
266266
addr.script_pubkey()
267267
}
268268

269-
/// Obtain the corresponding script pubkey for this descriptor
270-
/// Non failing verion of [`DescriptorTrait::address`] for this descriptor
269+
/// Obtains the [`Address`] for this descriptor.
271270
pub fn addr(&self, network: Network) -> Address {
272271
Address::p2pkh(&self.pk.to_public_key(), network)
273272
}
274273

275-
/// Obtain the underlying miniscript for this descriptor
276-
/// Non failing verion of [`DescriptorTrait::explicit_script`] for this descriptor
274+
/// Obtains the underlying miniscript for this descriptor.
275+
/// Called by [`DescriptorTrait::explicit_script`] for this descriptor.
276+
/// Equivalent to [`DescriptorTrait::script_pubkey`] for this descriptor.
277277
pub fn inner_script(&self) -> Script {
278278
self.spk()
279279
}
280280

281-
/// Obtain the pre bip-340 signature script code for this descriptor
282-
/// Non failing verion of [`DescriptorTrait::script_code`] for this descriptor
281+
/// Obtain the pre bip-340 signature script code for this descriptor.
282+
/// Called by [`DescriptorTrait::script_code`] for this descriptor.
283+
/// Equivalent to [`DescriptorTrait::script_pubkey`] for this descriptor.
283284
pub fn ecdsa_sighash_script_code(&self) -> Script {
284285
self.spk()
285286
}

src/descriptor/segwitv0.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,32 +79,33 @@ impl<Pk: MiniscriptKey> Wsh<Pk> {
7979
}
8080

8181
impl<Pk: MiniscriptKey + ToPublicKey> Wsh<Pk> {
82-
/// Obtain the corresponding script pubkey for this descriptor
83-
/// Non failing verion of [`DescriptorTrait::script_pubkey`] for this descriptor
82+
/// Obtains the corresponding script pubkey for this descriptor.
83+
/// Called by [`DescriptorTrait::script_pubkey`] for this descriptor.
8484
pub fn spk(&self) -> Script {
8585
self.inner_script().to_v0_p2wsh()
8686
}
8787

88-
/// Obtain the corresponding script pubkey for this descriptor
89-
/// Non failing verion of [`DescriptorTrait::address`] for this descriptor
88+
/// Obtains the corresponding script pubkey for this descriptor.
89+
/// Called by [`DescriptorTrait::address`] for this descriptor.
9090
pub fn addr(&self, network: Network) -> Address {
9191
match self.inner {
9292
WshInner::SortedMulti(ref smv) => Address::p2wsh(&smv.encode(), network),
9393
WshInner::Ms(ref ms) => Address::p2wsh(&ms.encode(), network),
9494
}
9595
}
9696

97-
/// Obtain the underlying miniscript for this descriptor
98-
/// Non failing verion of [`DescriptorTrait::explicit_script`] for this descriptor
97+
/// Obtains the underlying miniscript for this descriptor.
98+
/// Called by [`DescriptorTrait::explicit_script`] for this descriptor.
9999
pub fn inner_script(&self) -> Script {
100100
match self.inner {
101101
WshInner::SortedMulti(ref smv) => smv.encode(),
102102
WshInner::Ms(ref ms) => ms.encode(),
103103
}
104104
}
105105

106-
/// Obtain the pre bip-340 signature script code for this descriptor
107-
/// Non failing verion of [`DescriptorTrait::script_code`] for this descriptor
106+
/// Obtains the pre bip-340 signature script code for this descriptor.
107+
/// Called by [`DescriptorTrait::script_code`] for this descriptor.
108+
/// Equivalent to `self.inner_script`.
108109
pub fn ecdsa_sighash_script_code(&self) -> Script {
109110
self.inner_script()
110111
}
@@ -359,28 +360,29 @@ impl<Pk: MiniscriptKey> Wpkh<Pk> {
359360
}
360361

361362
impl<Pk: MiniscriptKey + ToPublicKey> Wpkh<Pk> {
362-
/// Obtain the corresponding script pubkey for this descriptor
363-
/// Non failing verion of [`DescriptorTrait::script_pubkey`] for this descriptor
363+
/// Obtains the corresponding script pubkey for this descriptor.
364+
/// Called by [`DescriptorTrait::script_pubkey`] for this descriptor.
364365
pub fn spk(&self) -> Script {
365366
let addr = Address::p2wpkh(&self.pk.to_public_key(), Network::Bitcoin)
366367
.expect("wpkh descriptors have compressed keys");
367368
addr.script_pubkey()
368369
}
369370

370-
/// Obtain the corresponding script pubkey for this descriptor
371-
/// Non failing verion of [`DescriptorTrait::address`] for this descriptor
371+
/// Obtains the [`Address`] for this descriptor.
372372
pub fn addr(&self, network: Network) -> Address {
373-
Address::p2wpkh(&self.pk.to_public_key(), network)
373+
bitcoin::Address::p2wpkh(&self.pk.to_public_key(), network)
374374
.expect("Rust Miniscript types don't allow uncompressed pks in segwit descriptors")
375375
}
376376

377-
/// Obtain the underlying miniscript for this descriptor
378-
/// Non failing verion of [`DescriptorTrait::explicit_script`] for this descriptor
377+
/// Obtains the underlying miniscript for this descriptor.
378+
/// Called by [`DescriptorTrait::explicit_script`] for this descriptor.
379+
/// Equivalent to [`DescriptorTrait::script_pubkey`] for this descriptor.
379380
pub fn inner_script(&self) -> Script {
380381
self.spk()
381382
}
382383

383384
/// Obtains the pre bip-340 signature script code for this descriptor.
385+
/// Called by [`DescriptorTrait::script_code`] for this descriptor.
384386
pub fn ecdsa_sighash_script_code(&self) -> Script {
385387
// For SegWit outputs, it is defined by bip-0143 (quoted below) and is different from
386388
// the previous txo's scriptPubKey.

src/descriptor/sh.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,8 @@ impl<Pk: MiniscriptKey> Sh<Pk> {
208208
}
209209

210210
impl<Pk: MiniscriptKey + ToPublicKey> Sh<Pk> {
211-
/// Obtain the corresponding script pubkey for this descriptor
212-
/// Non failing verion of [`DescriptorTrait::script_pubkey`] for this descriptor
211+
/// Obtains the corresponding script pubkey for this descriptor.
212+
/// Called by [`DescriptorTrait::script_pubkey`] for this descriptor.
213213
pub fn spk(&self) -> Script {
214214
match self.inner {
215215
ShInner::Wsh(ref wsh) => wsh.spk().to_p2sh(),
@@ -219,8 +219,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Sh<Pk> {
219219
}
220220
}
221221

222-
/// Obtain the corresponding script pubkey for this descriptor
223-
/// Non failing verion of [`DescriptorTrait::address`] for this descriptor
222+
/// Obtains the [`Address`] for this descriptor.
224223
pub fn addr(&self, network: Network) -> Address {
225224
match self.inner {
226225
ShInner::Wsh(ref wsh) => {
@@ -238,8 +237,8 @@ impl<Pk: MiniscriptKey + ToPublicKey> Sh<Pk> {
238237
}
239238
}
240239

241-
/// Obtain the underlying miniscript for this descriptor
242-
/// Non failing verion of [`DescriptorTrait::explicit_script`] for this descriptor
240+
/// Obtains the underlying miniscript for this descriptor.
241+
/// Called by [`DescriptorTrait::explicit_script`] for this descriptor.
243242
pub fn inner_script(&self) -> Script {
244243
match self.inner {
245244
ShInner::Wsh(ref wsh) => wsh.inner_script(),
@@ -249,12 +248,12 @@ impl<Pk: MiniscriptKey + ToPublicKey> Sh<Pk> {
249248
}
250249
}
251250

252-
/// Obtain the pre bip-340 signature script code for this descriptor
253-
/// Non failing verion of [`DescriptorTrait::script_code`] for this descriptor
251+
/// Obtain the pre bip-340 signature script code for this descriptor.
252+
/// Called by [`DescriptorTrait::script_code`] for this descriptor.
254253
pub fn ecdsa_sighash_script_code(&self) -> Script {
255254
match self.inner {
256-
// - For P2WSH witness program, if the witnessScript does not contain any `OP_CODESEPARATOR`,
257-
// the `scriptCode` is the `witnessScript` serialized as scripts inside CTxOut.
255+
// For P2WSH witness program, if the witnessScript does not contain any `OP_CODESEPARATOR`,
256+
// the `scriptCode` is the `witnessScript` serialized as scripts inside CTxOut.
258257
ShInner::Wsh(ref wsh) => wsh.ecdsa_sighash_script_code(),
259258
ShInner::SortedMulti(ref smv) => smv.encode(),
260259
ShInner::Wpkh(ref wpkh) => wpkh.ecdsa_sighash_script_code(),

src/descriptor/tr.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,8 @@ impl<Pk: MiniscriptKey> Tr<Pk> {
274274
}
275275

276276
impl<Pk: MiniscriptKey + ToPublicKey> Tr<Pk> {
277-
/// Obtain the corresponding script pubkey for this descriptor
278-
/// Same as[`DescriptorTrait::script_pubkey`] for this descriptor
277+
/// Obtains the corresponding script pubkey for this descriptor.
278+
/// Called by [`DescriptorTrait::script_pubkey`] for this descriptor.
279279
pub fn spk(&self) -> Script {
280280
let output_key = self.spend_info().output_key();
281281
let builder = bitcoin::blockdata::script::Builder::new();
@@ -285,8 +285,7 @@ impl<Pk: MiniscriptKey + ToPublicKey> Tr<Pk> {
285285
.into_script()
286286
}
287287

288-
/// Obtain the corresponding script pubkey for this descriptor
289-
/// Same as[`DescriptorTrait::address`] for this descriptor
288+
/// Obtains the [`Address`] for this descriptor.
290289
pub fn addr(&self, network: Network) -> Result<Address, Error> {
291290
let spend_info = self.spend_info();
292291
Ok(Address::p2tr_tweaked(spend_info.output_key(), network))

0 commit comments

Comments
 (0)