gmsol_decode/decoder/decoder_impl/
mod.rs1#[cfg(feature = "solana-decoder")]
3pub mod solana_decoder;
4
5#[cfg(feature = "solana-decoder")]
6pub use solana_decoder::{CPIEventFilter, CPIEvents, TransactionDecoder};
7
8use crate::{AccountAccess, DecodeError, Visitor};
9
10use super::Decoder;
11
12#[derive(Debug, Clone)]
14pub struct AccountAccessDecoder<A>(A);
15
16impl<A> AccountAccessDecoder<A> {
17 pub fn new(account: A) -> Self {
19 Self(account)
20 }
21}
22
23impl<A: AccountAccess> Decoder for AccountAccessDecoder<A> {
24 fn decode_account<V>(&self, visitor: V) -> Result<V::Value, DecodeError>
25 where
26 V: Visitor,
27 {
28 visitor.visit_account(&self.0)
29 }
30
31 fn decode_transaction<V>(&self, _visitor: V) -> Result<V::Value, DecodeError>
32 where
33 V: Visitor,
34 {
35 Err(DecodeError::InvalidType(
36 "Expecting `Transaction` but found `AccountInfo`".to_string(),
37 ))
38 }
39
40 fn decode_anchor_cpi_events<V>(&self, _visitor: V) -> Result<V::Value, DecodeError>
41 where
42 V: Visitor,
43 {
44 Err(DecodeError::InvalidType(
45 "Expecting `AnchorCPIEvents` but found `AccountInfo`".to_string(),
46 ))
47 }
48
49 fn decode_owned_data<V>(&self, visitor: V) -> Result<V::Value, DecodeError>
50 where
51 V: Visitor,
52 {
53 visitor.visit_owned_data(&self.0.owner()?, self.0.data()?)
54 }
55
56 fn decode_bytes<V>(&self, visitor: V) -> Result<V::Value, DecodeError>
57 where
58 V: Visitor,
59 {
60 visitor.visit_bytes(self.0.data()?)
61 }
62}