Skip to content

Commit

Permalink
Merge branch 'main' into arbitrary-for-upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
leighmcculloch committed Jun 16, 2023
2 parents ea350a0 + 6d4b0b5 commit 8b6210b
Show file tree
Hide file tree
Showing 44 changed files with 2,009 additions and 1,061 deletions.
47 changes: 34 additions & 13 deletions Cargo.lock

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

12 changes: 8 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ members = [
"soroban-sdk",
"soroban-sdk-macros",
"soroban-spec",
"soroban-spec-rust",
"soroban-spec-json",
"soroban-ledger-snapshot",
"soroban-token-sdk",
"tests/empty",
Expand All @@ -30,32 +32,34 @@ version = "0.8.4"
soroban-sdk = { version = "0.8.4", path = "soroban-sdk" }
soroban-sdk-macros = { version = "0.8.4", path = "soroban-sdk-macros" }
soroban-spec = { version = "0.8.4", path = "soroban-spec" }
soroban-spec-rust = { version = "0.8.4", path = "soroban-spec-rust" }
soroban-ledger-snapshot = { version = "0.8.4", path = "soroban-ledger-snapshot" }
soroban-token-sdk = { version = "0.8.4", path = "soroban-token-sdk" }

[workspace.dependencies.soroban-env-common]
version = "0.0.16"
git = "https://github.com/stellar/rs-soroban-env"
rev = "c09c5f1b9af1a60d93c881a545607a84d36b88d2"
rev = "e64000dfed0512ebcf398e65bd5534e898db5951"

[workspace.dependencies.soroban-env-guest]
version = "0.0.16"
git = "https://github.com/stellar/rs-soroban-env"
rev = "c09c5f1b9af1a60d93c881a545607a84d36b88d2"
rev = "e64000dfed0512ebcf398e65bd5534e898db5951"

[workspace.dependencies.soroban-env-host]
version = "0.0.16"
git = "https://github.com/stellar/rs-soroban-env"
rev = "c09c5f1b9af1a60d93c881a545607a84d36b88d2"
rev = "e64000dfed0512ebcf398e65bd5534e898db5951"

[workspace.dependencies.stellar-strkey]
version = "0.0.7"
git = "https://github.com/stellar/rs-stellar-strkey"
rev = "e6ba45c60c16de28c7522586b80ed0150157df73"

[workspace.dependencies.stellar-xdr]
version = "0.0.16"
git = "https://github.com/stellar/rs-stellar-xdr"
rev = "a2f370c930bb94f7bc0c9ea0426ecef3700b90a9"
rev = "60ea4cda01f1deba2ae7db5657e502e8f4381826"
default-features = false

#[patch."https://github.com/stellar/rs-soroban-env"]
Expand Down
6 changes: 6 additions & 0 deletions soroban-ledger-snapshot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ pub struct LedgerSnapshot {
pub timestamp: u64,
pub network_id: [u8; 32],
pub base_reserve: u32,
pub min_persistent_entry_expiration: u32,
pub min_temp_entry_expiration: u32,
pub ledger_entries: Vec<(Box<LedgerKey>, Box<LedgerEntry>)>,
}

Expand Down Expand Up @@ -70,6 +72,8 @@ impl LedgerSnapshot {
timestamp: self.timestamp,
network_id: self.network_id.clone(),
base_reserve: self.base_reserve,
min_persistent_entry_expiration: self.min_persistent_entry_expiration,
min_temp_entry_expiration: self.min_temp_entry_expiration,
}
}

Expand Down Expand Up @@ -158,6 +162,8 @@ impl Default for LedgerSnapshot {
network_id: Default::default(),
base_reserve: Default::default(),
ledger_entries: Vec::default(),
min_persistent_entry_expiration: Default::default(),
min_temp_entry_expiration: Default::default(),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions soroban-sdk-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ doctest = false

[dependencies]
soroban-spec = { workspace = true }
soroban-spec-rust = { workspace = true }
soroban-env-common = { workspace = true }
stellar-xdr = { workspace = true, features = ["next", "std"] }
syn = {version="2.0",features=["full"]}
Expand Down
2 changes: 1 addition & 1 deletion soroban-sdk-macros/src/derive_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ pub fn derive_type_enum(
use #path::{EnvBase,TryIntoVal,TryFromVal};
const CASES: &'static [&'static str] = &[#(#case_name_str_lits),*];
let vec: #path::Vec<#path::RawVal> = val.try_into_val(env)?;
let mut iter = vec.iter();
let mut iter = vec.try_iter();
let discriminant: #path::Symbol = iter.next().ok_or(#path::ConversionError)??.try_into_val(env).map_err(|_|#path::ConversionError)?;
Ok(match u32::from(env.symbol_index_in_strs(discriminant.to_val(), CASES)?) as usize {
#(#try_froms,)*
Expand Down
2 changes: 1 addition & 1 deletion soroban-sdk-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use syn::{
};
use syn_ext::HasFnsItem;

use soroban_spec::gen::rust::{generate_from_wasm, GenerateFromFileError};
use soroban_spec_rust::{generate_from_wasm, GenerateFromFileError};

use stellar_xdr::{ScMetaEntry, ScMetaV0, StringM, WriteXdr};

Expand Down
14 changes: 4 additions & 10 deletions soroban-sdk/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,11 +201,6 @@ impl Address {
/// will allow the contract callers to easily build the required signature
/// payloads and prevent potential authorization failures.
///
/// When called in the tests, the `require_auth` calls are just recorded and
/// no signatures are required. In order to make sure that the contract
/// has indeed called `require_auth` for this Address with expected arguments
/// use `env.verify_top_authorization`.
///
/// ### Panics
///
/// If the invocation is not authorized.
Expand Down Expand Up @@ -236,7 +231,10 @@ impl Address {
/// Prefer using the `Address` directly as input or output argument. Only
/// use this in special cases, for example to get an Address of a freshly
/// deployed contract.
pub(crate) fn from_contract_id(contract_id: &BytesN<32>) -> Self {
///
/// TODO: Replace this function in its pub form with a function that accepts
/// a strkey instead. Dependent on https://github.com/stellar/rs-stellar-strkey/issues/56.
pub fn from_contract_id(contract_id: &BytesN<32>) -> Self {
let env = contract_id.env();
unsafe {
Self::unchecked_new(
Expand Down Expand Up @@ -310,10 +308,6 @@ impl crate::testutils::Address for Address {
Self::try_from_val(env, &sc_addr).unwrap()
}

fn from_contract_id(contract_id: &crate::BytesN<32>) -> crate::Address {
Self::from_contract_id(contract_id)
}

fn contract_id(&self) -> crate::BytesN<32> {
self.contract_id()
}
Expand Down
61 changes: 55 additions & 6 deletions soroban-sdk/src/auth.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,64 @@
use crate::{contracttype, Address, BytesN, RawVal, Symbol, Vec};

/// Context of a single authorized call peformed by an address.
///
/// Custom account contracts that implement `__check_auth` special function
/// receive a list of `Context` values corresponding to all the calls that
/// need to be authorized.
#[derive(Clone)]
#[contracttype(crate_path = "crate", export = false)]
pub enum Context {
Contract(ContractContext),
CreateContractHostFn(CreateContractHostFnContext),
}

/// Authorization context of a single contract call.
///
/// This struct corresponds to a `require_auth_for_args` call for an address
/// from `contract` function with `fn_name` name and `args` arguments.
#[derive(Clone)]
pub struct Context {
pub contract: BytesN<32>,
#[contracttype(crate_path = "crate", export = false)]
pub struct ContractContext {
pub contract: Address,
pub fn_name: Symbol,
pub args: Vec<RawVal>,
}

impl Context {
pub fn contract(&self) -> Address {
Address::from_contract_id(&self.contract)
}
/// Authorization context for `create_contract` host function that creates a
/// new contract on behalf of authorizer address.
#[derive(Clone)]
#[contracttype(crate_path = "crate", export = false)]
pub struct CreateContractHostFnContext {
pub executable: ContractExecutable,
pub salt: BytesN<32>,
}

/// Contract executable used for creating a new contract and used in
/// `CreateContractHostFnContext`.
#[derive(Clone)]
#[contracttype(crate_path = "crate", export = false)]
pub enum ContractExecutable {
Wasm(BytesN<32>),
}

/// A node in the tree of authorizations performed on behalf of the current
/// contract as invoker of the contracts deeper in the call stack.
///
/// This is used as an argument of `authorize_as_current_contract` host function.
///
/// This tree corresponds `require_auth[_for_args]` calls on behalf of the
/// current contract.
#[derive(Clone)]
#[contracttype(crate_path = "crate", export = false)]
pub enum InvokerContractAuthEntry {
Contract(SubContractInvocation),
CreateContractHostFn(CreateContractHostFnContext),
}

/// Value of contract node in InvokerContractAuthEntry tree.
#[derive(Clone)]
#[contracttype(crate_path = "crate", export = false)]
pub struct SubContractInvocation {
pub context: ContractContext,
pub sub_invocations: Vec<InvokerContractAuthEntry>,
}
Loading

0 comments on commit 8b6210b

Please sign in to comment.