spl_token_2022/extension/
permanent_delegate.rs1#[cfg(feature = "serde-traits")]
2use serde::{Deserialize, Serialize};
3use {
4 crate::extension::{BaseState, BaseStateWithExtensions, Extension, ExtensionType},
5 bytemuck::{Pod, Zeroable},
6 solana_program::pubkey::Pubkey,
7 spl_pod::optional_keys::OptionalNonZeroPubkey,
8};
9
10#[repr(C)]
12#[cfg_attr(feature = "serde-traits", derive(Serialize, Deserialize))]
13#[cfg_attr(feature = "serde-traits", serde(rename_all = "camelCase"))]
14#[derive(Clone, Copy, Debug, Default, PartialEq, Pod, Zeroable)]
15pub struct PermanentDelegate {
16 pub delegate: OptionalNonZeroPubkey,
18}
19impl Extension for PermanentDelegate {
20 const TYPE: ExtensionType = ExtensionType::PermanentDelegate;
21}
22
23pub fn get_permanent_delegate<S: BaseState, BSE: BaseStateWithExtensions<S>>(
26 state: &BSE,
27) -> Option<Pubkey> {
28 state
29 .get_extension::<PermanentDelegate>()
30 .ok()
31 .and_then(|e| Option::<Pubkey>::from(e.delegate))
32}