light_token_interface/state/mint/
borsh.rs1use borsh::{BorshDeserialize, BorshSerialize};
2use light_compressed_account::Pubkey;
3
4use super::compressed_mint::BaseMint;
5
6impl BorshSerialize for BaseMint {
8 fn serialize<W: std::io::Write>(&self, writer: &mut W) -> std::io::Result<()> {
9 if let Some(authority) = self.mint_authority {
11 writer.write_all(&[1, 0, 0, 0])?; writer.write_all(&authority.to_bytes())?;
13 } else {
14 writer.write_all(&[0; 36])?; }
16
17 writer.write_all(&self.supply.to_le_bytes())?;
19
20 writer.write_all(&[self.decimals])?;
22
23 writer.write_all(&[if self.is_initialized { 1 } else { 0 }])?;
25
26 if let Some(authority) = self.freeze_authority {
28 writer.write_all(&[1, 0, 0, 0])?; writer.write_all(&authority.to_bytes())?;
30 } else {
31 writer.write_all(&[0; 36])?; }
33
34 Ok(())
35 }
36}
37
38impl BorshDeserialize for BaseMint {
40 fn deserialize_reader<R: std::io::Read>(buf: &mut R) -> std::io::Result<Self> {
41 let mut discriminator = [0u8; 4];
43 buf.read_exact(&mut discriminator)?;
44 let mut pubkey_bytes = [0u8; 32];
45 buf.read_exact(&mut pubkey_bytes)?;
46 let mint_authority = if u32::from_le_bytes(discriminator) == 1 {
47 Some(Pubkey::from(pubkey_bytes))
48 } else {
49 None
50 };
51
52 let mut supply_bytes = [0u8; 8];
54 buf.read_exact(&mut supply_bytes)?;
55 let supply = u64::from_le_bytes(supply_bytes);
56
57 let mut decimals = [0u8; 1];
59 buf.read_exact(&mut decimals)?;
60 let decimals = decimals[0];
61
62 let mut is_initialized = [0u8; 1];
64 buf.read_exact(&mut is_initialized)?;
65 let is_initialized = is_initialized[0] != 0;
66
67 let mut discriminator = [0u8; 4];
69 buf.read_exact(&mut discriminator)?;
70 let mut pubkey_bytes = [0u8; 32];
71 buf.read_exact(&mut pubkey_bytes)?;
72 let freeze_authority = if u32::from_le_bytes(discriminator) == 1 {
73 Some(Pubkey::from(pubkey_bytes))
74 } else {
75 None
76 };
77
78 Ok(Self {
79 mint_authority,
80 supply,
81 decimals,
82 is_initialized,
83 freeze_authority,
84 })
85 }
86}