Merge rust-bitcoin/rust-bitcoin#1658: Changing docs and examples to use correct function signature
f69363d71a
adding suggested documentation for path arg (Lorenzo Maturano)673ca2d2fe
changing docs and examples to use reference to slice in `derive_pub` (Lorenzo Maturano) Pull request description: `P: AsRef<[ChildNumber]>` means that path can be borrowed as a reference to a slice of `ChildNumber`. While it does work with `Vec`, the documentation and examples mislead the user into thinking that he/she has to use a vec, which is not true. A simple reference to a slice of `ChildNumber` also works and does not consume heap ACKs for top commit: tcharding: ACKf69363d71a
Kixunil: ACKf69363d71a
Tree-SHA512: 9f0a2764c676ecaa45de69663c83c3008ee01f534c324ceca627c69d689d6ca6d0a3dda9361eaa402bacc68975e998840b78a3856e0572db3de10325b354ac6a
This commit is contained in:
commit
97c925ab36
|
@ -52,7 +52,7 @@ fn main() {
|
||||||
// generate first receiving address at m/0/0
|
// generate first receiving address at m/0/0
|
||||||
// manually creating indexes this time
|
// manually creating indexes this time
|
||||||
let zero = ChildNumber::from_normal_idx(0).unwrap();
|
let zero = ChildNumber::from_normal_idx(0).unwrap();
|
||||||
let public_key = xpub.derive_pub(&secp, &vec![zero, zero]).unwrap().public_key;
|
let public_key = xpub.derive_pub(&secp, &[zero, zero]).unwrap().public_key;
|
||||||
let address = Address::p2wpkh(&PublicKey::new(public_key), network).unwrap();
|
let address = Address::p2wpkh(&PublicKey::new(public_key), network).unwrap();
|
||||||
println!("First receiving address: {}", address);
|
println!("First receiving address: {}", address);
|
||||||
}
|
}
|
||||||
|
|
|
@ -265,7 +265,7 @@ impl WatchOnly {
|
||||||
&self,
|
&self,
|
||||||
secp: &Secp256k1<C>,
|
secp: &Secp256k1<C>,
|
||||||
) -> Result<(PublicKey, Address, DerivationPath)> {
|
) -> Result<(PublicKey, Address, DerivationPath)> {
|
||||||
let path = vec![ChildNumber::from_normal_idx(1)?, ChildNumber::from_normal_idx(0)?];
|
let path = [ChildNumber::from_normal_idx(1)?, ChildNumber::from_normal_idx(0)?];
|
||||||
let derived = self.account_0_xpub.derive_pub(secp, &path)?;
|
let derived = self.account_0_xpub.derive_pub(secp, &path)?;
|
||||||
|
|
||||||
let pk = derived.to_pub();
|
let pk = derived.to_pub();
|
||||||
|
|
|
@ -683,7 +683,7 @@ impl ExtendedPubKey {
|
||||||
|
|
||||||
/// Attempts to derive an extended public key from a path.
|
/// Attempts to derive an extended public key from a path.
|
||||||
///
|
///
|
||||||
/// The `path` argument can be both of type `DerivationPath` or `Vec<ChildNumber>`.
|
/// The `path` argument can be any type implementing `AsRef<ChildNumber>`, such as `DerivationPath`, for instance.
|
||||||
pub fn derive_pub<C: secp256k1::Verification, P: AsRef<[ChildNumber]>>(
|
pub fn derive_pub<C: secp256k1::Verification, P: AsRef<[ChildNumber]>>(
|
||||||
&self,
|
&self,
|
||||||
secp: &Secp256k1<C>,
|
secp: &Secp256k1<C>,
|
||||||
|
|
Loading…
Reference in New Issue