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