2021-03-26 16:45:45 -07:00
|
|
|
#![allow(incomplete_features)]
|
2020-06-03 04:51:56 -07:00
|
|
|
#![cfg_attr(RUSTC_WITH_SPECIALIZATION, feature(specialization))]
|
2020-07-14 11:06:01 -07:00
|
|
|
#![cfg_attr(RUSTC_NEEDS_PROC_MACRO_HYGIENE, feature(proc_macro_hygiene))]
|
2020-06-03 04:51:56 -07:00
|
|
|
|
2019-12-03 17:55:18 -08:00
|
|
|
// Allows macro expansion of `use ::solana_sdk::*` to work within this crate
|
|
|
|
extern crate self as solana_sdk;
|
|
|
|
|
2021-05-07 01:33:37 -07:00
|
|
|
#[cfg(feature = "full")]
|
|
|
|
pub use signer::signers;
|
2020-10-23 17:22:10 -07:00
|
|
|
pub use solana_program::*;
|
2020-10-19 13:19:24 -07:00
|
|
|
|
2020-10-28 22:01:07 -07:00
|
|
|
pub mod account;
|
|
|
|
pub mod account_utils;
|
2020-08-14 12:32:45 -07:00
|
|
|
pub mod builtins;
|
2020-10-19 13:19:24 -07:00
|
|
|
pub mod client;
|
2020-01-08 13:49:35 -08:00
|
|
|
pub mod commitment_config;
|
2021-07-16 00:31:22 -07:00
|
|
|
pub mod compute_budget;
|
2021-04-16 15:03:24 -07:00
|
|
|
pub mod derivation_path;
|
2020-09-30 10:49:35 -07:00
|
|
|
pub mod deserialize_utils;
|
2021-09-03 14:35:38 -07:00
|
|
|
pub mod ed25519_instruction;
|
2020-10-19 13:19:24 -07:00
|
|
|
pub mod entrypoint;
|
|
|
|
pub mod entrypoint_deprecated;
|
2020-05-20 16:42:46 -07:00
|
|
|
pub mod epoch_info;
|
2022-01-21 17:30:12 -08:00
|
|
|
pub mod example_mocks;
|
2021-06-03 20:06:13 -07:00
|
|
|
pub mod exit;
|
2020-10-28 20:21:50 -07:00
|
|
|
pub mod feature;
|
|
|
|
pub mod feature_set;
|
2022-02-11 16:23:16 -08:00
|
|
|
pub mod fee;
|
2020-10-19 13:19:24 -07:00
|
|
|
pub mod genesis_config;
|
|
|
|
pub mod hard_forks;
|
2019-09-06 15:33:58 -07:00
|
|
|
pub mod hash;
|
|
|
|
pub mod inflation;
|
2020-10-26 09:14:57 -07:00
|
|
|
pub mod keyed_account;
|
2020-10-19 13:19:24 -07:00
|
|
|
pub mod log;
|
2019-09-06 15:33:58 -07:00
|
|
|
pub mod native_loader;
|
2020-10-28 22:01:07 -07:00
|
|
|
pub mod nonce_account;
|
2019-12-10 23:19:13 -08:00
|
|
|
pub mod packet;
|
2019-09-06 15:33:58 -07:00
|
|
|
pub mod poh_config;
|
2021-09-17 11:36:57 -07:00
|
|
|
pub mod precompiles;
|
2020-02-05 12:48:30 -08:00
|
|
|
pub mod program_utils;
|
2019-09-09 16:38:52 -07:00
|
|
|
pub mod pubkey;
|
2022-02-04 06:27:09 -08:00
|
|
|
pub mod quic;
|
2020-10-28 22:01:07 -07:00
|
|
|
pub mod recent_blockhashes_account;
|
2019-09-06 15:33:58 -07:00
|
|
|
pub mod rpc_port;
|
2020-11-12 16:58:40 -08:00
|
|
|
pub mod secp256k1_instruction;
|
2020-10-19 13:19:24 -07:00
|
|
|
pub mod shred_version;
|
|
|
|
pub mod signature;
|
2021-05-06 23:51:52 -07:00
|
|
|
pub mod signer;
|
2020-10-19 13:19:24 -07:00
|
|
|
pub mod system_transaction;
|
2019-09-06 15:33:58 -07:00
|
|
|
pub mod timing;
|
2020-10-19 13:19:24 -07:00
|
|
|
pub mod transaction;
|
2021-12-27 09:49:32 -08:00
|
|
|
pub mod transaction_context;
|
2020-10-19 13:19:24 -07:00
|
|
|
pub mod transport;
|
2021-10-13 16:52:52 -07:00
|
|
|
pub mod wasm;
|
2019-09-09 16:38:52 -07:00
|
|
|
|
2021-07-26 20:54:46 -07:00
|
|
|
/// Same as `declare_id` except report that this id has been deprecated
|
|
|
|
pub use solana_sdk_macro::declare_deprecated_id;
|
2019-12-03 17:55:18 -08:00
|
|
|
/// 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 solana_sdk::{declare_id, pubkey::Pubkey};
|
|
|
|
///
|
|
|
|
/// # mod item_wrapper {
|
|
|
|
/// # use solana_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 solana_sdk_macro::declare_id;
|
2021-11-15 11:22:51 -08:00
|
|
|
/// Convenience macro to define a static public key
|
|
|
|
///
|
|
|
|
/// Input: a single literal base58 string representation of a Pubkey
|
|
|
|
///
|
|
|
|
/// # Example
|
|
|
|
///
|
|
|
|
/// ```
|
|
|
|
/// use std::str::FromStr;
|
|
|
|
/// use solana_program::{pubkey, pubkey::Pubkey};
|
|
|
|
///
|
|
|
|
/// static ID: Pubkey = pubkey!("My11111111111111111111111111111111111111111");
|
|
|
|
///
|
|
|
|
/// let my_id = Pubkey::from_str("My11111111111111111111111111111111111111111").unwrap();
|
|
|
|
/// assert_eq!(ID, my_id);
|
|
|
|
/// ```
|
|
|
|
pub use solana_sdk_macro::pubkey;
|
2020-05-09 11:05:29 -07:00
|
|
|
pub use solana_sdk_macro::pubkeys;
|
Fix hygiene issues in `declare_program!` and `declare_loader!`
The `declare_program!` and `declare_loader!` macros both expand to
new macro definitions (based on the `$name` argument). These 'inner'
macros make use of the special `$crate` metavariable to access items in
the crate where the 'inner' macros is defined.
However, this only works due to a bug in rustc. When a macro is
expanded, all `$crate` tokens in its output are 'marked' as being
resolved in the defining crate of that macro. An inner macro (including
the body of its arms) is 'just' another set of tokens that appears in
the body of the outer macro, so any `$crate` identifiers used there are
resolved relative to the 'outer' macro.
For example, consider the following code:
```rust
macro_rules! outer {
() => {
macro_rules! inner {
() => {
$crate::Foo
}
}
}
}
```
The path `$crate::Foo` will be resolved relative to the crate that defines `outer`,
**not** the crate which defines `inner`.
However, rustc currently loses this extra resolution information
(referred to as 'hygiene' information) when a crate is serialized.
In the above example, this means that the macro `inner` (which gets
defined in whatever crate invokes `outer!`) will behave differently
depending on which crate it is invoked from:
When `inner` is invoked from the same crate in which it is defined,
the hygiene information will still be available,
which will cause `$crate::Foo` to be resolved in the crate which defines 'outer'.
When `inner` is invoked from a different crate, it will be loaded from
the metadata of the crate which defines 'inner'. Since the hygiene
information is currently lost, rust will 'forget' that `$crate::Foo` is
supposed to be resolved in the context of 'outer'. Instead, it will be
resolved relative to the crate which defines 'inner', which can cause
incorrect code to compile.
This bug will soon be fixed in rust (see https://github.com/rust-lang/rust/pull/72121),
which will break `declare_program!` and `declare_loader!`. Fortunately,
it's possible to obtain the desired behavior (`$crate` resolving in the
context of the 'inner' macro) by use of a procedural macro.
This commit adds a `respan!` proc-macro to the `sdk/macro` crate.
Using the newly-stabilized (on Nightly) `Span::resolved_at` method,
the `$crate` identifier can be made to be resolved in the context of the
proper crate.
Since `Span::resolved_at` is only stable on the latest nightly,
referencing it on an earlier version of Rust will cause a compilation error.
This requires the `rustversion` crate to be used, which allows conditionally
compiling code epending on the Rust compiler version in use. Since this method is already
stabilized in the latest nightly, there will never be a situation where
the hygiene bug is fixed (e.g. https://github.com/rust-lang/rust/pull/72121)
is merged but we are unable to call `Span::resolved_at`.
2020-06-19 22:42:11 -07:00
|
|
|
#[rustversion::since(1.46.0)]
|
|
|
|
pub use solana_sdk_macro::respan;
|
2019-12-03 17:55:18 -08:00
|
|
|
|
2022-02-23 18:44:43 -08:00
|
|
|
#[deprecated(
|
|
|
|
since = "1.9.0",
|
|
|
|
note = "use only to break https://github.com/rust-lang/rust/issues/92987. remove when we move to Rust 1.60.0"
|
|
|
|
)]
|
|
|
|
#[doc(hidden)]
|
|
|
|
#[cfg(debug_assertions)]
|
|
|
|
pub trait AutoTraitBreakSendSync: Send + Sync {}
|
|
|
|
|
2020-10-19 13:19:24 -07:00
|
|
|
// Unused `solana_sdk::program_stubs!()` macro retained for source backwards compatibility with older programs
|
2020-10-16 22:04:53 -07:00
|
|
|
#[macro_export]
|
|
|
|
#[deprecated(
|
2020-10-19 13:19:24 -07:00
|
|
|
since = "1.4.3",
|
2020-10-16 22:04:53 -07:00
|
|
|
note = "program_stubs macro is obsolete and can be safely removed"
|
|
|
|
)]
|
|
|
|
macro_rules! program_stubs {
|
|
|
|
() => {};
|
|
|
|
}
|
|
|
|
|
2022-01-05 14:56:39 -08:00
|
|
|
/// 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)
|
|
|
|
}};
|
|
|
|
}
|
|
|
|
|
2018-09-27 07:49:26 -07:00
|
|
|
#[macro_use]
|
|
|
|
extern crate serde_derive;
|
2019-11-21 16:34:40 -08:00
|
|
|
pub extern crate bs58;
|
2019-11-14 10:24:53 -08:00
|
|
|
extern crate log as logger;
|
2020-06-03 04:51:56 -07:00
|
|
|
|
|
|
|
#[macro_use]
|
2020-10-19 21:07:46 -07:00
|
|
|
extern crate solana_frozen_abi_macro;
|
2022-01-05 14:56:39 -08:00
|
|
|
|
|
|
|
#[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);
|
|
|
|
}
|
|
|
|
}
|