miraland_sdk/lib.rs
1//! The Miraland host and client SDK.
2//!
3//! This is the base library for all off-chain programs that interact with
4//! Miraland or otherwise operate on Miraland data structures. On-chain programs
5//! instead use the [`miraland-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 `miraland-program`, see that crate's documentation for an
9//! overview.
10//!
11//! [`miraland-program`]: https://docs.rs/miraland-program
12//!
13//! Many of the modules in this crate are primarily of use to the Miraland runtime
14//! itself. Additional crates provide capabilities built on `miraland-sdk`, and
15//! many programs will need to link to those crates as well, particularly for
16//! clients communicating with Miraland nodes over RPC.
17//!
18//! Such crates include:
19//!
20//! - [`miraland-client`] - For interacting with a Miraland node via the [JSON-RPC API][json].
21//! - [`miraland-cli-config`] - Loading and saving the Miraland CLI configuration file.
22//! - [`miraland-clap-utils`] - Routines for setting up the CLI using [`clap`], as
23//! used by the Miraland CLI. Includes functions for loading all types of
24//! signers supported by the CLI.
25//!
26//! [`miraland-client`]: https://docs.rs/miraland-client
27//! [`miraland-cli-config`]: https://docs.rs/miraland-cli-config
28//! [`miraland-clap-utils`]: https://docs.rs/miraland-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 ::miraland_sdk::*` to work within this crate
37extern crate self as miraland_sdk;
38
39#[cfg(feature = "full")]
40pub use signer::signers;
41// These miraland_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 miraland_program::address_lookup_table_account;
45#[cfg(not(target_os = "solana"))]
46pub use miraland_program::program_stubs;
47pub use miraland_program::{
48 account_info, address_lookup_table, alt_bn128, big_mod_exp, blake3, borsh, borsh0_10, borsh0_9,
49 borsh1, bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable, clock, config,
50 custom_heap_default, custom_panic_default, debug_account_data, declare_deprecated_sysvar_id,
51 declare_sysvar_id, decode_error, ed25519_program, epoch_rewards, epoch_schedule,
52 fee_calculator, impl_sysvar_get, incinerator, instruction, keccak, lamports,
53 loader_instruction, loader_upgradeable_instruction, loader_v4, loader_v4_instruction, message,
54 msg, native_token, nonce, poseidon, program, program_error, program_memory, program_option,
55 program_pack, rent, sanitize, sdk_ids, secp256k1_program, secp256k1_recover, serde_varint,
56 serialize_utils, short_vec, slot_hashes, slot_history, stable_layout, stake, stake_history,
57 syscalls, system_instruction, system_program, sysvar, unchecked_div_by_const, vote,
58 wasm_bindgen,
59};
60
61pub mod account;
62pub mod account_utils;
63pub mod client;
64pub mod commitment_config;
65pub mod compute_budget;
66pub mod derivation_path;
67pub mod deserialize_utils;
68pub mod ed25519_instruction;
69pub mod entrypoint;
70pub mod entrypoint_deprecated;
71pub mod epoch_info;
72pub mod epoch_rewards_hasher;
73pub mod example_mocks;
74pub mod exit;
75pub mod feature;
76pub mod feature_set;
77pub mod fee;
78pub mod genesis_config;
79pub mod hard_forks;
80pub mod hash;
81pub mod inflation;
82pub mod inner_instruction;
83pub mod log;
84pub mod native_loader;
85pub mod net;
86pub mod nonce_account;
87pub mod nonce_info;
88pub mod offchain_message;
89pub mod packet;
90pub mod poh_config;
91pub mod precompiles;
92pub mod program_utils;
93pub mod pubkey;
94pub mod quic;
95pub mod recent_blockhashes_account;
96pub mod rent_collector;
97pub mod rent_debits;
98pub mod reward_info;
99pub mod reward_type;
100pub mod rpc_port;
101pub mod secp256k1_instruction;
102pub mod shred_version;
103pub mod signature;
104pub mod signer;
105pub mod simple_vote_transaction_checker;
106pub mod system_transaction;
107pub mod timing;
108pub mod transaction;
109pub mod transaction_context;
110pub mod transport;
111pub mod wasm;
112
113/// Same as `declare_id` except report that this id has been deprecated.
114pub use miraland_sdk_macro::declare_deprecated_id;
115/// Convenience macro to declare a static public key and functions to interact with it.
116///
117/// Input: a single literal base58 string representation of a program's id
118///
119/// # Example
120///
121/// ```
122/// # // wrapper is used so that the macro invocation occurs in the item position
123/// # // rather than in the statement position which isn't allowed.
124/// use std::str::FromStr;
125/// use miraland_sdk::{declare_id, pubkey::Pubkey};
126///
127/// # mod item_wrapper {
128/// # use miraland_sdk::declare_id;
129/// declare_id!("My11111111111111111111111111111111111111111");
130/// # }
131/// # use item_wrapper::id;
132///
133/// let my_id = Pubkey::from_str("My11111111111111111111111111111111111111111").unwrap();
134/// assert_eq!(id(), my_id);
135/// ```
136pub use miraland_sdk_macro::declare_id;
137/// Convenience macro to define a static public key.
138///
139/// Input: a single literal base58 string representation of a Pubkey
140///
141/// # Example
142///
143/// ```
144/// use std::str::FromStr;
145/// use miraland_program::{pubkey, pubkey::Pubkey};
146///
147/// static ID: Pubkey = pubkey!("My11111111111111111111111111111111111111111");
148///
149/// let my_id = Pubkey::from_str("My11111111111111111111111111111111111111111").unwrap();
150/// assert_eq!(ID, my_id);
151/// ```
152pub use miraland_sdk_macro::pubkey;
153/// Convenience macro to define multiple static public keys.
154pub use miraland_sdk_macro::pubkeys;
155#[rustversion::since(1.46.0)]
156pub use miraland_sdk_macro::respan;
157
158// Unused `miraland_sdk::program_stubs!()` macro retained for source backwards compatibility with older programs
159#[macro_export]
160#[deprecated(
161 since = "1.4.3",
162 note = "program_stubs macro is obsolete and can be safely removed"
163)]
164macro_rules! program_stubs {
165 () => {};
166}
167
168/// Convenience macro for `AddAssign` with saturating arithmetic.
169/// Replace by `std::num::Saturating` once stable
170#[macro_export]
171macro_rules! saturating_add_assign {
172 ($i:expr, $v:expr) => {{
173 $i = $i.saturating_add($v)
174 }};
175}
176
177#[macro_use]
178extern crate serde_derive;
179pub extern crate bs58;
180extern crate log as logger;
181
182#[macro_use]
183extern crate miraland_frozen_abi_macro;
184
185#[cfg(test)]
186mod tests {
187 #[test]
188 fn test_saturating_add_assign() {
189 let mut i = 0u64;
190 let v = 1;
191 saturating_add_assign!(i, v);
192 assert_eq!(i, 1);
193
194 i = u64::MAX;
195 saturating_add_assign!(i, v);
196 assert_eq!(i, u64::MAX);
197 }
198}