diff --git a/Cargo.lock b/Cargo.lock index 04cd582c..91044b0e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -791,10 +791,17 @@ version = "1.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "74233d3b3b2f6d4b006dc19dee745e73e2a6bfb6f93607cd3b02bd5b00797d7c" +[[package]] +name = "soroban-alloc-contract" +version = "0.0.0" +dependencies = [ + "soroban-sdk", +] + [[package]] name = "soroban-auth" -version = "0.4.1" -source = "git+https://github.com/stellar/rs-soroban-sdk?rev=980778e#980778ecc78e57178fd0226fed25b341a17c1eac" +version = "0.4.2" +source = "git+https://github.com/stellar/rs-soroban-sdk?rev=135c3c8#135c3c8ec99d6288d722eaf1977c11671d09fe62" dependencies = [ "ed25519-dalek", "rand 0.7.3", @@ -940,8 +947,8 @@ dependencies = [ [[package]] name = "soroban-ledger-snapshot" -version = "0.4.1" -source = "git+https://github.com/stellar/rs-soroban-sdk?rev=980778e#980778ecc78e57178fd0226fed25b341a17c1eac" +version = "0.4.2" +source = "git+https://github.com/stellar/rs-soroban-sdk?rev=135c3c8#135c3c8ec99d6288d722eaf1977c11671d09fe62" dependencies = [ "serde", "serde_json", @@ -986,8 +993,8 @@ dependencies = [ [[package]] name = "soroban-sdk" -version = "0.4.1" -source = "git+https://github.com/stellar/rs-soroban-sdk?rev=980778e#980778ecc78e57178fd0226fed25b341a17c1eac" +version = "0.4.2" +source = "git+https://github.com/stellar/rs-soroban-sdk?rev=135c3c8#135c3c8ec99d6288d722eaf1977c11671d09fe62" dependencies = [ "bytes-lit", "ed25519-dalek", @@ -1001,8 +1008,8 @@ dependencies = [ [[package]] name = "soroban-sdk-macros" -version = "0.4.1" -source = "git+https://github.com/stellar/rs-soroban-sdk?rev=980778e#980778ecc78e57178fd0226fed25b341a17c1eac" +version = "0.4.2" +source = "git+https://github.com/stellar/rs-soroban-sdk?rev=135c3c8#135c3c8ec99d6288d722eaf1977c11671d09fe62" dependencies = [ "darling", "itertools", @@ -1041,8 +1048,8 @@ dependencies = [ [[package]] name = "soroban-spec" -version = "0.4.1" -source = "git+https://github.com/stellar/rs-soroban-sdk?rev=980778e#980778ecc78e57178fd0226fed25b341a17c1eac" +version = "0.4.2" +source = "git+https://github.com/stellar/rs-soroban-sdk?rev=135c3c8#135c3c8ec99d6288d722eaf1977c11671d09fe62" dependencies = [ "base64", "darling", diff --git a/Cargo.toml b/Cargo.toml index 1940fd2f..69fb5722 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,6 +22,7 @@ members = [ "logging", "errors", "wallet", + "alloc", ] [profile.release-with-logs] @@ -39,11 +40,11 @@ codegen-units = 1 lto = true [workspace.dependencies.soroban-sdk] -version = "0.4.1" +version = "0.4.2" git = "https://github.com/stellar/rs-soroban-sdk" -rev = "980778e" +rev = "135c3c8" [workspace.dependencies.soroban-auth] -version = "0.4.1" +version = "0.4.2" git = "https://github.com/stellar/rs-soroban-sdk" -rev = "980778e" +rev = "135c3c8" diff --git a/alloc/Cargo.toml b/alloc/Cargo.toml new file mode 100644 index 00000000..535c6fe5 --- /dev/null +++ b/alloc/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "soroban-alloc-contract" +version = "0.0.0" +authors = ["Stellar Development Foundation "] +license = "Apache-2.0" +edition = "2021" +publish = false + +[lib] +crate-type = ["cdylib"] +doctest = false + +[dependencies] +soroban-sdk = { workspace = true, features = ["alloc"] } + +[dev_dependencies] +soroban-sdk = { workspace = true, features = ["testutils", "alloc"] } diff --git a/alloc/src/lib.rs b/alloc/src/lib.rs new file mode 100644 index 00000000..e2da0b1e --- /dev/null +++ b/alloc/src/lib.rs @@ -0,0 +1,24 @@ +#![no_std] +use soroban_sdk::{contractimpl, Env}; + +extern crate alloc; + +pub struct AllocContract; + +#[contractimpl] +impl AllocContract { + /// Allocates a temporary vector holding values (0..count), then computes and returns their sum. + pub fn sum(_env: Env, count: u32) -> u32 { + let mut v1 = alloc::vec![]; + (0..count).for_each(|i| v1.push(i)); + + let mut sum = 0; + for i in v1 { + sum += i; + } + + sum + } +} + +mod test; diff --git a/alloc/src/test.rs b/alloc/src/test.rs new file mode 100644 index 00000000..f7df9f10 --- /dev/null +++ b/alloc/src/test.rs @@ -0,0 +1,18 @@ +#![cfg(test)] + +use super::{AllocContract, AllocContractClient}; +use soroban_sdk::{testutils::Logger, Env}; + +extern crate std; + +#[test] +fn test() { + let env = Env::default(); + let contract_id = env.register_contract(None, AllocContract); + let client = AllocContractClient::new(&env, &contract_id); + assert_eq!(client.sum(&1), 0); + assert_eq!(client.sum(&2), 1); + assert_eq!(client.sum(&5), 10); + + std::println!("{}", env.logger().all().join("\n")); +}