clone_solana_sdk/
lib.rs

1//! The Solana host and client SDK.
2//!
3//! This is the base library for all off-chain programs that interact with
4//! Solana or otherwise operate on Solana data structures. On-chain programs
5//! instead use the [`solana-program`] crate, the modules of which are
6//! re-exported by this crate, like the relationship between the Rust
7//! `core` and `std` crates. As much of the functionality of this crate is
8//! provided by `solana-program`, see that crate's documentation for an
9//! overview.
10//!
11//! [`solana-program`]: https://docs.rs/solana-program
12//!
13//! Many of the modules in this crate are primarily of use to the Solana runtime
14//! itself. Additional crates provide capabilities built on `solana-sdk`, and
15//! many programs will need to link to those crates as well, particularly for
16//! clients communicating with Solana nodes over RPC.
17//!
18//! Such crates include:
19//!
20//! - [`solana-client`] - For interacting with a Solana node via the [JSON-RPC API][json].
21//! - [`solana-cli-config`] - Loading and saving the Solana CLI configuration file.
22//! - [`solana-clap-utils`] - Routines for setting up the CLI using [`clap`], as
23//!   used by the Solana CLI. Includes functions for loading all types of
24//!   signers supported by the CLI.
25//!
26//! [`solana-client`]: https://docs.rs/solana-client
27//! [`solana-cli-config`]: https://docs.rs/solana-cli-config
28//! [`solana-clap-utils`]: https://docs.rs/solana-clap-utils
29//! [json]: https://solana.com/docs/rpc
30//! [`clap`]: https://docs.rs/clap
31
32#![cfg_attr(docsrs, feature(doc_auto_cfg))]
33
34// Allows macro expansion of `use ::clone_solana_sdk::*` to work within this crate
35extern crate self as clone_solana_sdk;
36
37#[cfg(feature = "full")]
38pub use clone_solana_commitment_config as commitment_config;
39#[cfg(not(target_os = "solana"))]
40pub use clone_solana_program::program_stubs;
41// These clone_solana_program imports could be *-imported, but that causes a bunch of
42// confusing duplication in the docs due to a rustdoc bug. #26211
43#[allow(deprecated)]
44pub use clone_solana_program::sdk_ids;
45#[cfg(target_arch = "wasm32")]
46pub use clone_solana_program::wasm_bindgen;
47pub use clone_solana_program::{
48    account_info, address_lookup_table, big_mod_exp, blake3, bpf_loader, bpf_loader_deprecated,
49    bpf_loader_upgradeable, clock, config, custom_heap_default, custom_panic_default,
50    debug_account_data, declare_deprecated_sysvar_id, declare_sysvar_id, ed25519_program,
51    epoch_rewards, epoch_schedule, fee_calculator, impl_sysvar_get, incinerator, instruction,
52    keccak, lamports, loader_instruction, loader_upgradeable_instruction, loader_v4,
53    loader_v4_instruction, message, msg, native_token, nonce, program, program_error,
54    program_option, program_pack, rent, secp256k1_program, serialize_utils, slot_hashes,
55    slot_history, stable_layout, stake, stake_history, syscalls, system_instruction,
56    system_program, sysvar, unchecked_div_by_const, vote,
57};
58#[cfg(feature = "borsh")]
59pub use clone_solana_program::{borsh, borsh0_10, borsh1};
60#[cfg(feature = "full")]
61#[deprecated(since = "2.2.0", note = "Use `solana-signer` crate instead")]
62pub use clone_solana_signer::signers;
63pub mod entrypoint;
64pub mod entrypoint_deprecated;
65pub mod example_mocks;
66pub mod feature;
67#[cfg(feature = "full")]
68#[deprecated(since = "2.2.0", note = "Use `solana-genesis-config` crate instead")]
69pub use clone_solana_genesis_config as genesis_config;
70#[cfg(feature = "full")]
71#[deprecated(since = "2.2.0", note = "Use `solana-hard-forks` crate instead")]
72pub use clone_solana_hard_forks as hard_forks;
73pub mod hash;
74pub mod log;
75pub mod native_loader;
76pub mod net;
77#[deprecated(since = "2.2.2", note = "Use `agave-precompiles` crate instead")]
78pub mod precompiles;
79pub mod program_utils;
80pub mod pubkey;
81#[cfg(feature = "full")]
82#[deprecated(
83    since = "2.2.0",
84    note = "Use `clone_solana_rent_collector` crate instead"
85)]
86pub use clone_solana_rent_collector as rent_collector;
87#[deprecated(since = "2.2.0", note = "Use `solana-reward-info` crate instead")]
88pub mod reward_info {
89    pub use clone_solana_reward_info::RewardInfo;
90}
91#[deprecated(since = "2.2.0", note = "Use `solana-reward-info` crate instead")]
92pub mod reward_type {
93    pub use clone_solana_reward_info::RewardType;
94}
95pub mod rpc_port;
96#[cfg(feature = "full")]
97#[deprecated(since = "2.2.0", note = "Use `solana-shred-version` crate instead")]
98pub use clone_solana_shred_version as shred_version;
99pub mod signature;
100pub mod signer;
101pub mod transaction;
102pub mod transport;
103pub mod wasm;
104
105#[deprecated(since = "2.1.0", note = "Use `solana-account` crate instead")]
106pub use clone_solana_account as account;
107#[deprecated(
108    since = "2.1.0",
109    note = "Use `clone_solana_account::state_traits` crate instead"
110)]
111pub use clone_solana_account::state_traits as account_utils;
112#[deprecated(since = "2.1.0", note = "Use `solana-bn254` crate instead")]
113pub use clone_solana_bn254 as alt_bn128;
114#[cfg(feature = "full")]
115#[deprecated(since = "2.2.0", note = "Use `solana-client-traits` crate instead")]
116pub use clone_solana_client_traits as client;
117#[deprecated(
118    since = "2.2.0",
119    note = "Use `solana-compute-budget-interface` crate instead"
120)]
121#[cfg(feature = "full")]
122pub use clone_solana_compute_budget_interface as compute_budget;
123#[deprecated(since = "2.1.0", note = "Use `solana-decode-error` crate instead")]
124pub use clone_solana_decode_error as decode_error;
125#[deprecated(since = "2.1.0", note = "Use `solana-derivation-path` crate instead")]
126pub use clone_solana_derivation_path as derivation_path;
127#[cfg(feature = "full")]
128#[deprecated(since = "2.2.0", note = "Use `solana-ed25519-program` crate instead")]
129pub use clone_solana_ed25519_program as ed25519_instruction;
130#[deprecated(since = "2.2.0", note = "Use `solana-epoch-info` crate instead")]
131pub use clone_solana_epoch_info as epoch_info;
132#[deprecated(
133    since = "2.2.0",
134    note = "Use `solana-epoch-rewards-hasher` crate instead"
135)]
136pub use clone_solana_epoch_rewards_hasher as epoch_rewards_hasher;
137#[deprecated(since = "2.2.2", note = "Use `agave-feature-set` crate instead")]
138pub mod feature_set {
139    pub use clone_solana_feature_set::*;
140}
141#[deprecated(since = "2.2.0", note = "Use `solana-fee-structure` crate instead")]
142pub use clone_solana_fee_structure as fee;
143#[deprecated(since = "2.1.0", note = "Use `solana-inflation` crate instead")]
144pub use clone_solana_inflation as inflation;
145#[deprecated(
146    since = "2.2.0",
147    note = "Use `clone_solana_message::inner_instruction` instead"
148)]
149pub use clone_solana_message::inner_instruction;
150#[deprecated(since = "2.2.0", note = "Use `solana-nonce-account` crate instead")]
151pub use clone_solana_nonce_account as nonce_account;
152#[cfg(feature = "full")]
153#[deprecated(since = "2.2.0", note = "Use `solana-offchain-message` crate instead")]
154pub use clone_solana_offchain_message as offchain_message;
155#[deprecated(since = "2.1.0", note = "Use `solana-packet` crate instead")]
156pub use clone_solana_packet as packet;
157#[deprecated(since = "2.2.0", note = "Use `solana-poh-config` crate instead")]
158pub use clone_solana_poh_config as poh_config;
159#[deprecated(since = "2.1.0", note = "Use `solana-program-memory` crate instead")]
160pub use clone_solana_program_memory as program_memory;
161#[deprecated(since = "2.1.0", note = "Use `clone_solana_pubkey::pubkey` instead")]
162/// Convenience macro to define a static public key.
163///
164/// Input: a single literal base58 string representation of a Pubkey
165///
166/// # Example
167///
168/// ```
169/// use std::str::FromStr;
170/// use clone_solana_program::{pubkey, pubkey::Pubkey};
171///
172/// static ID: Pubkey = pubkey!("My11111111111111111111111111111111111111111");
173///
174/// let my_id = Pubkey::from_str("My11111111111111111111111111111111111111111").unwrap();
175/// assert_eq!(ID, my_id);
176/// ```
177pub use clone_solana_pubkey::pubkey;
178#[cfg(feature = "full")]
179#[deprecated(since = "2.2.0", note = "Use `solana-quic-definitions` crate instead")]
180pub use clone_solana_quic_definitions as quic;
181#[deprecated(since = "2.2.0", note = "Use `solana-rent-debits` crate instead")]
182pub use clone_solana_rent_debits as rent_debits;
183#[cfg(feature = "full")]
184#[deprecated(
185    since = "2.2.2",
186    note = "Use `agave-reserved-account-keys` crate instead"
187)]
188pub mod reserved_account_keys {
189    pub use clone_solana_reserved_account_keys::*;
190}
191#[deprecated(since = "2.1.0", note = "Use `solana-sanitize` crate instead")]
192pub use clone_solana_sanitize as sanitize;
193/// Same as `declare_id` except report that this id has been deprecated.
194pub use clone_solana_sdk_macro::declare_deprecated_id;
195/// Convenience macro to declare a static public key and functions to interact with it.
196///
197/// Input: a single literal base58 string representation of a program's id
198///
199/// # Example
200///
201/// ```
202/// # // wrapper is used so that the macro invocation occurs in the item position
203/// # // rather than in the statement position which isn't allowed.
204/// use std::str::FromStr;
205/// use clone_solana_sdk::{declare_id, pubkey::Pubkey};
206///
207/// # mod item_wrapper {
208/// #   use clone_solana_sdk::declare_id;
209/// declare_id!("My11111111111111111111111111111111111111111");
210/// # }
211/// # use item_wrapper::id;
212///
213/// let my_id = Pubkey::from_str("My11111111111111111111111111111111111111111").unwrap();
214/// assert_eq!(id(), my_id);
215/// ```
216pub use clone_solana_sdk_macro::declare_id;
217/// Convenience macro to define multiple static public keys.
218pub use clone_solana_sdk_macro::pubkeys;
219#[deprecated(since = "2.2.0", note = "Use `solana-secp256k1-program` crate instead")]
220#[cfg(feature = "full")]
221pub use clone_solana_secp256k1_program as secp256k1_instruction;
222#[deprecated(since = "2.1.0", note = "Use `solana-secp256k1-recover` crate instead")]
223pub use clone_solana_secp256k1_recover as secp256k1_recover;
224#[deprecated(since = "2.2.0", note = "Use `solana-serde` crate instead")]
225pub use clone_solana_serde as deserialize_utils;
226#[deprecated(since = "2.1.0", note = "Use `solana-serde-varint` crate instead")]
227pub use clone_solana_serde_varint as serde_varint;
228#[deprecated(since = "2.1.0", note = "Use `solana-short-vec` crate instead")]
229pub use clone_solana_short_vec as short_vec;
230#[cfg(feature = "full")]
231#[deprecated(
232    since = "2.2.0",
233    note = "Use `solana-system-transaction` crate instead"
234)]
235pub use clone_solana_system_transaction as system_transaction;
236#[deprecated(since = "2.2.0", note = "Use `solana-time-utils` crate instead")]
237pub use clone_solana_time_utils as timing;
238#[cfg(feature = "full")]
239#[deprecated(
240    since = "2.2.0",
241    note = "Use `clone_solana_transaction::simple_vote_transaction_checker` instead"
242)]
243pub use clone_solana_transaction::simple_vote_transaction_checker;
244#[deprecated(
245    since = "2.2.0",
246    note = "Use `solana-transaction-context` crate instead"
247)]
248pub mod transaction_context {
249    pub use clone_solana_transaction_context::*;
250}
251#[deprecated(since = "2.2.0", note = "Use `solana-validator-exit` crate instead")]
252pub use clone_solana_validator_exit as exit;
253
254/// Convenience macro for `AddAssign` with saturating arithmetic.
255/// Replace by `std::num::Saturating` once stable
256#[macro_export]
257macro_rules! saturating_add_assign {
258    ($i:expr, $v:expr) => {{
259        $i = $i.saturating_add($v)
260    }};
261}
262
263pub extern crate bs58;
264
265#[cfg(test)]
266mod tests {
267    #[test]
268    fn test_saturating_add_assign() {
269        let mut i = 0u64;
270        let v = 1;
271        saturating_add_assign!(i, v);
272        assert_eq!(i, 1);
273
274        i = u64::MAX;
275        saturating_add_assign!(i, v);
276        assert_eq!(i, u64::MAX);
277    }
278}