1#![allow(deprecated)]
22
23#[cfg(feature = "serde")]
24use serde_derive::{Deserialize, Serialize};
25pub use solana_sdk_ids::sysvar::fees::{check_id, id, ID};
26#[cfg(target_os = "solana")]
27use {solana_define_syscall::definitions, solana_program_entrypoint::SUCCESS};
28use {
29 solana_fee_calculator::FeeCalculator, solana_get_sysvar::GetSysvar,
30 solana_sdk_macro::CloneZeroed, solana_sysvar_id::impl_deprecated_sysvar_id,
31};
32
33impl_deprecated_sysvar_id!(Fees);
34
35#[deprecated(
37 since = "1.9.0",
38 note = "Please do not use, will no longer be available in the future"
39)]
40#[repr(C)]
41#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
42#[cfg_attr(feature = "wincode", derive(wincode::SchemaWrite, wincode::SchemaRead))]
43#[derive(Debug, CloneZeroed, Default, PartialEq, Eq)]
44pub struct Fees {
45 pub fee_calculator: FeeCalculator,
46}
47
48pub const SIZE: usize = size_of::<Fees>();
50const _: () = assert!(SIZE == 8);
51
52impl Fees {
53 pub fn new(fee_calculator: &FeeCalculator) -> Self {
54 #[allow(deprecated)]
55 Self {
56 fee_calculator: *fee_calculator,
57 }
58 }
59}
60
61impl GetSysvar for Fees {
65 fn get() -> Result<Self, solana_program_error::ProgramError> {
66 #[cfg(target_os = "solana")]
67 {
68 let mut fees = Self::default();
69 let fees_addr = &mut fees as *mut _ as *mut u8;
70 let result = unsafe { definitions::sol_get_fees_sysvar(fees_addr) };
71
72 match result {
73 SUCCESS => Ok(fees),
74 _ => Err(solana_program_error::ProgramError::UnsupportedSysvar),
75 }
76 }
77
78 #[cfg(not(target_os = "solana"))]
79 {
80 Err(solana_program_error::ProgramError::UnsupportedSysvar)
81 }
82 }
83}
84
85#[cfg(test)]
86mod tests {
87 use super::*;
88
89 #[test]
90 fn test_size_of() {
91 assert_eq!(
92 wincode::serialized_size(&Fees::default()).unwrap() as usize,
93 SIZE,
94 );
95 }
96
97 #[test]
98 fn test_clone() {
99 let fees = Fees {
100 fee_calculator: FeeCalculator {
101 lamports_per_signature: 1,
102 },
103 };
104 let cloned_fees = fees.clone();
105 assert_eq!(cloned_fees, fees);
106 }
107}