use light_client::rpc::{Rpc, RpcError};
use light_token::instruction::TransferChecked as TransferCheckedInstruction;
use solana_keypair::Keypair;
use solana_pubkey::Pubkey;
use solana_signature::Signature;
use solana_signer::Signer;
#[derive(Default, Clone, Debug)]
pub struct TransferChecked {
pub source: Pubkey,
pub mint: Pubkey,
pub destination: Pubkey,
pub amount: u64,
pub decimals: u8,
}
impl TransferChecked {
pub async fn execute<R: Rpc>(
self,
rpc: &mut R,
payer: &Keypair,
authority: &Keypair,
) -> Result<Signature, RpcError> {
let ix = TransferCheckedInstruction {
source: self.source,
mint: self.mint,
destination: self.destination,
amount: self.amount,
decimals: self.decimals,
authority: authority.pubkey(),
fee_payer: payer.pubkey(),
}
.instruction()
.map_err(|e| RpcError::CustomError(format!("Failed to create instruction: {}", e)))?;
let mut signers = vec![payer];
if authority.pubkey() != payer.pubkey() {
signers.push(authority);
}
rpc.create_and_send_transaction(&[ix], &payer.pubkey(), &signers)
.await
}
}