This repository was archived by the owner on Feb 6, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsplitwave.rs
More file actions
65 lines (57 loc) · 2.05 KB
/
splitwave.rs
File metadata and controls
65 lines (57 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use {
anchor_lang::prelude::*,
std::convert::TryFrom,
crate::errors::SplitwaveError,
};
pub const SEED_SPLITWAVE: &[u8] = b"splitwave";
pub const SEED_SPLITWAVE_TREASURY: &[u8] = b"splitwave-treasury";
/// A structure representing a participant's split and payment status.
#[derive(AnchorSerialize, AnchorDeserialize, Clone, Copy, PartialEq, Eq, Debug, Default)]
pub struct SplitParticipant {
pub paid: bool, //1
pub participant_split_amount: u64, //8
pub participant: Pubkey, //32
pub participant_token_account: Pubkey, //32
}
/// Represents the state of a splitwave.
#[account]
#[derive(Debug, Default, PartialEq, Eq)]
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
pub participants_paid_to_splitwave: u64, //8
pub authority: Pubkey, //32
pub recipient: Pubkey, //32
pub recipient_token_account: Pubkey, //32
pub splitwave_mint: Pubkey, //32
pub splitwave_treasury: Pubkey, //32
pub splitwave_treasury_bump: u8, //1
pub participants: Vec<SplitParticipant>, //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 {
/// Calculates the Splitwave's pubkey based on authority, mint, and recipient.
pub fn pubkey(&mut self) -> Pubkey {
Pubkey::find_program_address(
&[
SEED_SPLITWAVE,
self.splitwave_id.to_le_bytes().as_ref(),
],
&crate::ID,
)
.0
}
}
impl TryFrom<Vec<u8>> for Splitwave {
type Error = SplitwaveError;
/// Tries to create a Splitwave instance from a Vec<u8>.
fn try_from(data: Vec<u8>) -> std::result::Result<Self, Self::Error> {
Splitwave::try_deserialize(&mut data.as_slice()).map_err(|_| SplitwaveError::DeserializationError)
}
}