/// Helper function to evaluate a Pkh Node. Takes input as pubkey and sig
/// from the top of the stack and outputs Sat if the pubkey, sig is valid
/// Sat: If the pubkey hash matches and signature witness is correct,
/// Unsat: For an empty witness
/// Err: All of other witness result in errors.
/// `DUP HASH160 <keyhash> EQUALVERIY CHECKSIG`
Helper function to evaluate a Pkh Node. Takes input as pubkey and sig
from the top of the stack and outputs Sat if the pubkey, sig is valid
Sat: If the pubkey hash matches and signature witness is correct,
Unsat: For an empty witness
Err: All of other witness result in errors.
`DUP HASH160  EQUALVERIY CHECKSIG`
Helper function to evaluate a Pkh Node . Takes input as pubkey and sig from the top of the stack and outputs Sat if the pubkey sig is valid Sat : If the pubkey hash matches and signature witness is correct Unsat : For an empty witness Err : All of other witness result in errors . ` DUP HASH160 EQUALVERIY CHECKSIG `
pub fn evaluate_pkh<'intp, F>(
        &mut self,
        verify_sig: F,
        pkh: &'intp hash160::Hash,
    ) -> Option<Result<SatisfiedConstraint<'intp, 'txin>, Error>>
    where
        F: FnOnce(&bitcoin::PublicKey, ElementsSig) -> bool,
    {
        if let Some(Element::Push(pk)) = self.pop() {
            let pk_hash = hash160::Hash::hash(pk);
            if pk_hash != *pkh {
                return Some(Err(Error::PkHashVerifyFail(*pkh)));
            }
            match bitcoin::PublicKey::from_slice(pk) {
                Ok(pk) => {
                    if let Some(sigser) = self.pop() {
                        match sigser {
                            Element::Dissatisfied => {
                                self.push(Element::Dissatisfied);
                                None
                            }
                            Element::Push(sigser) => {
                                let sig = verify_sersig(verify_sig, &pk, sigser);
                                match sig {
                                    Ok(sig) => {
                                        self.push(Element::Satisfied);
                                        Some(Ok(SatisfiedConstraint::PublicKeyHash {
                                            keyhash: pkh,
                                            key: pk,
                                            sig,
                                        }))
                                    }
                                    Err(e) => return Some(Err(e)),
                                }
                            }
                            Element::Satisfied => {
                                return Some(Err(Error::PkEvaluationError(
                                    pk.clone().to_public_key(),
                                )))
                            }
                        }
                    } else {
                        Some(Err(Error::UnexpectedStackEnd))
                    }
                }
                Err(..) => Some(Err(Error::PubkeyParseError)),
            }
        } else {
            Some(Err(Error::UnexpectedStackEnd))
        }
    }
pub fn evaluate_pkh < ' intp , F > ( & mut self , verify_sig : F , pkh : & ' intp hash160 :: Hash , ) -> Option < Result < SatisfiedConstraint < ' intp , ' txin > , Error > > where F : FnOnce ( & bitcoin :: PublicKey , ElementsSig ) -> bool , { if let Some ( Element :: Push ( pk ) ) = self . pop ( ) { let pk_hash = hash160 :: Hash :: hash ( pk ) ; if pk_hash != * pkh { return Some ( Err ( Error :: PkHashVerifyFail ( * pkh ) ) ) ; } match bitcoin :: PublicKey :: from_slice ( pk ) { Ok ( pk ) => { if let Some ( sigser ) = self . pop ( ) { match sigser { Element :: Dissatisfied => { self . push ( Element :: Dissatisfied ) ; None } Element :: Push ( sigser ) => { let sig = verify_sersig ( verify_sig , & pk , sigser ) ; match sig { Ok ( sig ) => { self . push ( Element :: Satisfied ) ; Some ( Ok ( SatisfiedConstraint :: PublicKeyHash { keyhash : pkh , key : pk , sig , } ) ) } Err ( e ) => return Some ( Err ( e ) ) , } } Element :: Satisfied => { return Some ( Err ( Error :: PkEvaluationError ( pk . clone ( ) . to_public_key ( ) , ) ) ) } } } else { Some ( Err ( Error :: UnexpectedStackEnd ) ) } } Err ( .. ) => Some ( Err ( Error :: PubkeyParseError ) ) , } } else { Some ( Err ( Error :: UnexpectedStackEnd ) ) } }
Helper function to evaluate a Pkh Node.
Helper function to evaluate a Pkh Node .
&mut self
verify_sig
F
pkh
&'intp hash160::Hash