transfer_sol_with_program.rs 660 B

1234567891011121314151617181920
  1. use solana_program::{account_info::AccountInfo, entrypoint::ProgramResult};
  2. use steel::*;
  3. use transfer_sol_api::prelude::*;
  4. pub fn process_transfer_sol_with_program(accounts: &[AccountInfo], data: &[u8]) -> ProgramResult {
  5. // Parse args.
  6. let args = TransferSolWithProgram::try_from_bytes(data)?;
  7. let amount: u64 = u64::from_le_bytes(args.amount);
  8. // Load accounts.
  9. let [signer_info, receiver_info] = accounts else {
  10. return Err(ProgramError::NotEnoughAccountKeys);
  11. };
  12. signer_info.is_signer()?;
  13. **signer_info.try_borrow_mut_lamports()? -= amount;
  14. **receiver_info.try_borrow_mut_lamports()? += amount;
  15. Ok(())
  16. }