carbon_points_decoder/instructions/
spend_points.rs1use carbon_core::CarbonDeserialize;
3use carbon_core::account_utils::next_account;
4use carbon_core::borsh;
5use carbon_core::deserialize::ArrangeAccounts;
6use carbon_core::deserialize::CarbonDeserialize;
7
8#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
9#[derive(Debug, Clone, borsh::BorshSerialize, CarbonDeserialize, PartialEq, Eq, Hash)]
10pub struct SpendPoints {
11 pub points_amount: u64,
12 pub key_index: u16,
13}
14
15#[derive(Debug, Clone, PartialEq)]
16#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
17pub struct SpendPointsInstructionAccounts {
18 pub spender: solana_pubkey::Pubkey,
19 pub spender_profile: solana_pubkey::Pubkey,
20 pub category: solana_pubkey::Pubkey,
21 pub user_points_account: solana_pubkey::Pubkey,
22 pub remaining: Vec<solana_instruction::AccountMeta>,
23}
24
25impl SpendPoints {
26 pub fn decode(data: &[u8]) -> Option<Self> {
27 if data.len() < 8 {
28 return None;
29 }
30 let discriminator = &data[0..8];
31 if discriminator != &[131, 89, 63, 98, 243, 212, 224, 102] {
32 return None;
33 }
34
35 let data_slice = data;
36
37 let data_slice = &data_slice[8..];
38
39 Self::deserialize(data_slice)
40 }
41}
42
43impl ArrangeAccounts for SpendPoints {
44 type ArrangedAccounts = SpendPointsInstructionAccounts;
45
46 fn arrange_accounts(
47 accounts: &[solana_instruction::AccountMeta],
48 ) -> Option<Self::ArrangedAccounts> {
49 let mut iter = accounts.iter();
50
51 let spender = next_account(&mut iter)?;
52 let spender_profile = next_account(&mut iter)?;
53 let category = next_account(&mut iter)?;
54 let user_points_account = next_account(&mut iter)?;
55
56 let remaining = iter.as_slice();
57
58 Some(SpendPointsInstructionAccounts {
59 spender,
60 spender_profile,
61 category,
62 user_points_account,
63 remaining: remaining.to_vec(),
64 })
65 }
66}