diff --git a/programs/splitwave/src/instructions/create_splitwave.rs b/programs/splitwave/src/instructions/create_splitwave.rs index 02575cf..0b6afe4 100644 --- a/programs/splitwave/src/instructions/create_splitwave.rs +++ b/programs/splitwave/src/instructions/create_splitwave.rs @@ -41,8 +41,9 @@ pub struct CreateSplitwave<'info> { init, payer = authority, seeds = [ - SEED_SPLITWAVE, - splitwave_id.splitwave_id.to_le_bytes().as_ref(), + SEED_SPLITWAVE, + splitwave_id.key().as_ref(), + splitwave_id.next_id.to_le_bytes().as_ref(), ], bump, space = 8 + SIZE_OF_SPLITWAVE + SIZE_OF_PARTSPLIT * participants.len(), @@ -61,7 +62,7 @@ pub struct CreateSplitwave<'info> { /// splitwave_id instance /// constant address but the splitwave_id increments sequentially - #[account(mut, seeds = [SEED_SPLITWAVE_ID],bump = splitwave_id.bump)] + #[account(mut)] pub splitwave_id: Box>, pub rent: Sysvar<'info, Rent>, @@ -199,7 +200,8 @@ pub fn handler( let bump = *ctx.bumps.get("splitwave").unwrap(); splitwave.bump = bump; - splitwave.splitwave_id = splitwave_id.splitwave_id; + splitwave.splitwave_id = splitwave_id.next_id; + splitwave.splitwave_id_key = splitwave_id.key(); splitwave.total_amount_to_recipient = total_amount_to_recipient; splitwave.amount_paid_to_splitwave_account = 0; splitwave.total_participants = total_participants as u64; @@ -214,7 +216,7 @@ pub fn handler( splitwave.participants = participants; msg!("Splitwave account initialized"); - splitwave_id.splitwave_id += 1; + splitwave_id.next_id += 1; msg!("Splitwave id incremented"); Ok(()) diff --git a/programs/splitwave/src/instructions/create_splitwave_id.rs b/programs/splitwave/src/instructions/create_splitwave_id.rs index dc8db0a..eb706c6 100644 --- a/programs/splitwave/src/instructions/create_splitwave_id.rs +++ b/programs/splitwave/src/instructions/create_splitwave_id.rs @@ -2,7 +2,6 @@ use { anchor_lang::prelude::*, crate::state::{ SIZE_OF_SPLITWAVE_ID, - SEED_SPLITWAVE_ID, SplitwaveId } }; @@ -12,9 +11,7 @@ pub struct CreateSplitwaveId<'info> { #[account( init, payer = payer, - space = 8 + SIZE_OF_SPLITWAVE_ID, - seeds = [SEED_SPLITWAVE_ID], - bump + space = 8 + SIZE_OF_SPLITWAVE_ID )] pub splitwave_id: Box>, @@ -26,10 +23,7 @@ pub struct CreateSplitwaveId<'info> { pub fn handler(ctx: Context) -> Result<()> { let splitwave_id = &mut ctx.accounts.splitwave_id; - splitwave_id.bump = *ctx.bumps.get("splitwave_id").unwrap(); - // splitwave_id.count = 1; - splitwave_id.splitwave_id = 1; - // splitwave_id.splitwave_id = "1".to_string(); + splitwave_id.next_id = 1; Ok(()) } \ No newline at end of file diff --git a/programs/splitwave/src/state/splitwave.rs b/programs/splitwave/src/state/splitwave.rs index b01f2e2..3c5d73b 100644 --- a/programs/splitwave/src/state/splitwave.rs +++ b/programs/splitwave/src/state/splitwave.rs @@ -23,6 +23,7 @@ pub struct Splitwave { pub bump: u8, //1 pub splitwave_disbursed: u8, //1 pub splitwave_id: u64, //8 + pub splitwave_id_key: Pubkey, //32 pub total_amount_to_recipient: u64, //8 pub amount_paid_to_splitwave_account: u64, //8 pub total_participants: u64, //8 @@ -36,7 +37,7 @@ pub struct Splitwave { pub participants: Vec, //4 } -pub const SIZE_OF_SPLITWAVE: usize = 1 + 1 + 8 + 8 + 8 + 8 + 8 + 32 + 32 + 32 + 32 + 32 + 1 + 4; +pub const SIZE_OF_SPLITWAVE: usize = 1 + 1 + 8 + 32 + 8 + 8 + 8 + 8 + 32 + 32 + 32 + 32 + 32 + 1 + 4; pub const SIZE_OF_PARTSPLIT: usize = 1 + 8 + 32 + 32; impl Splitwave { diff --git a/programs/splitwave/src/state/splitwave_id.rs b/programs/splitwave/src/state/splitwave_id.rs index 06315d2..143fa68 100644 --- a/programs/splitwave/src/state/splitwave_id.rs +++ b/programs/splitwave/src/state/splitwave_id.rs @@ -1,16 +1,11 @@ use anchor_lang::prelude::*; use shank::ShankAccount; - -pub const SEED_SPLITWAVE_ID: &[u8] = b"splitwave-id"; - - /// Represents the state of a splitwave. #[account] #[derive(Debug, Default, PartialEq, Eq, ShankAccount)] pub struct SplitwaveId { - pub bump: u8, //1 - pub splitwave_id: u64, //24 + pub next_id: u64 //8 } -pub const SIZE_OF_SPLITWAVE_ID: usize = 1 + 8; \ No newline at end of file +pub const SIZE_OF_SPLITWAVE_ID: usize = 8; \ No newline at end of file