use anchor_lang::{prelude::*, solana_program::{native_token::LAMPORTS_PER_SOL, system_instruction}}; use anchor_spl::{ associated_token::AssociatedToken,token_interface::{transfer_checked, Mint, TokenAccount, TokenInterface, TransferChecked} }; use crate::{DataRegistry, DATA_REGISTRY_SEED}; pub fn pay_seller(ctx:&Context, amount:u64)->Result<()>{ let from_account = &ctx.accounts.buyer; let to_account = &ctx.accounts.author; let transfer_instruction = system_instruction::transfer( from_account.key, to_account.key, amount); anchor_lang::solana_program::program::invoke_signed( &transfer_instruction, &[ from_account.to_account_info(), to_account.to_account_info(), ctx.accounts.system_program.to_account_info(), ], &[], )?; Ok(()) } pub fn handover_tickets(ctx:Context, amount:u64)->Result<()>{ let accounts = TransferChecked { from: ctx.accounts.vault.to_account_info(), to: ctx.accounts.buyer_token_account.to_account_info(), authority: ctx.accounts.data_registry.to_account_info(), mint: ctx.accounts.mint.to_account_info() }; let bump = ctx.bumps.data_registry; let seeds = &[ &DATA_REGISTRY_SEED[..], &[bump] ]; let signer_seeds = &[&seeds[..]]; let ctx = CpiContext::new_with_signer( ctx.accounts.token_program.to_account_info(), accounts, signer_seeds ); transfer_checked(ctx, amount *LAMPORTS_PER_SOL, 9) } #[derive(Accounts)] pub struct PurchaseTickets<'info>{ #[account(mut)] pub buyer:Signer<'info>, #[account(mint::token_program = token_program)] pub mint: InterfaceAccount<'info, Mint>, #[account( mut, address = data_registry.authority )] pub author: SystemAccount<'info>, #[account( init_if_needed, payer= buyer, associated_token::mint = mint, associated_token::authority = buyer, associated_token::token_program = token_program )] pub buyer_token_account: Box>, #[account( mut, seeds = [DATA_REGISTRY_SEED], bump )] pub data_registry: Account<'info, DataRegistry>, #[account( mut, associated_token::mint= mint, associated_token::authority = data_registry, associated_token::token_program = token_program )] vault: InterfaceAccount<'info, TokenAccount>, pub system_program: Program<'info, System>, pub token_program: Interface<'info, TokenInterface>, pub associated_token_program: Program<'info, AssociatedToken> }