pub fn merchant_close<E: Engine>(channel_state: &ChannelState<E>,
                                     channel_token: &ChannelToken<E>,
                                     cust_close: &ChannelcloseC<E>,
                                     merch_state: &MerchantState<E>) -> BoltResult<PubKeyMap> {
        if (!channel_state.channel_established) {
            return Err(String::from("merchant_close - Channel not established! Cannot generate channel closure message."));
        }

        let cp = channel_state.cp.as_ref().unwrap();
        let pk = cp.pub_params.pk.get_pub_key();
        let mut wallet = cust_close.message.clone();
        let close_wallet = wallet.with_close(String::from("close")).clone();
        let close_token = cust_close.signature.clone();

        let is_valid = pk.verify(&channel_token.mpk, &close_wallet, &close_token);

        if is_valid {
            let wpk = cust_close.wpk;
            // found the wpk, which means old close token
            let fingerprint = util::compute_pub_key_fingerprint(&wpk);
            if merch_state.keys.contains_key(&fingerprint) {
                let revoked_state = merch_state.keys.get(&fingerprint).unwrap();
                if !revoked_state.revoke_token.is_none() {
                    let revoke_token = revoked_state.revoke_token.unwrap().clone();
                    // verify the revoked state first before returning
                    let secp = secp256k1::Secp256k1::new();
                    let revoke_msg = RevokedMessage::new(String::from("revoked"), wpk.clone());
                    let msg = secp256k1::Message::from_slice(&revoke_msg.hash_to_slice()).unwrap();
                    // verify that the revocation token is valid
                    if secp.verify(&msg, &revoke_token, &wpk).is_ok() {
                        // compute signature on
                        return Ok(Some(revoked_state.clone()));
                    }
                }
                return Err(String::from("merchant_close - Found wpk but could not find the revoke token. Merchant abort detected."));
            }
            return Err(String::from("merchant_close - Could not find entry for wpk & revoke token pair. Valid close!"));
        }
        Err(String::from("merchant_close - Customer close message not valid!"))
    }
///
/// merchant_close - takes as input the channel state, channel token, customer close msg/sig,
/// Returns tokens for merchant close transaction (only if customer close message is found to be a
/// double spend). If not, then None is returned.
///
takes as input the channel state, channel token, customer close msg/sig,
Returns tokens for merchant close transaction (only if customer close message is found to be a
double spend). If not, then None is returned.
takes as input the channel state channel token customer close msg / sig Returns tokens for merchant close transaction ( only if customer close message is found to be a double spend ) . If not then None is returned .
pub fn merchant_close<E: Engine>(channel_state: &ChannelState<E>,
                                     channel_token: &ChannelToken<E>,
                                     cust_close: &ChannelcloseC<E>,
                                     merch_state: &MerchantState<E>) -> BoltResult<PubKeyMap> {
        if (!channel_state.channel_established) {
            return Err(String::from("merchant_close - Channel not established! Cannot generate channel closure message."));
        }
        let cp = channel_state.cp.as_ref().unwrap();
        let pk = cp.pub_params.pk.get_pub_key();
        let mut wallet = cust_close.message.clone();
        let close_wallet = wallet.with_close(String::from("close")).clone();
        let close_token = cust_close.signature.clone();
        let is_valid = pk.verify(&channel_token.mpk, &close_wallet, &close_token);
        if is_valid {
            let wpk = cust_close.wpk;
            // found the wpk, which means old close token
            let fingerprint = util::compute_pub_key_fingerprint(&wpk);
            if merch_state.keys.contains_key(&fingerprint) {
                let revoked_state = merch_state.keys.get(&fingerprint).unwrap();
                if !revoked_state.revoke_token.is_none() {
                    let revoke_token = revoked_state.revoke_token.unwrap().clone();
                    // verify the revoked state first before returning
                    let secp = secp256k1::Secp256k1::new();
                    let revoke_msg = RevokedMessage::new(String::from("revoked"), wpk.clone());
                    let msg = secp256k1::Message::from_slice(&revoke_msg.hash_to_slice()).unwrap();
                    // verify that the revocation token is valid
                    if secp.verify(&msg, &revoke_token, &wpk).is_ok() {
                        // compute signature on
                        return Ok(Some(revoked_state.clone()));
                    }
                }
                return Err(String::from("merchant_close - Found wpk but could not find the revoke token. Merchant abort detected."));
            }
            return Err(String::from("merchant_close - Could not find entry for wpk & revoke token pair. Valid close!"));
        }
        Err(String::from("merchant_close - Customer close message not valid!"))
    }
pub fn merchant_close < E : Engine > ( channel_state : & ChannelState < E > , channel_token : & ChannelToken < E > , cust_close : & ChannelcloseC < E > , merch_state : & MerchantState < E > ) -> BoltResult < PubKeyMap > { if ( ! channel_state . channel_established ) { return Err ( String :: from ( " " ) ) ; } let cp = channel_state . cp . as_ref ( ) . unwrap ( ) ; let pk = cp . pub_params . pk . get_pub_key ( ) ; let mut wallet = cust_close . message . clone ( ) ; let close_wallet = wallet . with_close ( String :: from ( " " ) ) . clone ( ) ; let close_token = cust_close . signature . clone ( ) ; let is_valid = pk . verify ( & channel_token . mpk , & close_wallet , & close_token ) ; if is_valid { let wpk = cust_close . wpk ; // found the wpk, which means old close token let fingerprint = util :: compute_pub_key_fingerprint ( & wpk ) ; if merch_state . keys . contains_key ( & fingerprint ) { let revoked_state = merch_state . keys . get ( & fingerprint ) . unwrap ( ) ; if ! revoked_state . revoke_token . is_none ( ) { let revoke_token = revoked_state . revoke_token . unwrap ( ) . clone ( ) ; // verify the revoked state first before returning let secp = secp256k1 :: Secp256k1 :: new ( ) ; let revoke_msg = RevokedMessage :: new ( String :: from ( " " ) , wpk . clone ( ) ) ; let msg = secp256k1 :: Message :: from_slice ( & revoke_msg . hash_to_slice ( ) ) . unwrap ( ) ; // verify that the revocation token is valid if secp . verify ( & msg , & revoke_token , & wpk ) . is_ok ( ) { // compute signature on return Ok ( Some ( revoked_state . clone ( ) ) ) ; } } return Err ( String :: from ( " " ) ) ; } return Err ( String :: from ( " " ) ) ; } Err ( String :: from ( " " ) ) }
merchant_close - takes as input the channel state, channel token, customer close msg/sig,
Returns tokens for merchant close transaction (only if customer close message is found to be a
double spend).
merchant_close - takes as input the channel state channel token customer close msg / sig Returns tokens for merchant close transaction ( only if customer close message is found to be a double spend ) .
channel_state
&ChannelState<E>
channel_token
&ChannelToken<E>
cust_close
&ChannelcloseC<E>
merch_state
&MerchantState<E>
channel_state
&ChannelState<E>
channel_token
&ChannelToken<E>
cust_close
&ChannelcloseC<E>
merch_state
&MerchantState<E>