pub fn ft_on_transfer(
        &mut self,
        sender_id: AccountId,
        amount: U128,
        msg: String,
    ) -> PromiseOrValue<U128> {
        let deposit_purpose: DepositPurpose = match serde_json::from_str(msg.as_str()) {
            Ok(purpose) => purpose,
            Err(_) => {
                log!(
                    "Invalid msg '{}' attached in `ft_transfer_call`. Return deposit.",
                    msg
                );
                return PromiseOrValue::Value(amount);
            }
        };
        match deposit_purpose {
            DepositPurpose::DepositTradeOutToken => {
                assert!(
                    env::predecessor_account_id().eq(&self.trade_out_token_contract),
                    "Invalid deposit account for trade out token. Return deposit."
                );
                self.trade_out_token_deposit += amount.0;
                log!(
                    "Received trade out token deposit {} from '@{}'.",
                    amount.0,
                    &sender_id,
                );
            }
            DepositPurpose::ConvertToTradeOutToken => {
                assert!(
                    env::predecessor_account_id().eq(&self.trade_in_token_contract),
                    "Invalid deposit account for trade in token. Return deposit."
                );
                let send_out_amount = match amount.0.checked_mul(self.exchange_rate.into()) {
                    Some(amount) => amount / 100,
                    None => {
                        log!("Send out amount overflow. Return deposit.");
                        return PromiseOrValue::Value(amount);
                    }
                };
                assert!(send_out_amount > 0, "Send out amount is too small.");
                assert!(
                    send_out_amount <= self.trade_out_token_deposit,
                    "Send out amount is too big."
                );
                self.trade_out_token_deposit -= send_out_amount;
                ext_fungible_token::ft_transfer(
                    sender_id.clone(),
                    U128::from(send_out_amount),
                    None,
                    &self.trade_out_token_contract,
                    1,
                    GAS_FOR_FT_TRANSFER,
                );
                log!(
                    "Tokens are converted for holder '@{}'. Received token amount: {} -> Send out token amount: {}",
                    &sender_id,
                    amount.0,
                    send_out_amount,
                );
            }
        }
        PromiseOrValue::Value(0.into())
    }
/// Callback function for `ft_transfer_call` of NEP-141 compatible contracts
Callback function for `ft_transfer_call` of NEP-141 compatible contracts
Callback function for ` ft_transfer_call ` of NEP - 141 compatible contracts
pub fn ft_on_transfer(
        &mut self,
        sender_id: AccountId,
        amount: U128,
        msg: String,
    ) -> PromiseOrValue<U128> {
        let deposit_purpose: DepositPurpose = match serde_json::from_str(msg.as_str()) {
            Ok(purpose) => purpose,
            Err(_) => {
                log!(
                    "Invalid msg '{}' attached in `ft_transfer_call`. Return deposit.",
                    msg
                );
                return PromiseOrValue::Value(amount);
            }
        };
        match deposit_purpose {
            DepositPurpose::DepositTradeOutToken => {
                assert!(
                    env::predecessor_account_id().eq(&self.trade_out_token_contract),
                    "Invalid deposit account for trade out token. Return deposit."
                );
                self.trade_out_token_deposit += amount.0;
                log!(
                    "Received trade out token deposit {} from '@{}'.",
                    amount.0,
                    &sender_id,
                );
            }
            DepositPurpose::ConvertToTradeOutToken => {
                assert!(
                    env::predecessor_account_id().eq(&self.trade_in_token_contract),
                    "Invalid deposit account for trade in token. Return deposit."
                );
                let send_out_amount = match amount.0.checked_mul(self.exchange_rate.into()) {
                    Some(amount) => amount / 100,
                    None => {
                        log!("Send out amount overflow. Return deposit.");
                        return PromiseOrValue::Value(amount);
                    }
                };
                assert!(send_out_amount > 0, "Send out amount is too small.");
                assert!(
                    send_out_amount <= self.trade_out_token_deposit,
                    "Send out amount is too big."
                );
                self.trade_out_token_deposit -= send_out_amount;
                ext_fungible_token::ft_transfer(
                    sender_id.clone(),
                    U128::from(send_out_amount),
                    None,
                    &self.trade_out_token_contract,
                    1,
                    GAS_FOR_FT_TRANSFER,
                );
                log!(
                    "Tokens are converted for holder '@{}'. Received token amount: {} -> Send out token amount: {}",
                    &sender_id,
                    amount.0,
                    send_out_amount,
                );
            }
        }
        PromiseOrValue::Value(0.into())
    }
pub fn ft_on_transfer ( & mut self , sender_id : AccountId , amount : U128 , msg : String , ) -> PromiseOrValue < U128 > { let deposit_purpose : DepositPurpose = match serde_json :: from_str ( msg . as_str ( ) ) { Ok ( purpose ) => purpose , Err ( _ ) => { log ! ( " " msg ) ; return PromiseOrValue :: Value ( amount ) ; } } ; match deposit_purpose { DepositPurpose :: DepositTradeOutToken => { assert ! ( env predecessor_account_id ( ) eq ( self trade_out_token_contract ) " " ) ; self . trade_out_token_deposit += amount . 0 ; log ! ( " " amount 0 sender_id ) ; } DepositPurpose :: ConvertToTradeOutToken => { assert ! ( env predecessor_account_id ( ) eq ( self trade_in_token_contract ) " " ) ; let send_out_amount = match amount . 0 . checked_mul ( self . exchange_rate . into ( ) ) { Some ( amount ) => amount / 100 , None => { log ! ( " " ) ; return PromiseOrValue :: Value ( amount ) ; } } ; assert ! ( send_out_amount 0 " " ) ; assert ! ( send_out_amount self trade_out_token_deposit " " ) ; self . trade_out_token_deposit -= send_out_amount ; ext_fungible_token :: ft_transfer ( sender_id . clone ( ) , U128 :: from ( send_out_amount ) , None , & self . trade_out_token_contract , 1 , GAS_FOR_FT_TRANSFER , ) ; log ! ( " " sender_id amount 0 send_out_amount ) ; } } PromiseOrValue :: Value ( 0 . into ( ) ) }
Callback function for `ft_transfer_call` of NEP-141 compatible contracts
Callback function for ` ft_transfer_call ` of NEP - 141 compatible contracts
&mut self
sender_id
AccountId
amount
U128
msg
String
&mut self
sender_id
AccountId
amount
U128
msg
String