solana_program/sysvar/
rent.rs

1//! Configuration for network [rent].
2//!
3//! [rent]: https://docs.solanalabs.com/implemented-proposals/rent
4//!
5//! The _rent sysvar_ provides access to the [`Rent`] type, which defines
6//! storage rent fees.
7//!
8//! [`Rent`] implements [`Sysvar::get`] and can be loaded efficiently without
9//! passing the sysvar account ID to the program.
10//!
11//! See also the Solana [documentation on the rent sysvar][sdoc].
12//!
13//! [sdoc]: https://docs.solanalabs.com/runtime/sysvars#rent
14//!
15//! # Examples
16//!
17//! Accessing via on-chain program directly:
18//!
19//! ```no_run
20//! # use solana_program::{
21//! #    account_info::{AccountInfo, next_account_info},
22//! #    entrypoint::ProgramResult,
23//! #    msg,
24//! #    pubkey::Pubkey,
25//! #    sysvar::rent::{self, Rent},
26//! #    sysvar::Sysvar,
27//! # };
28//! # use solana_program::program_error::ProgramError;
29//! #
30//! fn process_instruction(
31//!     program_id: &Pubkey,
32//!     accounts: &[AccountInfo],
33//!     instruction_data: &[u8],
34//! ) -> ProgramResult {
35//!
36//!     let rent = Rent::get()?;
37//!     msg!("rent: {:#?}", rent);
38//!
39//!     Ok(())
40//! }
41//! #
42//! # use solana_sysvar_id::SysvarId;
43//! # let p = Rent::id();
44//! # let l = &mut 1009200;
45//! # let d = &mut vec![152, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 100];
46//! # let a = AccountInfo::new(&p, false, false, l, d, &p, false, 0);
47//! # let accounts = &[a.clone(), a];
48//! # process_instruction(
49//! #     &Pubkey::new_unique(),
50//! #     accounts,
51//! #     &[],
52//! # )?;
53//! # Ok::<(), ProgramError>(())
54//! ```
55//!
56//! Accessing via on-chain program's parameters:
57//!
58//! ```
59//! # use solana_program::{
60//! #    account_info::{AccountInfo, next_account_info},
61//! #    entrypoint::ProgramResult,
62//! #    msg,
63//! #    pubkey::Pubkey,
64//! #    sysvar::rent::{self, Rent},
65//! #    sysvar::Sysvar,
66//! # };
67//! # use solana_program::program_error::ProgramError;
68//! #
69//! fn process_instruction(
70//!     program_id: &Pubkey,
71//!     accounts: &[AccountInfo],
72//!     instruction_data: &[u8],
73//! ) -> ProgramResult {
74//!     let account_info_iter = &mut accounts.iter();
75//!     let rent_account_info = next_account_info(account_info_iter)?;
76//!
77//!     assert!(rent::check_id(rent_account_info.key));
78//!
79//!     let rent = Rent::from_account_info(rent_account_info)?;
80//!     msg!("rent: {:#?}", rent);
81//!
82//!     Ok(())
83//! }
84//! #
85//! # use solana_sysvar_id::SysvarId;
86//! # let p = Rent::id();
87//! # let l = &mut 1009200;
88//! # let d = &mut vec![152, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 100];
89//! # let a = AccountInfo::new(&p, false, false, l, d, &p, false, 0);
90//! # let accounts = &[a.clone(), a];
91//! # process_instruction(
92//! #     &Pubkey::new_unique(),
93//! #     accounts,
94//! #     &[],
95//! # )?;
96//! # Ok::<(), ProgramError>(())
97//! ```
98//!
99//! Accessing via the RPC client:
100//!
101//! ```
102//! # use solana_program::example_mocks::solana_sdk;
103//! # use solana_program::example_mocks::solana_rpc_client;
104//! # use solana_sdk::account::Account;
105//! # use solana_rpc_client::rpc_client::RpcClient;
106//! # use solana_sdk::sysvar::rent::{self, Rent};
107//! # use anyhow::Result;
108//! #
109//! fn print_sysvar_rent(client: &RpcClient) -> Result<()> {
110//! #   client.set_get_account_response(rent::ID, Account {
111//! #       lamports: 1009200,
112//! #       data: vec![152, 13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 64, 100],
113//! #       owner: solana_sdk::system_program::ID,
114//! #       executable: false,
115//! #       rent_epoch: 307,
116//! # });
117//! #
118//!     let rent = client.get_account(&rent::ID)?;
119//!     let data: Rent = bincode::deserialize(&rent.data)?;
120//!
121//!     Ok(())
122//! }
123//! #
124//! # let client = RpcClient::new(String::new());
125//! # print_sysvar_rent(&client)?;
126//! #
127//! # Ok::<(), anyhow::Error>(())
128//! ```
129use crate::{impl_sysvar_get, program_error::ProgramError, sysvar::Sysvar};
130pub use solana_rent::{
131    sysvar::{check_id, id, ID},
132    Rent,
133};
134
135impl Sysvar for Rent {
136    impl_sysvar_get!(sol_get_rent_sysvar);
137}