solana_sdk/
lib.rs

1#![allow(incomplete_features)]
2#![cfg_attr(RUSTC_WITH_SPECIALIZATION, feature(specialization))]
3#![cfg_attr(RUSTC_NEEDS_PROC_MACRO_HYGIENE, feature(proc_macro_hygiene))]
4
5// Allows macro expansion of `use ::solana_sdk::*` to work within this crate
6extern crate self as solana_sdk;
7
8#[cfg(feature = "full")]
9pub use signer::signers;
10pub use solana_program::*;
11
12pub mod account;
13pub mod account_utils;
14pub mod builtins;
15pub mod client;
16pub mod commitment_config;
17pub mod compute_budget;
18pub mod derivation_path;
19pub mod deserialize_utils;
20pub mod ed25519_instruction;
21pub mod entrypoint;
22pub mod entrypoint_deprecated;
23pub mod epoch_info;
24pub mod example_mocks;
25pub mod exit;
26pub mod feature;
27pub mod feature_set;
28pub mod fee;
29pub mod genesis_config;
30pub mod hard_forks;
31pub mod hash;
32pub mod inflation;
33pub mod keyed_account;
34pub mod log;
35pub mod native_loader;
36pub mod nonce_account;
37pub mod packet;
38pub mod poh_config;
39pub mod precompiles;
40pub mod program_utils;
41pub mod pubkey;
42pub mod quic;
43pub mod recent_blockhashes_account;
44pub mod reward_type;
45pub mod rpc_port;
46pub mod secp256k1_instruction;
47pub mod shred_version;
48pub mod signature;
49pub mod signer;
50pub mod system_transaction;
51pub mod timing;
52pub mod transaction;
53pub mod transaction_context;
54pub mod transport;
55pub mod wasm;
56
57/// Same as `declare_id` except report that this id has been deprecated
58pub use solana_sdk_macro::declare_deprecated_id;
59/// Convenience macro to declare a static public key and functions to interact with it
60///
61/// Input: a single literal base58 string representation of a program's id
62///
63/// # Example
64///
65/// ```
66/// # // wrapper is used so that the macro invocation occurs in the item position
67/// # // rather than in the statement position which isn't allowed.
68/// use std::str::FromStr;
69/// use solana_sdk::{declare_id, pubkey::Pubkey};
70///
71/// # mod item_wrapper {
72/// #   use solana_sdk::declare_id;
73/// declare_id!("My11111111111111111111111111111111111111111");
74/// # }
75/// # use item_wrapper::id;
76///
77/// let my_id = Pubkey::from_str("My11111111111111111111111111111111111111111").unwrap();
78/// assert_eq!(id(), my_id);
79/// ```
80pub use solana_sdk_macro::declare_id;
81/// Convenience macro to define a static public key
82///
83/// Input: a single literal base58 string representation of a Pubkey
84///
85/// # Example
86///
87/// ```
88/// use std::str::FromStr;
89/// use solana_program::{pubkey, pubkey::Pubkey};
90///
91/// static ID: Pubkey = pubkey!("My11111111111111111111111111111111111111111");
92///
93/// let my_id = Pubkey::from_str("My11111111111111111111111111111111111111111").unwrap();
94/// assert_eq!(ID, my_id);
95/// ```
96pub use solana_sdk_macro::pubkey;
97pub use solana_sdk_macro::pubkeys;
98#[rustversion::since(1.46.0)]
99pub use solana_sdk_macro::respan;
100
101// Unused `solana_sdk::program_stubs!()` macro retained for source backwards compatibility with older programs
102#[macro_export]
103#[deprecated(
104    since = "1.4.3",
105    note = "program_stubs macro is obsolete and can be safely removed"
106)]
107macro_rules! program_stubs {
108    () => {};
109}
110
111/// Convenience macro for `AddAssign` with saturating arithmetic.
112/// Replace by `std::num::Saturating` once stable
113#[macro_export]
114macro_rules! saturating_add_assign {
115    ($i:expr, $v:expr) => {{
116        $i = $i.saturating_add($v)
117    }};
118}
119
120#[macro_use]
121extern crate serde_derive;
122pub extern crate bs58;
123extern crate log as logger;
124
125#[macro_use]
126extern crate safecoin_frozen_abi_macro;
127
128#[cfg(test)]
129mod tests {
130    #[test]
131    fn test_saturating_add_assign() {
132        let mut i = 0u64;
133        let v = 1;
134        saturating_add_assign!(i, v);
135        assert_eq!(i, 1);
136
137        i = u64::MAX;
138        saturating_add_assign!(i, v);
139        assert_eq!(i, u64::MAX);
140    }
141}