yellowstone_shield_parser/generated/
accounts_parser.rs1use solana_program::pubkey::Pubkey;
2use yellowstone_shield_client::ID;
3use yellowstone_shield_client::{accounts, types::PermissionStrategy, PolicyTrait};
4use yellowstone_vixen_core::AccountUpdate;
5
6#[derive(Debug, Clone)]
7pub struct Policy {
8 pub strategy: PermissionStrategy,
9 pub identities: Vec<Pubkey>,
10}
11
12impl Policy {
13 pub fn new(strategy: PermissionStrategy, identities: Vec<Pubkey>) -> Self {
14 Self {
15 strategy,
16 identities,
17 }
18 }
19}
20
21#[allow(clippy::large_enum_variant, dead_code)]
23#[derive(Debug, Clone)]
24pub enum ShieldProgramState {
25 Policy(u64, Pubkey, Policy),
26}
27
28impl ShieldProgramState {
29 fn parse_policy<T: PolicyTrait>(data: &[u8]) -> yellowstone_vixen_core::ParseResult<Policy> {
30 let policy = T::from_bytes(data)?;
31 let identities = accounts::Policy::try_deserialize_identities(data)?;
32 let strategy = policy.try_strategy()?;
33
34 Ok(Policy {
35 strategy,
36 identities,
37 })
38 }
39
40 pub fn try_unpack(account_update: &AccountUpdate) -> yellowstone_vixen_core::ParseResult<Self> {
41 let inner = account_update
42 .account
43 .as_ref()
44 .ok_or(solana_program::program_error::ProgramError::InvalidArgument)?;
45 let data = inner.data.as_slice();
46
47 if data.is_empty() {
48 return Err(yellowstone_vixen_core::ParseError::from(
49 "Data is empty".to_owned(),
50 ));
51 }
52
53 let policy = match data[0] {
54 0 => Self::parse_policy::<accounts::Policy>(data)?,
55 1 => Self::parse_policy::<accounts::PolicyV2>(data)?,
56 _ => {
57 return Err(yellowstone_vixen_core::ParseError::from(
58 "Unsupported data type".to_owned(),
59 ))
60 }
61 };
62
63 Ok(ShieldProgramState::Policy(
64 account_update.slot,
65 Pubkey::try_from(inner.pubkey.as_slice())?,
66 policy,
67 ))
68 }
69}
70
71#[derive(Debug, Copy, Clone)]
72pub struct AccountParser;
73
74impl yellowstone_vixen_core::Parser for AccountParser {
75 type Input = yellowstone_vixen_core::AccountUpdate;
76 type Output = ShieldProgramState;
77
78 fn id(&self) -> std::borrow::Cow<str> {
79 "shield::AccountParser".into()
80 }
81
82 fn prefilter(&self) -> yellowstone_vixen_core::Prefilter {
83 yellowstone_vixen_core::Prefilter::builder()
84 .account_owners([ID])
85 .build()
86 .unwrap()
87 }
88
89 async fn parse(
90 &self,
91 acct: &yellowstone_vixen_core::AccountUpdate,
92 ) -> yellowstone_vixen_core::ParseResult<Self::Output> {
93 ShieldProgramState::try_unpack(acct)
94 }
95}
96
97impl yellowstone_vixen_core::ProgramParser for AccountParser {
98 #[inline]
99 fn program_id(&self) -> yellowstone_vixen_core::Pubkey {
100 ID.to_bytes().into()
101 }
102}