Skip to content

Commit

Permalink
Support for constructor-related functionality in Soroban SDK.
Browse files Browse the repository at this point in the history
The main non-test changes are updates for the auth-related data structures and a wrapper for the new deployer function (create_contract_with_constructor).

The remaining changes concern the test infrastructure support, specifically contract creation utilities that support passing constructor arguments.
  • Loading branch information
dmkozh committed Sep 6, 2024
1 parent f57d245 commit a7ac4f4
Show file tree
Hide file tree
Showing 127 changed files with 5,191 additions and 228 deletions.
131 changes: 98 additions & 33 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 14 additions & 14 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ members = [

[workspace.package]
version = "21.6.0"
rust-version = "1.74.0"
rust-version = "1.79.0"

[workspace.dependencies]
soroban-sdk = { version = "21.6.0", path = "soroban-sdk" }
Expand All @@ -24,34 +24,34 @@ soroban-ledger-snapshot = { version = "21.6.0", path = "soroban-ledger-snapshot"
soroban-token-sdk = { version = "21.6.0", path = "soroban-token-sdk" }

[workspace.dependencies.soroban-env-common]
version = "=21.2.1"
# git = "https://github.com/stellar/rs-soroban-env"
# rev = "0c918ac2bd808ba1a850281c6b1c731e7fe50c53"
version = "=22.0.0"
git = "https://github.com/stellar/rs-soroban-env"
rev = "75b782119942a4c8be8003f2901db38b30b6db2d"

[workspace.dependencies.soroban-env-guest]
version = "=21.2.1"
# git = "https://github.com/stellar/rs-soroban-env"
# rev = "0c918ac2bd808ba1a850281c6b1c731e7fe50c53"
version = "=22.0.0"
git = "https://github.com/stellar/rs-soroban-env"
rev = "75b782119942a4c8be8003f2901db38b30b6db2d"

[workspace.dependencies.soroban-env-host]
version = "=21.2.1"
# git = "https://github.com/stellar/rs-soroban-env"
# rev = "0c918ac2bd808ba1a850281c6b1c731e7fe50c53"
version = "=22.0.0"
git = "https://github.com/stellar/rs-soroban-env"
rev = "75b782119942a4c8be8003f2901db38b30b6db2d"

[workspace.dependencies.stellar-strkey]
version = "=0.0.8"

[workspace.dependencies.stellar-xdr]
version = "=21.2.0"
version = "=22.0.0"
default-features = false
features = ["curr"]
# git = "https://github.com/stellar/rs-stellar-xdr"
# rev = "d0138770652a615e3cd99447f2f2727658c17450"
git = "https://github.com/stellar/rs-stellar-xdr"
rev = "39d7dbb0c12bd422ee43a6e2e3277789da4eaac8"

#[patch."https://github.com/stellar/rs-soroban-env"]
#soroban-env-common = { path = "../rs-soroban-env/soroban-env-common" }
#soroban-env-guest = { path = "../rs-soroban-env/soroban-env-guest" }
#soroban-env-host = { path = "../rs-soroban-env/soroban-env-host/" }
#soroban-env-host = { path = "../rs-soroban-env/soroban-env-host" }
#[patch."https://github.com/stellar/rs-stellar-xdr"]
#stellar-xdr = { path = "../rs-stellar-xdr/" }

Expand Down
2 changes: 1 addition & 1 deletion soroban-ledger-snapshot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl LedgerSnapshot {
impl Default for LedgerSnapshot {
fn default() -> Self {
Self {
protocol_version: 20,
protocol_version: 22,
sequence_number: Default::default(),
timestamp: Default::default(),
network_id: Default::default(),
Expand Down
4 changes: 4 additions & 0 deletions soroban-sdk-macros/src/derive_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ pub fn derive_pub_fn(
quote! {}
};
let slice_args: Vec<TokenStream2> = (0..wrap_args.len()).map(|n| quote! { args[#n] }).collect();
let arg_count = slice_args.len();
let use_trait = if let Some(t) = trait_ident {
quote! { use super::#t }
} else {
Expand Down Expand Up @@ -150,6 +151,9 @@ pub fn derive_pub_fn(
env: #crate_path::Env,
args: &[#crate_path::Val],
) -> #crate_path::Val {
if args.len() != #arg_count {
panic!("invalid number of input arguments: {} expected, got {}", #arg_count, args.len());
}
#[allow(deprecated)]
invoke_raw(env, #(#slice_args),*)
}
Expand Down
Binary file modified soroban-sdk/doctest_fixtures/contract.wasm
Binary file not shown.
Binary file not shown.
20 changes: 20 additions & 0 deletions soroban-sdk/src/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ use crate::{contracttype, crypto::Hash, Address, BytesN, Env, Error, Symbol, Val
#[derive(Clone)]
#[contracttype(crate_path = "crate", export = false)]
pub enum Context {
/// Contract invocation.
Contract(ContractContext),
/// Contract that has a constructor with no arguments is created.
CreateContractHostFn(CreateContractHostFnContext),
/// Contract that has a constructor with 1 or more arguments is created.
CreateContractWithCtorHostFn(CreateContractWithConstructorHostFnContext),
}

/// Authorization context of a single contract call.
Expand All @@ -35,6 +39,18 @@ pub struct CreateContractHostFnContext {
pub salt: BytesN<32>,
}

/// Authorization context for `create_contract` host function that creates a
/// new contract on behalf of authorizer address.
/// This is the same as `CreateContractHostFnContext`, but also has
/// contract constructor arguments.
#[derive(Clone)]
#[contracttype(crate_path = "crate", export = false)]
pub struct CreateContractWithConstructorHostFnContext {
pub executable: ContractExecutable,
pub salt: BytesN<32>,
pub constructor_args: Vec<Val>,
}

/// Contract executable used for creating a new contract and used in
/// `CreateContractHostFnContext`.
#[derive(Clone)]
Expand All @@ -53,8 +69,12 @@ pub enum ContractExecutable {
#[derive(Clone)]
#[contracttype(crate_path = "crate", export = false)]
pub enum InvokerContractAuthEntry {
/// Invoke a contract.
Contract(SubContractInvocation),
/// Create a contract passing 0 arguments to constructor.
CreateContractHostFn(CreateContractHostFnContext),
/// Create a contract passing 0 or more arguments to constructor.
CreateContractWithCtorHostFn(CreateContractWithConstructorHostFnContext),
}

/// Value of contract node in InvokerContractAuthEntry tree.
Expand Down
Loading

0 comments on commit a7ac4f4

Please sign in to comment.