gmsol_decode/decoder/
mod.rs

1use crate::{decode::visitor::Visitor, error::DecodeError};
2
3/// Account Access.
4pub mod account_access;
5
6/// Transaction Access.
7pub mod transaction_access;
8
9/// CPI Event Access.
10pub mod cpi_event_access;
11
12/// Decoder implementations.
13pub mod decoder_impl;
14
15pub use decoder_impl::*;
16
17/// Decoder for received program data.
18pub trait Decoder {
19    /// Hint that the visitor is expecting an `AccountInfo`.
20    fn decode_account<V>(&self, visitor: V) -> Result<V::Value, DecodeError>
21    where
22        V: Visitor;
23
24    /// Hint that the visitor is expecting a `Transaction`.
25    fn decode_transaction<V>(&self, visitor: V) -> Result<V::Value, DecodeError>
26    where
27        V: Visitor;
28
29    /// Hint that the visitor is expecting `AnchorCPIEvent` list.
30    fn decode_anchor_cpi_events<V>(&self, visitor: V) -> Result<V::Value, DecodeError>
31    where
32        V: Visitor;
33
34    /// Hint that the visitor is expecting a `OwnedData`.
35    ///
36    /// It can be the data of an `Event` of an `Instruction`.
37    fn decode_owned_data<V>(&self, visitor: V) -> Result<V::Value, DecodeError>
38    where
39        V: Visitor;
40
41    /// Hint that the visitor is expecting a `Data`.
42    ///
43    /// It can be the data of an `Event` of an `Instruction`.
44    fn decode_bytes<V>(&self, visitor: V) -> Result<V::Value, DecodeError>
45    where
46        V: Visitor;
47}
48
49impl<D: Decoder> Decoder for &D {
50    fn decode_account<V>(&self, visitor: V) -> Result<V::Value, DecodeError>
51    where
52        V: Visitor,
53    {
54        (**self).decode_account(visitor)
55    }
56
57    fn decode_transaction<V>(&self, visitor: V) -> Result<V::Value, DecodeError>
58    where
59        V: Visitor,
60    {
61        (**self).decode_transaction(visitor)
62    }
63
64    fn decode_anchor_cpi_events<V>(&self, visitor: V) -> Result<V::Value, DecodeError>
65    where
66        V: Visitor,
67    {
68        (**self).decode_anchor_cpi_events(visitor)
69    }
70
71    fn decode_owned_data<V>(&self, visitor: V) -> Result<V::Value, DecodeError>
72    where
73        V: Visitor,
74    {
75        (**self).decode_owned_data(visitor)
76    }
77
78    fn decode_bytes<V>(&self, visitor: V) -> Result<V::Value, DecodeError>
79    where
80        V: Visitor,
81    {
82        (**self).decode_bytes(visitor)
83    }
84}