Skip to content
This repository was archived by the owner on Feb 6, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions programs/splitwave/src/instructions/create_splitwave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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<Account<'info, SplitwaveId>>,

pub rent: Sysvar<'info, Rent>,
Expand Down Expand Up @@ -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;
Expand All @@ -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(())
Expand Down
10 changes: 2 additions & 8 deletions programs/splitwave/src/instructions/create_splitwave_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use {
anchor_lang::prelude::*,
crate::state::{
SIZE_OF_SPLITWAVE_ID,
SEED_SPLITWAVE_ID,
SplitwaveId
}
};
Expand All @@ -12,9 +11,7 @@ pub struct CreateSplitwaveId<'info> {
#[account(
init,
payer = payer,
space = 8 + SIZE_OF_SPLITWAVE_ID,
seeds = [SEED_SPLITWAVE_ID],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we remove seeds for splitwave_id it would be an extra work for protocol users to store the key of SplitwaveId account. We should make the tracking of SplitwaveAccount easy.

bump
space = 8 + SIZE_OF_SPLITWAVE_ID
)]
pub splitwave_id: Box<Account<'info, SplitwaveId>>,

Expand All @@ -26,10 +23,7 @@ pub struct CreateSplitwaveId<'info> {

pub fn handler(ctx: Context<CreateSplitwaveId>) -> 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(())
}
3 changes: 2 additions & 1 deletion programs/splitwave/src/state/splitwave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,7 +37,7 @@ pub struct Splitwave {
pub participants: Vec<SplitParticipant>, //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 {
Expand Down
9 changes: 2 additions & 7 deletions programs/splitwave/src/state/splitwave_id.rs
Original file line number Diff line number Diff line change
@@ -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;
pub const SIZE_OF_SPLITWAVE_ID: usize = 8;