pub trait TranslatePk2<P: MiniscriptKey<Hash = P>, Q: MiniscriptKey>: TranslatePk<P, Q> {
// Provided methods
fn translate_pk2<Fpk: Fn(&P) -> Result<Q, E>, E>(
&self,
translatefpk: Fpk,
) -> Result<<Self as TranslatePk<P, Q>>::Output, E> { ... }
fn translate_pk2_infallible<Fpk: Fn(&P) -> Q>(
&self,
translatefpk: Fpk,
) -> <Self as TranslatePk<P, Q>>::Output { ... }
}Expand description
Variant of TranslatePk where P’s hash is P, so the hashes
can be converted by reusing the key-conversion function
Provided Methods§
Sourcefn translate_pk2<Fpk: Fn(&P) -> Result<Q, E>, E>(
&self,
translatefpk: Fpk,
) -> Result<<Self as TranslatePk<P, Q>>::Output, E>
fn translate_pk2<Fpk: Fn(&P) -> Result<Q, E>, E>( &self, translatefpk: Fpk, ) -> Result<<Self as TranslatePk<P, Q>>::Output, E>
Translate a struct from one generic to another where the translation for Pk is provided by translatefpk
Examples found in repository?
examples/xpub_descriptors.rs (line 31)
23fn main() {
24 // For deriving from descriptors, we need to provide a secp context
25 let secp_ctx = secp256k1::Secp256k1::verification_only();
26 // P2WSH and single xpubs
27 let addr_one = Descriptor::<DescriptorPublicKey>::from_str(
28 "wsh(sortedmulti(1,xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB,xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH))",
29 )
30 .unwrap()
31 .translate_pk2(|xpk| xpk.derive_public_key(&secp_ctx))
32 .unwrap()
33 .address(bitcoin::Network::Bitcoin).unwrap();
34
35 let addr_two = Descriptor::<DescriptorPublicKey>::from_str(
36 "wsh(sortedmulti(1,xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH,xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB))",
37 )
38 .unwrap()
39 .translate_pk2(|xpk| xpk.derive_public_key(&secp_ctx))
40 .unwrap()
41 .address(bitcoin::Network::Bitcoin).unwrap();
42 let expected = bitcoin::Address::from_str(
43 "bc1qpq2cfgz5lktxzr5zqv7nrzz46hsvq3492ump9pz8rzcl8wqtwqcspx5y6a",
44 )
45 .unwrap();
46 assert_eq!(addr_one, expected);
47 assert_eq!(addr_two, expected);
48
49 // P2WSH-P2SH and ranged xpubs
50 let addr_one = Descriptor::<DescriptorPublicKey>::from_str(
51 "sh(wsh(sortedmulti(1,xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB/1/0/*,xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH/0/0/*)))",
52 )
53 .unwrap()
54 .derived_descriptor(&secp_ctx, 5)
55 .unwrap()
56 .address(bitcoin::Network::Bitcoin).unwrap();
57
58 let addr_two = Descriptor::<DescriptorPublicKey>::from_str(
59 "sh(wsh(sortedmulti(1,xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH/0/0/*,xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB/1/0/*)))",
60 )
61 .unwrap()
62 .derived_descriptor(&secp_ctx, 5)
63 .unwrap()
64 .address(bitcoin::Network::Bitcoin).unwrap();
65 let expected = bitcoin::Address::from_str("325zcVBN5o2eqqqtGwPjmtDd8dJRyYP82s").unwrap();
66 assert_eq!(addr_one, expected);
67 assert_eq!(addr_two, expected);
68}Sourcefn translate_pk2_infallible<Fpk: Fn(&P) -> Q>(
&self,
translatefpk: Fpk,
) -> <Self as TranslatePk<P, Q>>::Output
fn translate_pk2_infallible<Fpk: Fn(&P) -> Q>( &self, translatefpk: Fpk, ) -> <Self as TranslatePk<P, Q>>::Output
Translate a struct from one generic to another where the translation for Pk is provided by translatefpk
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.