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