rialo-s-sdk 0.12.2

Solana SDK
//! The Solana host and client SDK.
//!
//! This is the base library for all off-chain programs that interact with
//! Solana or otherwise operate on Solana data structures. On-chain programs
//! instead use the [`solana-program`] crate, the modules of which are
//! re-exported by this crate, like the relationship between the Rust
//! `core` and `std` crates. As much of the functionality of this crate is
//! provided by `solana-program`, see that crate's documentation for an
//! overview.
//!
//! [`solana-program`]: https://docs.rs/solana-program
//!
//! Many of the modules in this crate are primarily of use to the Solana runtime
//! itself. Additional crates provide capabilities built on `solana-sdk`, and
//! many programs will need to link to those crates as well, particularly for
//! clients communicating with Solana nodes over RPC.
//!
//! Such crates include:
//!
//! - [`solana-client`] - For interacting with a Solana node via the [JSON-RPC API][json].
//! - [`solana-cli-config`] - Loading and saving the Solana CLI configuration file.
//! - [`solana-clap-utils`] - Routines for setting up the CLI using [`clap`], as
//!   used by the Solana CLI. Includes functions for loading all types of
//!   signers supported by the CLI.
//!
//! [`solana-client`]: https://docs.rs/solana-client
//! [`solana-cli-config`]: https://docs.rs/solana-cli-config
//! [`solana-clap-utils`]: https://docs.rs/solana-clap-utils
//! [json]: https://solana.com/docs/rpc
//! [`clap`]: https://docs.rs/clap

#![cfg_attr(docsrs, feature(doc_auto_cfg))]

// Allows macro expansion of `use ::rialo_s_sdk::*` to work within this crate
extern crate self as rialo_s_sdk;

#[cfg(not(target_os = "solana"))]
pub use rialo_s_program::program_stubs;
// These rialo_s_program imports could be *-imported, but that causes a bunch of
// confusing duplication in the docs due to a rustdoc bug. #26211
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
pub use rialo_s_program::wasm_bindgen;
pub use rialo_s_program::{
    account_info, bpf_loader, bpf_loader_deprecated, clock, config, custom_heap_default,
    custom_panic_default, debug_account_data, ed25519_program, impl_sysvar_get, incinerator,
    instruction, msg, native_token, nonce, program, program_error, program_option, rent,
    secp256k1_program, syscalls, system_instruction, system_program, sysvar,
    unchecked_div_by_const,
};
pub mod entrypoint;
pub mod example_mocks;
pub mod feature;
pub mod hash;
pub mod log;
pub mod native_loader;
pub mod net;
pub mod program_utils;
pub mod pubkey;
pub mod rpc_port;
pub mod signature;
pub mod signer;
pub mod transaction;
pub mod transport;
pub mod v0_message_utils;
pub mod wasm;

#[deprecated(since = "2.1.0", note = "Use `solana-account` crate instead")]
pub use rialo_s_account as account;
/// Same as `declare_id` except report that this id has been deprecated.
pub use rialo_s_sdk_macro::declare_deprecated_id;
/// Convenience macro to declare a static public key and functions to interact with it.
///
/// Input: a single literal base58 string representation of a program's id
///
/// # Example
///
/// ```
/// # // wrapper is used so that the macro invocation occurs in the item position
/// # // rather than in the statement position which isn't allowed.
/// use std::str::FromStr;
/// use rialo_s_sdk::{declare_id, pubkey::Pubkey};
///
/// # mod item_wrapper {
/// #   use rialo_s_sdk::declare_id;
/// declare_id!("My11111111111111111111111111111111111111111");
/// # }
/// # use item_wrapper::id;
///
/// let my_id = Pubkey::from_str("My11111111111111111111111111111111111111111").unwrap();
/// assert_eq!(id(), my_id);
/// ```
pub use rialo_s_sdk_macro::declare_id;
/// Convenience macro to define multiple static public keys.
pub use rialo_s_sdk_macro::pubkeys;

/// Convenience macro for `AddAssign` with saturating arithmetic.
/// Replace by `std::num::Saturating` once stable
#[macro_export]
macro_rules! saturating_add_assign {
    ($i:expr, $v:expr) => {{
        $i = $i.saturating_add($v)
    }};
}

pub use bs58;

#[cfg(test)]
mod tests {
    #[test]
    fn test_saturating_add_assign() {
        let mut i = 0u64;
        let v = 1;
        saturating_add_assign!(i, v);
        assert_eq!(i, 1);

        i = u64::MAX;
        saturating_add_assign!(i, v);
        assert_eq!(i, u64::MAX);
    }
}