pub fn translate_pk<Fpk, Fpkh, Q, E>(
        &self,
        mut translatefpk: Fpk,
        mut translatefpkh: Fpkh,
    ) -> Result<Descriptor<Q>, E>
    where
        Fpk: FnMut(&Pk) -> Result<Q, E>,
        Fpkh: FnMut(&Pk::Hash) -> Result<Q::Hash, E>,
        Q: MiniscriptKey,
    {
        match *self {
            Descriptor::Bare(ref ms) => Ok(Descriptor::Bare(
                ms.translate_pk(&mut translatefpk, &mut translatefpkh)?,
            )),
            Descriptor::Pk(ref pk) => translatefpk(pk).map(Descriptor::Pk),
            Descriptor::Pkh(ref pk) => translatefpk(pk).map(Descriptor::Pkh),
            Descriptor::Wpkh(ref pk) => {
                if pk.is_uncompressed() {
                    panic!("Uncompressed pubkeys are not allowed in segwit v0 scripts");
                }
                translatefpk(pk).map(Descriptor::Wpkh)
            }
            Descriptor::ShWpkh(ref pk) => {
                if pk.is_uncompressed() {
                    panic!("Uncompressed pubkeys are not allowed in segwit v0 scripts");
                }
                translatefpk(pk).map(Descriptor::ShWpkh)
            }
            Descriptor::Sh(ref ms) => Ok(Descriptor::Sh(
                ms.translate_pk(&mut translatefpk, &mut translatefpkh)?,
            )),
            Descriptor::Wsh(ref ms) => Ok(Descriptor::Wsh(
                ms.translate_pk(&mut translatefpk, &mut translatefpkh)?,
            )),
            Descriptor::ShWsh(ref ms) => Ok(Descriptor::ShWsh(
                ms.translate_pk(&mut translatefpk, &mut translatefpkh)?,
            )),
            Descriptor::Cov(ref cov) => Ok(Descriptor::Cov(CovenantCtx {
                spend_ctx: None, //FIXME later if required
                commit_ctx: CovenantAddressCtx {
                    cov_info: cov.commit_ctx.cov_info.clone(),
                    redeem_pk: translatefpk(&cov.commit_ctx.redeem_pk)?,
                },
            })),
        }
    }
/// Convert a descriptor using abstract keys to one using specific keys
/// This will panic if translatefpk returns an uncompressed key when
/// converting to a Segwit descriptor. To prevent this panic, ensure
/// translatefpk returns an error in this case instead.
Convert a descriptor using abstract keys to one using specific keys
This will panic if translatefpk returns an uncompressed key when
converting to a Segwit descriptor. To prevent this panic, ensure
translatefpk returns an error in this case instead.
Convert a descriptor using abstract keys to one using specific keys This will panic if translatefpk returns an uncompressed key when converting to a Segwit descriptor . To prevent this panic ensure translatefpk returns an error in this case instead .
pub fn translate_pk<Fpk, Fpkh, Q, E>(
        &self,
        mut translatefpk: Fpk,
        mut translatefpkh: Fpkh,
    ) -> Result<Descriptor<Q>, E>
    where
        Fpk: FnMut(&Pk) -> Result<Q, E>,
        Fpkh: FnMut(&Pk::Hash) -> Result<Q::Hash, E>,
        Q: MiniscriptKey,
    {
        match *self {
            Descriptor::Bare(ref ms) => Ok(Descriptor::Bare(
                ms.translate_pk(&mut translatefpk, &mut translatefpkh)?,
            )),
            Descriptor::Pk(ref pk) => translatefpk(pk).map(Descriptor::Pk),
            Descriptor::Pkh(ref pk) => translatefpk(pk).map(Descriptor::Pkh),
            Descriptor::Wpkh(ref pk) => {
                if pk.is_uncompressed() {
                    panic!("Uncompressed pubkeys are not allowed in segwit v0 scripts");
                }
                translatefpk(pk).map(Descriptor::Wpkh)
            }
            Descriptor::ShWpkh(ref pk) => {
                if pk.is_uncompressed() {
                    panic!("Uncompressed pubkeys are not allowed in segwit v0 scripts");
                }
                translatefpk(pk).map(Descriptor::ShWpkh)
            }
            Descriptor::Sh(ref ms) => Ok(Descriptor::Sh(
                ms.translate_pk(&mut translatefpk, &mut translatefpkh)?,
            )),
            Descriptor::Wsh(ref ms) => Ok(Descriptor::Wsh(
                ms.translate_pk(&mut translatefpk, &mut translatefpkh)?,
            )),
            Descriptor::ShWsh(ref ms) => Ok(Descriptor::ShWsh(
                ms.translate_pk(&mut translatefpk, &mut translatefpkh)?,
            )),
            Descriptor::Cov(ref cov) => Ok(Descriptor::Cov(CovenantCtx {
                spend_ctx: None, //FIXME later if required
                commit_ctx: CovenantAddressCtx {
                    cov_info: cov.commit_ctx.cov_info.clone(),
                    redeem_pk: translatefpk(&cov.commit_ctx.redeem_pk)?,
                },
            })),
        }
    }
pub fn translate_pk < Fpk , Fpkh , Q , E > ( & self , mut translatefpk : Fpk , mut translatefpkh : Fpkh , ) -> Result < Descriptor < Q > , E > where Fpk : FnMut ( & Pk ) -> Result < Q , E > , Fpkh : FnMut ( & Pk :: Hash ) -> Result < Q :: Hash , E > , Q : MiniscriptKey , { match * self { Descriptor :: Bare ( ref ms ) => Ok ( Descriptor :: Bare ( ms . translate_pk ( & mut translatefpk , & mut translatefpkh ) ? , ) ) , Descriptor :: Pk ( ref pk ) => translatefpk ( pk ) . map ( Descriptor :: Pk ) , Descriptor :: Pkh ( ref pk ) => translatefpk ( pk ) . map ( Descriptor :: Pkh ) , Descriptor :: Wpkh ( ref pk ) => { if pk . is_uncompressed ( ) { panic ! ( " " ) ; } translatefpk ( pk ) . map ( Descriptor :: Wpkh ) } Descriptor :: ShWpkh ( ref pk ) => { if pk . is_uncompressed ( ) { panic ! ( " " ) ; } translatefpk ( pk ) . map ( Descriptor :: ShWpkh ) } Descriptor :: Sh ( ref ms ) => Ok ( Descriptor :: Sh ( ms . translate_pk ( & mut translatefpk , & mut translatefpkh ) ? , ) ) , Descriptor :: Wsh ( ref ms ) => Ok ( Descriptor :: Wsh ( ms . translate_pk ( & mut translatefpk , & mut translatefpkh ) ? , ) ) , Descriptor :: ShWsh ( ref ms ) => Ok ( Descriptor :: ShWsh ( ms . translate_pk ( & mut translatefpk , & mut translatefpkh ) ? , ) ) , Descriptor :: Cov ( ref cov ) => Ok ( Descriptor :: Cov ( CovenantCtx { spend_ctx : None , //FIXME later if required commit_ctx : CovenantAddressCtx { cov_info : cov . commit_ctx . cov_info . clone ( ) , redeem_pk : translatefpk ( & cov . commit_ctx . redeem_pk ) ? , } , } ) ) , } }
Convert a descriptor using abstract keys to one using specific keys
This will panic if translatefpk returns an uncompressed key when
converting to a Segwit descriptor.
Convert a descriptor using abstract keys to one using specific keys This will panic if translatefpk returns an uncompressed key when converting to a Segwit descriptor .
&self
translatefpk
Fpk
translatefpkh
Fpkh
&self
translatefpk
Fpk
translatefpkh
Fpkh