1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
//! Soroban SDK supports writing programs for the Soroban smart contract
//! platform.
//!
//! ### Docs
//!
//! See [soroban.stellar.org](https://soroban.stellar.org) for documentation.
//!
//! ### Examples
//!
//! ```
//! use soroban_sdk::{contractimpl, symbol, vec, BytesN, Env, Symbol, Vec};
//!
//! pub struct HelloContract;
//!
//! #[contractimpl]
//! impl HelloContract {
//! pub fn hello(env: Env, to: Symbol) -> Vec<Symbol> {
//! vec![&env, symbol!("Hello"), to]
//! }
//! }
//!
//! #[test]
//! fn test() {
//! # }
//! # #[cfg(feature = "testutils")]
//! # fn main() {
//! let env = Env::default();
//! let contract_id = BytesN::from_array(&env, &[0; 32]);
//! env.register_contract(&contract_id, HelloContract);
//! let client = HelloContractClient::new(&env, &contract_id);
//!
//! let words = client.hello(&symbol!("Dev"));
//!
//! assert_eq!(words, vec![&env, symbol!("Hello"), symbol!("Dev"),]);
//! }
//! # #[cfg(not(feature = "testutils"))]
//! # fn main() { }
//! ```
//!
//! More examples are available at <https://soroban.stellar.org/docs/category/examples>.
#![cfg_attr(target_family = "wasm", no_std)]
#![cfg_attr(feature = "docs", feature(doc_cfg))]
#![allow(dead_code)]
#[cfg(target_family = "wasm")]
#[panic_handler]
fn handle_panic(_: &core::panic::PanicInfo) -> ! {
core::arch::wasm32::unreachable()
}
/// __link_sections returns and does nothing, but it contains link sections that
/// should be ensured end up in the final build of any contract using the SDK.
///
/// In Rust's build system sections only get included into the final build if
/// the object file containing those sections are processed by the linker, but
/// as an optimization step if no code is called in an object file it is
/// discarded. This has the unfortunate effect of causing anything else in
/// those object files, such as link sections, to be discarded. Placing anything
/// that must be included in the build inside an exported function ensures the
/// object files won't be discarded. wasm-bindgen does a similar thing to this,
/// and so this seems to be a reasonably accepted way to work around this
/// limitation in the build system.
///
/// This has an unfortunate side-effect that all contracts will have a function
/// in the resulting WASM named `_`, however this function won't be rendered in
/// the contract specification. The overhead of this is very minimal on file
/// size.
///
/// See https://github.com/stellar/rs-soroban-sdk/issues/383 for more details.
#[export_name = "_"]
fn __link_sections() {
#[cfg_attr(target_family = "wasm", link_section = "contractenvmetav0")]
static __ENV_META_XDR: [u8; env::meta::XDR.len()] = env::meta::XDR;
}
pub use soroban_sdk_macros::{
contractclient, contractfile, contractimpl, contractimport, contracttype,
};
mod env;
pub mod xdr;
pub use env::ConversionError;
pub use env::Env;
/// Raw value of the Soroban smart contract platform that types can be converted
/// to and from for storing, or passing between contracts.
///
pub use env::RawVal;
/// Used to do conversions between values in the Soroban environment.
pub use env::FromVal;
/// Used to do conversions between values in the Soroban environment.
pub use env::IntoVal;
/// Used to do conversions between values in the Soroban environment.
pub use env::TryFromVal;
/// Used to do conversions between values in the Soroban environment.
pub use env::TryIntoVal;
pub use env::Symbol;
mod envhidden {
pub use super::env::EnvVal;
pub use super::env::Object;
pub use super::env::Status;
}
#[doc(hidden)]
pub use envhidden::*;
mod operators;
mod account;
mod bigint;
mod bytes;
mod contract_data;
pub mod deploy;
mod events;
pub mod iter;
mod ledger;
mod map;
mod set;
mod symbol;
mod vec;
pub use account::Account;
pub use bigint::{BigInt, Sign};
#[allow(deprecated)]
pub use bytes::{Binary, FixedBinary};
pub use bytes::{Bytes, BytesN};
pub use contract_data::ContractData;
pub use events::Events;
pub use ledger::Ledger;
pub use map::Map;
pub use set::Set;
pub use vec::Vec;
pub mod serde;
pub mod testutils;