waffles_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://docs.solana.com/developing/clients/jsonrpc-api
30//! [`clap`]: https://docs.rs/clap
31
32#![allow(incomplete_features)]
33#![cfg_attr(RUSTC_WITH_SPECIALIZATION, feature(specialization))]
34#![cfg_attr(RUSTC_NEEDS_PROC_MACRO_HYGIENE, feature(proc_macro_hygiene))]
35
36// Allows macro expansion of `use ::solana_sdk::*` to work within this crate
37extern crate self as solana_sdk;
38
39#[cfg(feature = "full")]
40pub use signer::signers;
41// These 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#[cfg(not(target_os = "solana"))]
44pub use solana_program::program_stubs;
45pub use solana_program::{
46 account_info, address_lookup_table_account, alt_bn128, big_mod_exp, blake3, borsh, bpf_loader,
47 bpf_loader_deprecated, bpf_loader_upgradeable, clock, config, custom_heap_default,
48 custom_panic_default, debug_account_data, declare_deprecated_sysvar_id, declare_sysvar_id,
49 decode_error, ed25519_program, epoch_schedule, fee_calculator, impl_sysvar_get, incinerator,
50 instruction, keccak, lamports, loader_instruction, loader_upgradeable_instruction, message,
51 msg, native_token, nonce, program, program_error, program_memory, program_option, program_pack,
52 rent, sanitize, sdk_ids, secp256k1_program, secp256k1_recover, serde_varint, serialize_utils,
53 short_vec, slot_hashes, slot_history, stable_layout, stake, stake_history, syscalls,
54 system_instruction, system_program, sysvar, unchecked_div_by_const, vote, wasm_bindgen,
55};
56
57pub mod account;
58pub mod account_utils;
59pub mod builtins;
60pub mod client;
61pub mod commitment_config;
62pub mod compute_budget;
63pub mod derivation_path;
64pub mod deserialize_utils;
65pub mod ed25519_instruction;
66pub mod entrypoint;
67pub mod entrypoint_deprecated;
68pub mod epoch_info;
69pub mod example_mocks;
70pub mod exit;
71pub mod feature;
72pub mod feature_set;
73pub mod fee;
74pub mod genesis_config;
75pub mod hard_forks;
76pub mod hash;
77pub mod inflation;
78pub mod log;
79pub mod native_loader;
80pub mod nonce_account;
81pub mod offchain_message;
82pub mod packet;
83pub mod poh_config;
84pub mod precompiles;
85pub mod program_utils;
86pub mod pubkey;
87pub mod quic;
88pub mod recent_blockhashes_account;
89pub mod reward_type;
90pub mod rpc_port;
91pub mod secp256k1_instruction;
92pub mod shred_version;
93pub mod signature;
94pub mod signer;
95pub mod system_transaction;
96pub mod timing;
97pub mod transaction;
98pub mod transaction_context;
99pub mod transport;
100pub mod wasm;
101
102/// Same as `declare_id` except report that this id has been deprecated.
103pub use solana_sdk_macro::declare_deprecated_id;
104/// Convenience macro to declare a static public key and functions to interact with it.
105///
106/// Input: a single literal base58 string representation of a program's id
107///
108/// # Example
109///
110/// ```
111/// # // wrapper is used so that the macro invocation occurs in the item position
112/// # // rather than in the statement position which isn't allowed.
113/// use std::str::FromStr;
114/// use solana_sdk::{declare_id, pubkey::Pubkey};
115///
116/// # mod item_wrapper {
117/// # use solana_sdk::declare_id;
118/// declare_id!("My11111111111111111111111111111111111111111");
119/// # }
120/// # use item_wrapper::id;
121///
122/// let my_id = Pubkey::from_str("My11111111111111111111111111111111111111111").unwrap();
123/// assert_eq!(id(), my_id);
124/// ```
125pub use solana_sdk_macro::declare_id;
126/// Convenience macro to define a static public key.
127///
128/// Input: a single literal base58 string representation of a Pubkey
129///
130/// # Example
131///
132/// ```
133/// use std::str::FromStr;
134/// use solana_program::{pubkey, pubkey::Pubkey};
135///
136/// static ID: Pubkey = pubkey!("My11111111111111111111111111111111111111111");
137///
138/// let my_id = Pubkey::from_str("My11111111111111111111111111111111111111111").unwrap();
139/// assert_eq!(ID, my_id);
140/// ```
141pub use solana_sdk_macro::pubkey;
142/// Convenience macro to define multiple static public keys.
143pub use solana_sdk_macro::pubkeys;
144#[rustversion::since(1.46.0)]
145pub use solana_sdk_macro::respan;
146
147// Unused `solana_sdk::program_stubs!()` macro retained for source backwards compatibility with older programs
148#[macro_export]
149#[deprecated(
150 since = "1.4.3",
151 note = "program_stubs macro is obsolete and can be safely removed"
152)]
153macro_rules! program_stubs {
154 () => {};
155}
156
157/// Convenience macro for `AddAssign` with saturating arithmetic.
158/// Replace by `std::num::Saturating` once stable
159#[macro_export]
160macro_rules! saturating_add_assign {
161 ($i:expr, $v:expr) => {{
162 $i = $i.saturating_add($v)
163 }};
164}
165
166#[macro_use]
167extern crate serde_derive;
168pub extern crate bs58;
169extern crate log as logger;
170
171#[macro_use]
172extern crate solana_frozen_abi_macro;
173
174#[cfg(test)]
175mod tests {
176 #[test]
177 fn test_saturating_add_assign() {
178 let mut i = 0u64;
179 let v = 1;
180 saturating_add_assign!(i, v);
181 assert_eq!(i, 1);
182
183 i = u64::MAX;
184 saturating_add_assign!(i, v);
185 assert_eq!(i, u64::MAX);
186 }
187}