init purchase sep

This commit is contained in:
2024-10-26 21:43:04 +05:30
parent ff1856c5bd
commit 4e17f2f443
10 changed files with 123 additions and 28 deletions

View File

@@ -1,4 +1,7 @@
use anchor_lang::prelude::*;
#[constant]
pub const ID: &str = "";
pub const ID: &str = "";
#[constant]
pub const SELLERS_REGISTRY_SEED:&[u8; 9] = b"sales_reg";

View File

@@ -0,0 +1,55 @@
use anchor_lang::prelude::*;
use anchor_spl:: token::{Mint, Token, TokenAccount};
use crate::{Sales, SellersRegistry, SELLERS_REGISTRY_SEED};
#[derive(Accounts)]
pub struct AddSeller <'info>{
#[account(mut)]
pub signer: Signer<'info>,
#[account(
init,
payer = signer,
space = 8 + Sales::INIT_SPACE,
seeds= [b"sales", signer.key().as_ref()],
bump
)]
pub sales_account: Account<'info, Sales>,
#[account(
init,
payer = signer,
seeds = [b"ticket_seller".as_ref(), signer.key().as_ref(), mint.key().as_ref()],
bump,
token::mint = mint,
token::authority = sales_account,
)]
pub signer_token_account: Account<'info, TokenAccount>,
#[account(
mut,
seeds=[SELLERS_REGISTRY_SEED],
bump
)]
pub sellers_registry: Account<'info, SellersRegistry>,
pub mint: Account<'info, Mint>,
pub system_program: Program<'info, System>,
pub token_program: Program<'info, Token>,
}
pub fn handler(ctx: Context<AddSeller>) -> Result<()> {
let sales_account = &mut ctx.accounts.sales_account;
sales_account.owner = ctx.accounts.signer.key();
sales_account.seller_ata = ctx.accounts.signer_token_account.key();
ctx.accounts.sellers_registry.sales_pdas.push(sales_account.key());
Ok(())
}

View File

@@ -2,7 +2,7 @@ use anchor_lang::prelude::*;
use anchor_spl:: token::{Mint, Token, TokenAccount};
use crate::Sales;
use crate::{Sales, SellersRegistry, SELLERS_REGISTRY_SEED};
#[derive(Accounts)]
pub struct Initialize <'info>{
@@ -11,36 +11,18 @@ pub struct Initialize <'info>{
#[account(
init,
payer = signer,
space = 8 + Sales::INIT_SPACE,
seeds= [b"sales", signer.key().as_ref()],
payer=signer,
space= 8 + SellersRegistry::INIT_SPACE,
seeds = [SELLERS_REGISTRY_SEED],
bump
)]
pub sales_account: Account<'info, Sales>,
#[account(
init,
payer = signer,
seeds = [b"ticket_seller".as_ref(), signer.key().as_ref(), mint.key().as_ref()],
bump,
token::mint = mint,
token::authority = sales_account,
)]
pub signer_token_account: Account<'info, TokenAccount>,
pub mint: Account<'info, Mint>,
pub sellers_registry: Account<'info, SellersRegistry>,
pub system_program: Program<'info, System>,
pub token_program: Program<'info, Token>,
}
pub fn handler(ctx: Context<Initialize>) -> Result<()> {
let sales_account = &mut ctx.accounts.sales_account;
sales_account.owner = ctx.accounts.signer.key();
sales_account.seller_ata = ctx.accounts.signer_token_account.key();
msg!("Initiating Ticket store");
Ok(())
}

View File

@@ -1,5 +1,8 @@
pub mod initialize;
pub use initialize::*;
pub mod add_seller;
pub use add_seller::*;
pub mod purchase;
pub use purchase::*;

View File

@@ -9,7 +9,7 @@ pub use constants::*;
pub use instructions::*;
pub use state::*;
declare_id!("8w2kJrGZyPrhd2cN68x16wwjwaAmngZZcgudDz2k9C9Z");
declare_id!("5kgwVNdKDndFYNkUhZ5TvkNXxEJngMSczfS61qNALhzJ");
#[program]
pub mod ticket_store {
@@ -19,6 +19,10 @@ pub mod ticket_store {
initialize::handler(ctx)
}
pub fn add_seller(ctx: Context<AddSeller>) -> Result<()> {
add_seller::handler(ctx)
}
pub fn purchase_tickets(ctx:Context<PurchaseTickets>, amount:u64)->Result<()>{
purchase::purchase_ticket(ctx, amount)
}

View File

@@ -1,2 +1,5 @@
pub mod sales;
pub use sales::Sales;
pub use sales::Sales;
pub mod sellers_registry;
pub use sellers_registry::SellersRegistry;

View File

@@ -0,0 +1,8 @@
use anchor_lang::prelude::*;
#[account]
#[derive(InitSpace)]
pub struct SellersRegistry{
#[max_len(100)]
pub sales_pdas: Vec<Pubkey>
}