fn ft_on_transfer(
        &mut self,
        sender_id: ValidAccountId,
        amount: U128,
        msg: String,
    ) -> PromiseOrValue<U128> {

        let sender: AccountId = sender_id.into();
        let amount: u128 = amount.into();
        if msg.is_empty() {
            // ****** seed Token deposit in ********

            // if seed not exist, it will panic
            let seed_farm = self.get_seed(&env::predecessor_account_id());
            if amount < seed_farm.get_ref().min_deposit {
                env::panic(
                    format!(
                        "{} {}", 
                        ERR34_BELOW_MIN_SEED_DEPOSITED, 
                        seed_farm.get_ref().min_deposit
                    )
                    .as_bytes()
                )
            }

            self.internal_seed_deposit(
                &env::predecessor_account_id(), 
                &sender, 
                amount.into(), 
                SeedType::FT
            );
            
            self.assert_storage_usage(&sender);

            env::log(
                format!(
                    "{} deposit FT seed {} with amount {}.",
                    sender, env::predecessor_account_id(), amount,
                )
                .as_bytes(),
            );
            PromiseOrValue::Value(U128(0))

        } else {  
            // ****** reward Token deposit in ********
            let farm_id = msg.parse::<FarmId>().expect(&format!("{}", ERR42_INVALID_FARM_ID));
            let mut farm = self.data().farms.get(&farm_id).expect(ERR41_FARM_NOT_EXIST);

            // update farm
            assert_eq!(farm.get_reward_token(), env::predecessor_account_id(), "{}", ERR44_INVALID_FARM_REWARD);
            if let Some(cur_remain) = farm.add_reward(&amount) {
                self.data_mut().farms.insert(&farm_id, &farm);
                let old_balance = self.data().reward_info.get(&env::predecessor_account_id()).unwrap_or(0);
                self.data_mut().reward_info.insert(&env::predecessor_account_id(), &(old_balance + amount));
                
                env::log(
                    format!(
                        "{} added {} Reward Token, Now has {} left",
                        sender, amount, cur_remain
                    )
                    .as_bytes(),
                );
                PromiseOrValue::Value(U128(0))
            } else {
                env::panic(format!("{}", ERR43_INVALID_FARM_STATUS).as_bytes())
            }
        }
        
    }
/// Callback on receiving tokens by this contract.
/// transfer reward token with specific msg indicate 
/// which farm to be deposited to.
Callback on receiving tokens by this contract.
transfer reward token with specific msg indicate
which farm to be deposited to.
Callback on receiving tokens by this contract . transfer reward token with specific msg indicate which farm to be deposited to .
fn ft_on_transfer(
        &mut self,
        sender_id: ValidAccountId,
        amount: U128,
        msg: String,
    ) -> PromiseOrValue<U128> {
        let sender: AccountId = sender_id.into();
        let amount: u128 = amount.into();
        if msg.is_empty() {
            // ****** seed Token deposit in ********
            // if seed not exist, it will panic
            let seed_farm = self.get_seed(&env::predecessor_account_id());
            if amount < seed_farm.get_ref().min_deposit {
                env::panic(
                    format!(
                        "{} {}", 
                        ERR34_BELOW_MIN_SEED_DEPOSITED, 
                        seed_farm.get_ref().min_deposit
                    )
                    .as_bytes()
                )
            }
            self.internal_seed_deposit(
                &env::predecessor_account_id(), 
                &sender, 
                amount.into(), 
                SeedType::FT
            );
            self.assert_storage_usage(&sender);
            env::log(
                format!(
                    "{} deposit FT seed {} with amount {}.",
                    sender, env::predecessor_account_id(), amount,
                )
                .as_bytes(),
            );
            PromiseOrValue::Value(U128(0))
        } else {  
            // ****** reward Token deposit in ********
            let farm_id = msg.parse::<FarmId>().expect(&format!("{}", ERR42_INVALID_FARM_ID));
            let mut farm = self.data().farms.get(&farm_id).expect(ERR41_FARM_NOT_EXIST);
            // update farm
            assert_eq!(farm.get_reward_token(), env::predecessor_account_id(), "{}", ERR44_INVALID_FARM_REWARD);
            if let Some(cur_remain) = farm.add_reward(&amount) {
                self.data_mut().farms.insert(&farm_id, &farm);
                let old_balance = self.data().reward_info.get(&env::predecessor_account_id()).unwrap_or(0);
                self.data_mut().reward_info.insert(&env::predecessor_account_id(), &(old_balance + amount));
                env::log(
                    format!(
                        "{} added {} Reward Token, Now has {} left",
                        sender, amount, cur_remain
                    )
                    .as_bytes(),
                );
                PromiseOrValue::Value(U128(0))
            } else {
                env::panic(format!("{}", ERR43_INVALID_FARM_STATUS).as_bytes())
            }
        }
    }
fn ft_on_transfer ( & mut self , sender_id : ValidAccountId , amount : U128 , msg : String , ) -> PromiseOrValue < U128 > { let sender : AccountId = sender_id . into ( ) ; let amount : u128 = amount . into ( ) ; if msg . is_empty ( ) { // ****** seed Token deposit in ******** // if seed not exist, it will panic let seed_farm = self . get_seed ( & env :: predecessor_account_id ( ) ) ; if amount < seed_farm . get_ref ( ) . min_deposit { env :: panic ( format ! ( " " ERR34_BELOW_MIN_SEED_DEPOSITED seed_farm get_ref ( ) min_deposit ) . as_bytes ( ) ) } self . internal_seed_deposit ( & env :: predecessor_account_id ( ) , & sender , amount . into ( ) , SeedType :: FT ) ; self . assert_storage_usage ( & sender ) ; env :: log ( format ! ( " " sender env predecessor_account_id ( ) amount ) . as_bytes ( ) , ) ; PromiseOrValue :: Value ( U128 ( 0 ) ) } else { // ****** reward Token deposit in ******** let farm_id = msg . parse :: < FarmId > ( ) . expect ( & format ! ( " " ERR42_INVALID_FARM_ID ) ) ; let mut farm = self . data ( ) . farms . get ( & farm_id ) . expect ( ERR41_FARM_NOT_EXIST ) ; // update farm assert_eq ! ( farm get_reward_token ( ) env predecessor_account_id ( ) " " ERR44_INVALID_FARM_REWARD ) ; if let Some ( cur_remain ) = farm . add_reward ( & amount ) { self . data_mut ( ) . farms . insert ( & farm_id , & farm ) ; let old_balance = self . data ( ) . reward_info . get ( & env :: predecessor_account_id ( ) ) . unwrap_or ( 0 ) ; self . data_mut ( ) . reward_info . insert ( & env :: predecessor_account_id ( ) , & ( old_balance + amount ) ) ; env :: log ( format ! ( " " sender amount cur_remain ) . as_bytes ( ) , ) ; PromiseOrValue :: Value ( U128 ( 0 ) ) } else { env :: panic ( format ! ( " " ERR43_INVALID_FARM_STATUS ) . as_bytes ( ) ) } } }
Callback on receiving tokens by this contract.
Callback on receiving tokens by this contract .
&mut self
sender_id
ValidAccountId
amount
U128
msg
String
&mut self
sender_id
ValidAccountId
amount
U128
msg
String