fn process_instruction(
    _program_id: &Pubkey,
    accounts: &[AccountInfo],
    _input: &[u8],
) -> ProgramResult {
    let account_info_iter = &mut accounts.iter();
    let mint_info = next_account_info(account_info_iter)?;
    let token_program = next_account_info(account_info_iter)?;
    // 10 tokens, with 9 decimal places
    let test_amount = 10_000_000_000;
    // "10" as an amount should be smaller than test_amount due to interest
    invoke(
        &ui_amount_to_amount(token_program.key, mint_info.key, "10")?,
        &[mint_info.clone(), token_program.clone()],
    )?;
    let (_, return_data) = get_return_data().unwrap();
    let amount = u64::from_le_bytes(return_data[0..8].try_into().unwrap());
    msg!("amount: {}", amount);
    if amount >= test_amount {
        return Err(ProgramError::InvalidInstructionData);
    }

    // test_amount as a UI amount should be larger due to interest
    invoke(
        &amount_to_ui_amount(token_program.key, mint_info.key, test_amount)?,
        &[mint_info.clone(), token_program.clone()],
    )?;
    let (_, return_data) = get_return_data().unwrap();
    let ui_amount = String::from_utf8(return_data).unwrap();
    msg!("ui amount: {}", ui_amount);
    let float_ui_amount = ui_amount.parse::<f64>().unwrap();
    if float_ui_amount <= 10.0 {
        return Err(ProgramError::InvalidInstructionData);
    }
    Ok(())
}
// test program to CPI into token to get ui amounts
test program to CPI into token to get ui amounts
test program to CPI into token to get ui amounts
fn process_instruction(
    _program_id: &Pubkey,
    accounts: &[AccountInfo],
    _input: &[u8],
) -> ProgramResult {
    let account_info_iter = &mut accounts.iter();
    let mint_info = next_account_info(account_info_iter)?;
    let token_program = next_account_info(account_info_iter)?;
    // 10 tokens, with 9 decimal places
    let test_amount = 10_000_000_000;
    // "10" as an amount should be smaller than test_amount due to interest
    invoke(
        &ui_amount_to_amount(token_program.key, mint_info.key, "10")?,
        &[mint_info.clone(), token_program.clone()],
    )?;
    let (_, return_data) = get_return_data().unwrap();
    let amount = u64::from_le_bytes(return_data[0..8].try_into().unwrap());
    msg!("amount: {}", amount);
    if amount >= test_amount {
        return Err(ProgramError::InvalidInstructionData);
    }
    // test_amount as a UI amount should be larger due to interest
    invoke(
        &amount_to_ui_amount(token_program.key, mint_info.key, test_amount)?,
        &[mint_info.clone(), token_program.clone()],
    )?;
    let (_, return_data) = get_return_data().unwrap();
    let ui_amount = String::from_utf8(return_data).unwrap();
    msg!("ui amount: {}", ui_amount);
    let float_ui_amount = ui_amount.parse::<f64>().unwrap();
    if float_ui_amount <= 10.0 {
        return Err(ProgramError::InvalidInstructionData);
    }
    Ok(())
}
fn process_instruction ( _program_id : & Pubkey , accounts : & [ AccountInfo ] , _input : & [ u8 ] , ) -> ProgramResult { let account_info_iter = & mut accounts . iter ( ) ; let mint_info = next_account_info ( account_info_iter ) ? ; let token_program = next_account_info ( account_info_iter ) ? ; // 10 tokens, with 9 decimal places let test_amount = 10_000_000_000 ; // "10" as an amount should be smaller than test_amount due to interest invoke ( & ui_amount_to_amount ( token_program . key , mint_info . key , " " ) ? , & [ mint_info . clone ( ) , token_program . clone ( ) ] , ) ? ; let ( _ , return_data ) = get_return_data ( ) . unwrap ( ) ; let amount = u64 :: from_le_bytes ( return_data [ 0 .. 8 ] . try_into ( ) . unwrap ( ) ) ; msg ! ( " " amount ) ; if amount >= test_amount { return Err ( ProgramError :: InvalidInstructionData ) ; } // test_amount as a UI amount should be larger due to interest invoke ( & amount_to_ui_amount ( token_program . key , mint_info . key , test_amount ) ? , & [ mint_info . clone ( ) , token_program . clone ( ) ] , ) ? ; let ( _ , return_data ) = get_return_data ( ) . unwrap ( ) ; let ui_amount = String :: from_utf8 ( return_data ) . unwrap ( ) ; msg ! ( " " ui_amount ) ; let float_ui_amount = ui_amount . parse :: < f64 > ( ) . unwrap ( ) ; if float_ui_amount <= 10.0 { return Err ( ProgramError :: InvalidInstructionData ) ; } Ok ( ( ) ) }
test program to CPI into token to get ui amounts
test program to CPI into token to get ui amounts
_program_id
&Pubkey
accounts
&[AccountInfo]
_input
&[u8]
_program_id
&Pubkey
accounts
&[AccountInfo]
_input
&[u8]