light_instruction_decoder/
core.rs1use solana_instruction::AccountMeta;
4use solana_pubkey::Pubkey;
5
6#[derive(Debug, Clone)]
8pub struct DecodedField {
9 pub name: String,
11 pub value: String,
13 pub children: Vec<DecodedField>,
15}
16
17impl DecodedField {
18 pub fn new(name: impl Into<String>, value: impl Into<String>) -> Self {
20 Self {
21 name: name.into(),
22 value: value.into(),
23 children: Vec::new(),
24 }
25 }
26
27 pub fn with_children(name: impl Into<String>, children: Vec<DecodedField>) -> Self {
29 Self {
30 name: name.into(),
31 value: String::new(),
32 children,
33 }
34 }
35}
36
37#[derive(Debug, Clone)]
39pub struct DecodedInstruction {
40 pub name: String,
42 pub fields: Vec<DecodedField>,
44 pub account_names: Vec<String>,
46}
47
48impl DecodedInstruction {
49 pub fn with_fields_and_accounts(
51 name: impl Into<String>,
52 fields: Vec<DecodedField>,
53 account_names: Vec<String>,
54 ) -> Self {
55 Self {
56 name: name.into(),
57 fields,
58 account_names,
59 }
60 }
61}
62
63pub trait InstructionDecoder: Send + Sync {
65 fn program_id(&self) -> Pubkey;
67
68 fn program_name(&self) -> &'static str;
70
71 fn decode(&self, data: &[u8], accounts: &[AccountMeta]) -> Option<DecodedInstruction>;
74}