fn decode_miniscript_inner<Pk, Ctx>(
            d: &mut impl io::Read,
            mut depth: u8,
        ) -> Result<Miniscript<Pk, Ctx>, Error>
        where
            Pk: MiniscriptKey + StrictDecode,
            <Pk as MiniscriptKey>::Hash: StrictDecode,
            Ctx: miniscript::ScriptContext,
        {
            if depth > MINISCRIPT_DEPTH_LIMIT {
                return Err(Error::ExceedMaxItems(
                    MINISCRIPT_DEPTH_LIMIT as usize,
                ));
            }
            depth += 1;
            let term = match d.read_u8()? {
                MS_TRUE => Terminal::True,
                MS_FALSE => Terminal::False,
                MS_KEY => Terminal::PkK(Pk::strict_decode(d)?),
                MS_KEY_HASH => Terminal::PkH(Pk::Hash::strict_decode(d)?),

                MS_AFTER => Terminal::After(u32::strict_decode(d)?),
                MS_OLDER => Terminal::Older(u32::strict_decode(d)?),
                MS_SHA256 => Terminal::Sha256(sha256::Hash::strict_decode(d)?),
                MS_HASH256 => {
                    Terminal::Hash256(sha256d::Hash::strict_decode(d)?)
                }
                MS_RIPEMD160 => {
                    Terminal::Ripemd160(ripemd160::Hash::strict_decode(d)?)
                }
                MS_HASH160 => {
                    Terminal::Hash160(hash160::Hash::strict_decode(d)?)
                }

                MS_ALT => {
                    Terminal::Alt(decode_miniscript_inner(d, depth)?.into())
                }
                MS_SWAP => {
                    Terminal::Swap(decode_miniscript_inner(d, depth)?.into())
                }
                MS_CHECK => {
                    Terminal::Check(decode_miniscript_inner(d, depth)?.into())
                }
                MS_DUP_IF => {
                    Terminal::DupIf(decode_miniscript_inner(d, depth)?.into())
                }
                MS_VERIFY => {
                    Terminal::Verify(decode_miniscript_inner(d, depth)?.into())
                }
                MS_NON_ZERO => {
                    Terminal::NonZero(decode_miniscript_inner(d, depth)?.into())
                }
                MS_ZERO_NE => Terminal::ZeroNotEqual(
                    decode_miniscript_inner(d, depth)?.into(),
                ),

                MS_AND_V => Terminal::AndV(
                    decode_miniscript_inner(d, depth)?.into(),
                    decode_miniscript_inner(d, depth)?.into(),
                ),
                MS_AND_B => Terminal::AndB(
                    decode_miniscript_inner(d, depth)?.into(),
                    decode_miniscript_inner(d, depth)?.into(),
                ),
                MS_AND_OR => Terminal::AndOr(
                    decode_miniscript_inner(d, depth)?.into(),
                    decode_miniscript_inner(d, depth)?.into(),
                    decode_miniscript_inner(d, depth)?.into(),
                ),
                MS_OR_B => Terminal::OrB(
                    decode_miniscript_inner(d, depth)?.into(),
                    decode_miniscript_inner(d, depth)?.into(),
                ),
                MS_OR_D => Terminal::OrD(
                    decode_miniscript_inner(d, depth)?.into(),
                    decode_miniscript_inner(d, depth)?.into(),
                ),
                MS_OR_C => Terminal::OrC(
                    decode_miniscript_inner(d, depth)?.into(),
                    decode_miniscript_inner(d, depth)?.into(),
                ),
                MS_OR_I => Terminal::OrI(
                    decode_miniscript_inner(d, depth)?.into(),
                    decode_miniscript_inner(d, depth)?.into(),
                ),
                MS_MULTI => Terminal::Multi(
                    d.read_u16()? as usize,
                    Vec::strict_decode(d)?,
                ),
                MS_THRESH => {
                    let thresh = d.read_u16()? as usize;
                    let len = d.read_u16()?;
                    let mut vec = Vec::with_capacity(len as usize);
                    for _ in 0..len {
                        vec.push(decode_miniscript_inner(d, depth)?.into());
                    }
                    Terminal::Thresh(thresh, vec)
                }

                wrong => {
                    return Err(Error::DataIntegrityError(format!(
                        "byte {:#04X} does not correspond to any of \
                         miniscript instructions",
                        wrong
                    )))
                }
            };
            Miniscript::from_ast(term).map_err(|err| {
                Error::DataIntegrityError(format!(
                    "miniscript does not pass check: {}",
                    err
                ))
            })
        }
// We need this first because of the need to control maximum number of
// nested miniscript code, and than because of the rust compiler
// limitations in working with recursive generic functions
We need this first because of the need to control maximum number of
nested miniscript code, and than because of the rust compiler
limitations in working with recursive generic functions
We need this first because of the need to control maximum number of nested miniscript code and than because of the rust compiler limitations in working with recursive generic functions
fn decode_miniscript_inner<Pk, Ctx>(
            d: &mut impl io::Read,
            mut depth: u8,
        ) -> Result<Miniscript<Pk, Ctx>, Error>
        where
            Pk: MiniscriptKey + StrictDecode,
            <Pk as MiniscriptKey>::Hash: StrictDecode,
            Ctx: miniscript::ScriptContext,
        {
            if depth > MINISCRIPT_DEPTH_LIMIT {
                return Err(Error::ExceedMaxItems(
                    MINISCRIPT_DEPTH_LIMIT as usize,
                ));
            }
            depth += 1;
            let term = match d.read_u8()? {
                MS_TRUE => Terminal::True,
                MS_FALSE => Terminal::False,
                MS_KEY => Terminal::PkK(Pk::strict_decode(d)?),
                MS_KEY_HASH => Terminal::PkH(Pk::Hash::strict_decode(d)?),
                MS_AFTER => Terminal::After(u32::strict_decode(d)?),
                MS_OLDER => Terminal::Older(u32::strict_decode(d)?),
                MS_SHA256 => Terminal::Sha256(sha256::Hash::strict_decode(d)?),
                MS_HASH256 => {
                    Terminal::Hash256(sha256d::Hash::strict_decode(d)?)
                }
                MS_RIPEMD160 => {
                    Terminal::Ripemd160(ripemd160::Hash::strict_decode(d)?)
                }
                MS_HASH160 => {
                    Terminal::Hash160(hash160::Hash::strict_decode(d)?)
                }
                MS_ALT => {
                    Terminal::Alt(decode_miniscript_inner(d, depth)?.into())
                }
                MS_SWAP => {
                    Terminal::Swap(decode_miniscript_inner(d, depth)?.into())
                }
                MS_CHECK => {
                    Terminal::Check(decode_miniscript_inner(d, depth)?.into())
                }
                MS_DUP_IF => {
                    Terminal::DupIf(decode_miniscript_inner(d, depth)?.into())
                }
                MS_VERIFY => {
                    Terminal::Verify(decode_miniscript_inner(d, depth)?.into())
                }
                MS_NON_ZERO => {
                    Terminal::NonZero(decode_miniscript_inner(d, depth)?.into())
                }
                MS_ZERO_NE => Terminal::ZeroNotEqual(
                    decode_miniscript_inner(d, depth)?.into(),
                ),
                MS_AND_V => Terminal::AndV(
                    decode_miniscript_inner(d, depth)?.into(),
                    decode_miniscript_inner(d, depth)?.into(),
                ),
                MS_AND_B => Terminal::AndB(
                    decode_miniscript_inner(d, depth)?.into(),
                    decode_miniscript_inner(d, depth)?.into(),
                ),
                MS_AND_OR => Terminal::AndOr(
                    decode_miniscript_inner(d, depth)?.into(),
                    decode_miniscript_inner(d, depth)?.into(),
                    decode_miniscript_inner(d, depth)?.into(),
                ),
                MS_OR_B => Terminal::OrB(
                    decode_miniscript_inner(d, depth)?.into(),
                    decode_miniscript_inner(d, depth)?.into(),
                ),
                MS_OR_D => Terminal::OrD(
                    decode_miniscript_inner(d, depth)?.into(),
                    decode_miniscript_inner(d, depth)?.into(),
                ),
                MS_OR_C => Terminal::OrC(
                    decode_miniscript_inner(d, depth)?.into(),
                    decode_miniscript_inner(d, depth)?.into(),
                ),
                MS_OR_I => Terminal::OrI(
                    decode_miniscript_inner(d, depth)?.into(),
                    decode_miniscript_inner(d, depth)?.into(),
                ),
                MS_MULTI => Terminal::Multi(
                    d.read_u16()? as usize,
                    Vec::strict_decode(d)?,
                ),
                MS_THRESH => {
                    let thresh = d.read_u16()? as usize;
                    let len = d.read_u16()?;
                    let mut vec = Vec::with_capacity(len as usize);
                    for _ in 0..len {
                        vec.push(decode_miniscript_inner(d, depth)?.into());
                    }
                    Terminal::Thresh(thresh, vec)
                }
                wrong => {
                    return Err(Error::DataIntegrityError(format!(
                        "byte {:#04X} does not correspond to any of \
                         miniscript instructions",
                        wrong
                    )))
                }
            };
            Miniscript::from_ast(term).map_err(|err| {
                Error::DataIntegrityError(format!(
                    "miniscript does not pass check: {}",
                    err
                ))
            })
        }
fn decode_miniscript_inner < Pk , Ctx > ( d : & mut impl io :: Read , mut depth : u8 , ) -> Result < Miniscript < Pk , Ctx > , Error > where Pk : MiniscriptKey + StrictDecode , < Pk as MiniscriptKey > :: Hash : StrictDecode , Ctx : miniscript :: ScriptContext , { if depth > MINISCRIPT_DEPTH_LIMIT { return Err ( Error :: ExceedMaxItems ( MINISCRIPT_DEPTH_LIMIT as usize , ) ) ; } depth += 1 ; let term = match d . read_u8 ( ) ? { MS_TRUE => Terminal :: True , MS_FALSE => Terminal :: False , MS_KEY => Terminal :: PkK ( Pk :: strict_decode ( d ) ? ) , MS_KEY_HASH => Terminal :: PkH ( Pk :: Hash :: strict_decode ( d ) ? ) , MS_AFTER => Terminal :: After ( u32 :: strict_decode ( d ) ? ) , MS_OLDER => Terminal :: Older ( u32 :: strict_decode ( d ) ? ) , MS_SHA256 => Terminal :: Sha256 ( sha256 :: Hash :: strict_decode ( d ) ? ) , MS_HASH256 => { Terminal :: Hash256 ( sha256d :: Hash :: strict_decode ( d ) ? ) } MS_RIPEMD160 => { Terminal :: Ripemd160 ( ripemd160 :: Hash :: strict_decode ( d ) ? ) } MS_HASH160 => { Terminal :: Hash160 ( hash160 :: Hash :: strict_decode ( d ) ? ) } MS_ALT => { Terminal :: Alt ( decode_miniscript_inner ( d , depth ) ? . into ( ) ) } MS_SWAP => { Terminal :: Swap ( decode_miniscript_inner ( d , depth ) ? . into ( ) ) } MS_CHECK => { Terminal :: Check ( decode_miniscript_inner ( d , depth ) ? . into ( ) ) } MS_DUP_IF => { Terminal :: DupIf ( decode_miniscript_inner ( d , depth ) ? . into ( ) ) } MS_VERIFY => { Terminal :: Verify ( decode_miniscript_inner ( d , depth ) ? . into ( ) ) } MS_NON_ZERO => { Terminal :: NonZero ( decode_miniscript_inner ( d , depth ) ? . into ( ) ) } MS_ZERO_NE => Terminal :: ZeroNotEqual ( decode_miniscript_inner ( d , depth ) ? . into ( ) , ) , MS_AND_V => Terminal :: AndV ( decode_miniscript_inner ( d , depth ) ? . into ( ) , decode_miniscript_inner ( d , depth ) ? . into ( ) , ) , MS_AND_B => Terminal :: AndB ( decode_miniscript_inner ( d , depth ) ? . into ( ) , decode_miniscript_inner ( d , depth ) ? . into ( ) , ) , MS_AND_OR => Terminal :: AndOr ( decode_miniscript_inner ( d , depth ) ? . into ( ) , decode_miniscript_inner ( d , depth ) ? . into ( ) , decode_miniscript_inner ( d , depth ) ? . into ( ) , ) , MS_OR_B => Terminal :: OrB ( decode_miniscript_inner ( d , depth ) ? . into ( ) , decode_miniscript_inner ( d , depth ) ? . into ( ) , ) , MS_OR_D => Terminal :: OrD ( decode_miniscript_inner ( d , depth ) ? . into ( ) , decode_miniscript_inner ( d , depth ) ? . into ( ) , ) , MS_OR_C => Terminal :: OrC ( decode_miniscript_inner ( d , depth ) ? . into ( ) , decode_miniscript_inner ( d , depth ) ? . into ( ) , ) , MS_OR_I => Terminal :: OrI ( decode_miniscript_inner ( d , depth ) ? . into ( ) , decode_miniscript_inner ( d , depth ) ? . into ( ) , ) , MS_MULTI => Terminal :: Multi ( d . read_u16 ( ) ? as usize , Vec :: strict_decode ( d ) ? , ) , MS_THRESH => { let thresh = d . read_u16 ( ) ? as usize ; let len = d . read_u16 ( ) ? ; let mut vec = Vec :: with_capacity ( len as usize ) ; for _ in 0 .. len { vec . push ( decode_miniscript_inner ( d , depth ) ? . into ( ) ) ; } Terminal :: Thresh ( thresh , vec ) } wrong => { return Err ( Error :: DataIntegrityError ( format ! ( " \
 " wrong ) ) ) } } ; Miniscript :: from_ast ( term ) . map_err ( | err | { Error :: DataIntegrityError ( format ! ( " " err ) ) } ) }
We need this first because of the need to control maximum number of
nested miniscript code, and than because of the rust compiler
limitations in working with recursive generic functions
We need this first because of the need to control maximum number of nested miniscript code and than because of the rust compiler limitations in working with recursive generic functions
d
&mut impl io::Read
depth
u8
d
&mut impl io::Read
depth
u8