Skip to main content

sendfun_sdk/nexus/generated/accounts/
partner_metadata.rs

1#![allow(
2	clippy::all,
3	clippy::pedantic,
4	clippy::nursery,
5	clippy::expect_used,
6	clippy::unwrap_used,
7	clippy::indexing_slicing,
8	clippy::allow_attributes,
9	clippy::allow_attributes_without_reason,
10	clippy::mem_forget,
11	unfulfilled_lint_expectations,
12	unexpected_cfgs,
13	unused_imports
14)]
15
16//! This code was AUTOGENERATED using the codama library.
17//! Please DO NOT EDIT THIS FILE, instead use visitors
18//! to add features, then rerun codama to update it.
19//!
20//! <https://github.com/codama-idl/codama>
21//!
22
23use borsh::BorshDeserialize;
24use borsh::BorshSerialize;
25use solana_address::Address;
26
27#[derive(BorshSerialize, BorshDeserialize, Clone, Debug, Eq, PartialEq)]
28#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
29#[cfg_attr(feature = "serde", serde(rename_all = "camelCase"))]
30pub struct PartnerMetadata {
31	pub discriminator: [u8; 8],
32	pub version: u8,
33	pub bump: u8,
34	#[cfg_attr(
35		feature = "serde",
36		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
37	)]
38	pub partner: Address,
39	pub name: String,
40	pub note: String,
41	#[cfg_attr(
42		feature = "serde",
43		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
44	)]
45	pub added_at: i64,
46	#[cfg_attr(
47		feature = "serde",
48		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
49	)]
50	pub updated_at: i64,
51	#[cfg_attr(
52		feature = "serde",
53		serde(with = "serde_with::As::<serde_with::DisplayFromStr>")
54	)]
55	pub platform_config: Address,
56	pub reserved: [u8; 32],
57}
58
59pub const PARTNER_METADATA_DISCRIMINATOR: [u8; 8] =
60	[68, 68, 130, 19, 16, 209, 98, 156];
61
62impl PartnerMetadata {
63	#[inline(always)]
64	pub fn from_bytes(data: &[u8]) -> Result<Self, std::io::Error> {
65		if data.get(..PARTNER_METADATA_DISCRIMINATOR.len())
66			!= Some(&PARTNER_METADATA_DISCRIMINATOR[..])
67		{
68			return Err(std::io::Error::new(
69				std::io::ErrorKind::InvalidData,
70				"invalid account discriminator",
71			));
72		}
73		let mut data = data;
74		Self::deserialize(&mut data)
75	}
76
77	/// Decodes an account read off-chain after checking its owner and discriminator.
78	pub fn from_account(
79		owner: &solana_address::Address,
80		data: &[u8],
81	) -> Result<Self, std::io::Error> {
82		if *owner != crate::nexus::generated::SEND_NEXUS_ID {
83			return Err(std::io::Error::new(
84				std::io::ErrorKind::InvalidData,
85				format!(
86					"invalid account owner: {owner}, expected {}",
87					crate::nexus::generated::SEND_NEXUS_ID
88				),
89			));
90		}
91		Self::from_bytes(data)
92	}
93
94	/// `Ok(None)` for an account that is not created yet: the system program owns it with no data (an address someone sent lamports to).
95	pub fn from_account_maybe(
96		owner: &solana_address::Address,
97		data: &[u8],
98	) -> Result<Option<Self>, std::io::Error> {
99		if data.is_empty() && *owner == super::SYSTEM_PROGRAM_ID {
100			return Ok(None);
101		}
102		Self::from_account(owner, data).map(Some)
103	}
104}
105
106impl<'a> TryFrom<&solana_program::account_info::AccountInfo<'a>>
107	for PartnerMetadata
108{
109	type Error = std::io::Error;
110
111	fn try_from(
112		account_info: &solana_program::account_info::AccountInfo<'a>,
113	) -> Result<Self, Self::Error> {
114		if account_info.owner != &crate::nexus::generated::SEND_NEXUS_ID {
115			return Err(std::io::Error::new(
116				std::io::ErrorKind::InvalidData,
117				"invalid account owner",
118			));
119		}
120		let data: &[u8] = &(*account_info.data).borrow();
121		Self::from_bytes(data)
122	}
123}
124
125#[cfg(feature = "anchor")]
126impl anchor_lang::AccountDeserialize for PartnerMetadata {
127	fn try_deserialize(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
128		if buf.len() < PARTNER_METADATA_DISCRIMINATOR.len()
129			|| buf[..PARTNER_METADATA_DISCRIMINATOR.len()]
130				!= PARTNER_METADATA_DISCRIMINATOR[..]
131		{
132			return Err(
133				anchor_lang::error::ErrorCode::AccountDiscriminatorMismatch
134					.into(),
135			);
136		}
137		Self::try_deserialize_unchecked(buf)
138	}
139
140	fn try_deserialize_unchecked(buf: &mut &[u8]) -> anchor_lang::Result<Self> {
141		Ok(Self::deserialize(buf)?)
142	}
143}
144
145#[cfg(feature = "anchor")]
146impl anchor_lang::AccountSerialize for PartnerMetadata {}
147
148#[cfg(feature = "anchor")]
149impl anchor_lang::Owner for PartnerMetadata {
150	fn owner() -> anchor_lang::solana_program::pubkey::Pubkey {
151		anchor_lang::solana_program::pubkey::Pubkey::from(
152			crate::nexus::generated::SEND_NEXUS_ID.to_bytes(),
153		)
154	}
155}
156
157#[cfg(feature = "anchor-idl-build")]
158impl anchor_lang::IdlBuild for PartnerMetadata {}
159
160#[cfg(feature = "anchor-idl-build")]
161impl anchor_lang::Discriminator for PartnerMetadata {
162	const DISCRIMINATOR: &[u8] = &PARTNER_METADATA_DISCRIMINATOR;
163}