Skip to content

Commit 4a234e2

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 4a234e2

File tree

4 files changed

+22
-27
lines changed

4 files changed

+22
-27
lines changed

src/descriptor/bare.rs

Lines changed: 6 additions & 6 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
}

src/descriptor/segwitv0.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -359,23 +359,22 @@ impl<Pk: MiniscriptKey> Wpkh<Pk> {
359359
}
360360

361361
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
362+
/// Obtains the corresponding script pubkey for this descriptor.
363+
/// Called by [`DescriptorTrait::script_pubkey`] for this descriptor.
364364
pub fn spk(&self) -> Script {
365365
let addr = Address::p2wpkh(&self.pk.to_public_key(), Network::Bitcoin)
366366
.expect("wpkh descriptors have compressed keys");
367367
addr.script_pubkey()
368368
}
369369

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

377-
/// Obtain the underlying miniscript for this descriptor
378-
/// Non failing verion of [`DescriptorTrait::explicit_script`] for this descriptor
376+
/// Obtains the underlying miniscript for this descriptor.
377+
/// Equivalent to [`DescriptorTrait::script_pubkey`] for this descriptor.
379378
pub fn inner_script(&self) -> Script {
380379
self.spk()
381380
}

src/descriptor/sh.rs

Lines changed: 7 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,7 @@ 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.
243241
pub fn inner_script(&self) -> Script {
244242
match self.inner {
245243
ShInner::Wsh(ref wsh) => wsh.inner_script(),
@@ -249,12 +247,11 @@ impl<Pk: MiniscriptKey + ToPublicKey> Sh<Pk> {
249247
}
250248
}
251249

252-
/// Obtain the pre bip-340 signature script code for this descriptor
253-
/// Non failing verion of [`DescriptorTrait::script_code`] for this descriptor
250+
/// Obtain the pre bip-340 signature script code for this descriptor.
254251
pub fn ecdsa_sighash_script_code(&self) -> Script {
255252
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.
253+
// For P2WSH witness program, if the witnessScript does not contain any `OP_CODESEPARATOR`,
254+
// the `scriptCode` is the `witnessScript` serialized as scripts inside CTxOut.
258255
ShInner::Wsh(ref wsh) => wsh.ecdsa_sighash_script_code(),
259256
ShInner::SortedMulti(ref smv) => smv.encode(),
260257
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+
/// This is equivalent to [`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)