Fixed warnings

This commit is contained in:
Sewmina Dilshan 2024-11-12 12:31:22 +05:30
parent 67e0c72c82
commit 98969ccb2e
10 changed files with 114 additions and 39 deletions

View File

@ -5,7 +5,7 @@ resolution = true
skip-lint = false
[programs.localnet]
tournaments = "3owEKMMjFuuYN2HjT2J2GiVauDivNBeYqaUymyX7Q8Lw"
tournaments = "F5ECXfrZwMyWv5WusMJD7bYSRjEEXYLLPy6TN3XqQBPA"
[registry]
url = "https://api.apr.dev"

View File

@ -7,5 +7,7 @@ pub enum CustomErrors {
#[msg("Insufficient funds to purchase a ticket, Recharge your wallet and try again")]
InsufficientFunds,
#[msg("Only the owner can perform this action")]
Unauthorized
Unauthorized,
#[msg("This tournament ID already exists, use a different one")]
ExistingTournament
}

View File

@ -1,16 +1,18 @@
use anchor_lang::prelude::*;
use anchor_spl::associated_token::spl_associated_token_account::instruction;
use crate::{error::CustomErrors, DataRegistry, Tournament, DATA_REGISTRY_SEED};
pub fn handler(ctx:Context<AddTournament>, id:u64, start_time:String)->Result<()>{
require!(ctx.accounts.payer.key() == ctx.accounts.data_registry.authority, CustomErrors::Unauthorized);
require!(!ctx.accounts.data_registry.tournament_ids.contains(&id), CustomErrors::ExistingTournament);
let tournamentAccount = &mut ctx.accounts.tournament_account;
let tournament_account = &mut ctx.accounts.tournament_account;
let data_reg = &mut ctx.accounts.data_registry;
tournament_account.id = id;
tournament_account.start_time = start_time;
tournamentAccount.id = id;
tournamentAccount.start_time = start_time;
data_reg.tournament_ids.push(id);
Ok(())
}

View File

@ -1,6 +1,6 @@
use anchor_lang::prelude::*;
use anchor_spl::{
associated_token::AssociatedToken, token_interface::{Mint, TokenAccount, TokenInterface, close_account, transfer_checked, CloseAccount, TransferChecked}
associated_token::AssociatedToken, token_interface::{Mint, TokenAccount, TokenInterface}
};
use crate::{ DataRegistry, DATA_REGISTRY_SEED};

View File

@ -1,35 +1,30 @@
use anchor_lang::prelude::*;
use anchor_lang::{prelude::*, solana_program::native_token::LAMPORTS_PER_SOL};
use crate::{DataRegistry,Tournament, DATA_REGISTRY_SEED};
use anchor_spl::{associated_token::AssociatedToken, token_interface::{transfer_checked, Mint, TokenAccount, TokenInterface, TransferChecked}};
// pub fn transfer_ticket_to_vault(ctx:&Context<JoinTorunament>, id:u64) -> Result<()>{
pub fn transfer_ticket_to_vault(ctx:&Context<JoinTorunament>, _id:u64) -> Result<()>{
let accounts = TransferChecked {
from: ctx.accounts.user_token_account.to_account_info(),
to: ctx.accounts.vault.to_account_info(),
authority: ctx.accounts.user.to_account_info(),
mint: ctx.accounts.mint.to_account_info()
};
// let seeds = &[
// b"sales",
// ctx.accounts.seller.to_account_info().key.as_ref(),
// &[ctx.accounts.sales.bump]
// ];
let seeds = &[];
// let signer_seeds = [&seeds[..]];
let signer_seeds = &[&seeds[..]];
// let accounts = TransferChecked{
// from: ctx.accounts.vault.to_account_info(),
// to: ctx.accounts.buyer_token_account.to_account_info(),
// mint: ctx.accounts.mint.to_account_info(),
// authority: ctx.accounts.sales.to_account_info()
// };
let ctx = CpiContext::new_with_signer(
ctx.accounts.token_program.to_account_info(),
accounts,
signer_seeds
);
// let cpi_context = CpiContext::new_with_signer(
// ctx.accounts.token_program.to_account_info(),
// accounts,
// &signer_seeds
// );
transfer_checked(ctx, 1 *LAMPORTS_PER_SOL, 9)
}
// transfer_checked(cpi_context, amount*LAMPORTS_PER_SOL, ctx.accounts.mint.decimals)
// }
pub fn add_to_participants_list(ctx:Context<JoinTorunament>, id:u64) -> Result<()>{
pub fn add_to_participants_list(ctx:Context<JoinTorunament>, _id:u64) -> Result<()>{
let tournament_account = &mut ctx.accounts.tournament_account;
tournament_account.participants.push(*ctx.accounts.user.key);
@ -42,6 +37,14 @@ pub struct JoinTorunament<'info>{
#[account(mut)]
pub user: Signer<'info>,
#[account(
mut,
associated_token::mint = mint,
associated_token::authority = user,
associated_token::token_program = token_program
)]
pub user_token_account: Box<InterfaceAccount<'info, TokenAccount>>,
#[account(
mut,
seeds = [b"Tournament", id.to_le_bytes().as_ref()],

View File

@ -4,9 +4,8 @@ use anchor_spl::{
associated_token::AssociatedToken,token_interface::{transfer_checked, Mint, TokenAccount, TokenInterface, TransferChecked}
};
use crate::{error::CustomErrors, DataRegistry, DATA_REGISTRY_SEED};
use crate::{DataRegistry, DATA_REGISTRY_SEED};
use super::transfer_tokens;
pub fn pay_seller(ctx:&Context<PurchaseTickets>, amount:u64)->Result<()>{
let from_account = &ctx.accounts.buyer;

View File

@ -1,5 +1,4 @@
use anchor_lang::prelude::*;
use anchor_spl:: token::{Mint, Token, TokenAccount};
use crate::{error::CustomErrors, DataRegistry, DATA_REGISTRY_SEED};

View File

@ -9,7 +9,7 @@ pub use constants::*;
pub use instructions::*;
pub use state::*;
declare_id!("3owEKMMjFuuYN2HjT2J2GiVauDivNBeYqaUymyX7Q8Lw");
declare_id!("F5ECXfrZwMyWv5WusMJD7bYSRjEEXYLLPy6TN3XqQBPA");
#[program]
pub mod tournaments {
use super::*;
@ -29,7 +29,7 @@ pub mod tournaments {
}
pub fn join_tournament(ctx:Context<JoinTorunament>, id:u64)-> Result<()>{
// join_tournament::transfer_ticket_to_vault(&ctx, id);
join_tournament::transfer_ticket_to_vault(&ctx, id)?;
join_tournament::add_to_participants_list(ctx, id)
}
}

View File

@ -1,8 +1,10 @@
use anchor_lang::{prelude::*, Bump};
use anchor_lang::prelude::*;
#[account]
#[derive(InitSpace)]
pub struct DataRegistry{
pub sales_pda: Pubkey,
pub authority: Pubkey
pub authority: Pubkey,
#[max_len(1000)]
pub tournament_ids: Vec<u64>
}

View File

@ -1,5 +1,5 @@
{
"address": "3owEKMMjFuuYN2HjT2J2GiVauDivNBeYqaUymyX7Q8Lw",
"address": "F5ECXfrZwMyWv5WusMJD7bYSRjEEXYLLPy6TN3XqQBPA",
"metadata": {
"name": "tournaments",
"version": "0.1.0",
@ -222,6 +222,63 @@
"writable": true,
"signer": true
},
{
"name": "user_token_account",
"writable": true,
"pda": {
"seeds": [
{
"kind": "account",
"path": "user"
},
{
"kind": "account",
"path": "token_program"
},
{
"kind": "account",
"path": "mint"
}
],
"program": {
"kind": "const",
"value": [
140,
151,
37,
143,
78,
36,
137,
241,
187,
61,
16,
41,
20,
142,
13,
131,
11,
90,
19,
153,
218,
255,
16,
132,
4,
142,
123,
216,
219,
233,
248,
89
]
}
}
},
{
"name": "tournament_account",
"writable": true,
@ -574,6 +631,11 @@
"code": 6002,
"name": "Unauthorized",
"msg": "Only the owner can perform this action"
},
{
"code": 6003,
"name": "ExistingTournament",
"msg": "This tournament ID already exists, use a different one"
}
],
"types": [
@ -589,6 +651,12 @@
{
"name": "authority",
"type": "pubkey"
},
{
"name": "tournament_ids",
"type": {
"vec": "u64"
}
}
]
}