Skip to content

Commit

Permalink
Add "next" feature to crates using xdr directly or indirectly
Browse files Browse the repository at this point in the history
  • Loading branch information
graydon committed Sep 13, 2023
1 parent f19ef13 commit 0a15ae4
Show file tree
Hide file tree
Showing 80 changed files with 275 additions and 85 deletions.
3 changes: 3 additions & 0 deletions soroban-bench-utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,8 @@ publish = false
soroban-env-common = { workspace = true }
tracking-allocator = "0.4.0"

[features]
next = ["soroban-env-common/next"]

[target.'cfg(target_os = "linux")'.dependencies]
perf-event = "0.4.7"
1 change: 1 addition & 0 deletions soroban-env-common/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ std = ["stellar-xdr/std", "stellar-xdr/base64"]
serde = ["dep:serde", "stellar-xdr/serde"]
wasmi = ["dep:wasmi"]
testutils = ["dep:arbitrary", "stellar-xdr/arbitrary"]
next = ["stellar-xdr/next"]

[package.metadata.docs.rs]
all-features = true
10 changes: 5 additions & 5 deletions soroban-env-common/src/convert.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
use crate::xdr::int128_helpers;
use crate::{
num::{i256_from_pieces, i256_into_pieces, u256_from_pieces, u256_into_pieces},
DurationSmall, DurationVal, Env, I128Small, I128Val, I256Small, I256Val, I64Small,
TimepointSmall, TimepointVal, U128Small, U128Val, U256Small, U256Val, U64Small, U64Val, Val,
I256, U256,
};
use core::fmt::Debug;
use stellar_xdr::int128_helpers;

#[cfg(feature = "std")]
use crate::xdr::{
Duration, Int128Parts, Int256Parts, ScVal, TimePoint, UInt128Parts, UInt256Parts,
};
#[cfg(feature = "std")]
use crate::{
num, object::ScValObjRef, val::ValConvert, ConversionError, Error, Object, ScValObject,
SymbolSmall, Tag,
};
#[cfg(feature = "std")]
use stellar_xdr::{
Duration, Int128Parts, Int256Parts, ScVal, TimePoint, UInt128Parts, UInt256Parts,
};

/// General trait representing a the ability of some object to perform a
/// (possibly unsuccessful) conversion between two other types.
Expand Down
22 changes: 11 additions & 11 deletions soroban-env-common/src/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::xdr::{ScError, ScErrorCode, ScErrorType, ScVal};
use crate::{
impl_wrapper_as_and_to_rawval, impl_wrapper_tag_based_constructors,
impl_wrapper_tag_based_rawvalconvertible, impl_wrapper_wasmi_conversions, Compare,
Expand All @@ -9,7 +10,6 @@ use core::{
fmt::Debug,
hash::{Hash, Hasher},
};
use stellar_xdr::{ScError, ScErrorCode, ScErrorType, ScVal};

/// Wrapper for a [Val] that is tagged with [Tag::Error], interpreting the
/// [Val]'s body as a pair of a 28-bit status-type code and a 32-bit status
Expand Down Expand Up @@ -95,7 +95,7 @@ impl<'a> From<&'a Error> for Error {
}

impl TryFrom<Error> for ScError {
type Error = stellar_xdr::Error;
type Error = crate::xdr::Error;
fn try_from(er: Error) -> Result<Self, Self::Error> {
let type_: ScErrorType = (er.as_val().get_minor() as i32).try_into()?;
let u: u32 = er.as_val().get_major();
Expand All @@ -115,15 +115,15 @@ impl TryFrom<Error> for ScError {
}

impl TryFrom<Error> for ScVal {
type Error = stellar_xdr::Error;
fn try_from(st: Error) -> Result<Self, stellar_xdr::Error> {
type Error = crate::xdr::Error;
fn try_from(st: Error) -> Result<Self, crate::xdr::Error> {
Ok(ScVal::Error(<_ as TryInto<ScError>>::try_into(st)?))
}
}

impl TryFrom<&Error> for ScVal {
type Error = stellar_xdr::Error;
fn try_from(value: &Error) -> Result<Self, stellar_xdr::Error> {
type Error = crate::xdr::Error;
fn try_from(value: &Error) -> Result<Self, crate::xdr::Error> {
(*value).try_into()
}
}
Expand Down Expand Up @@ -152,10 +152,10 @@ impl From<ConversionError> for Error {
}
}

impl From<stellar_xdr::Error> for Error {
fn from(e: stellar_xdr::Error) -> Self {
impl From<crate::xdr::Error> for Error {
fn from(e: crate::xdr::Error) -> Self {
match e {
stellar_xdr::Error::DepthLimitExceeded => {
crate::xdr::Error::DepthLimitExceeded => {
Error::from_type_and_code(ScErrorType::Context, ScErrorCode::ExceededLimit)
}
_ => Error::from_type_and_code(ScErrorType::Value, ScErrorCode::InvalidInput),
Expand All @@ -165,9 +165,9 @@ impl From<stellar_xdr::Error> for Error {

// This never happens, but it's needed for some impls of TryFromVal downstream
// in the SDK that use the xdr::Error type.
impl From<Error> for stellar_xdr::Error {
impl From<Error> for crate::xdr::Error {
fn from(_value: Error) -> Self {
stellar_xdr::Error::Unsupported
crate::xdr::Error::Unsupported
}
}

Expand Down
7 changes: 5 additions & 2 deletions soroban-env-common/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,11 @@ pub use num::{I256, U256};

pub use storage_type::StorageType;

// Re-export the XDR definitions
pub use stellar_xdr as xdr;
// Re-export the XDR definitions of a specific version -- curr or next -- of the xdr crate.
#[cfg(not(feature = "next"))]
pub use stellar_xdr::curr as xdr;
#[cfg(feature = "next")]
pub use stellar_xdr::next as xdr;

// Val is the 64-bit transparent type.
#[cfg(feature = "wasmi")]
Expand Down
16 changes: 16 additions & 0 deletions soroban-env-common/src/meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,22 @@

pub const ENV_META_V0_SECTION_NAME: &str = "contractenvmetav0";

// If the "next" feature is enabled, we're building from the "next" xdr
// definitions branch and rust module, which contains experimental, unstable,
// in-development definitions we aren't even close to ready to release to the
// network. This is typically associated with a one-higher-than-released
// protocol number for testing purposes.
#[cfg(feature = "next")]
soroban_env_macros::generate_env_meta_consts!(
ledger_protocol_version: 21,
pre_release_version: 1,
);

// If the "next" feature is _not_ enabled, it means we're building for a
// nearly-current release to the network and are using the "curr" xdr branch and
// module. This will therefore be associated with a current or nearly-current
// network protocol number.
#[cfg(not(feature = "next"))]
soroban_env_macros::generate_env_meta_consts!(
ledger_protocol_version: 20,
pre_release_version: 57,
Expand Down
2 changes: 1 addition & 1 deletion soroban-env-common/src/num.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use core::cmp::Ordering;

use crate::xdr::{Int256Parts, ScVal, UInt256Parts};
use crate::{
declare_tag_based_signed_small_and_object_wrappers,
declare_tag_based_small_and_object_wrappers,
declare_tag_based_unsigned_small_and_object_wrappers, declare_tag_based_wrapper, val::TAG_BITS,
Compare, ConversionError, Env, Tag, Val,
};
pub use ethnum::{AsI256, AsU256, I256, U256};
use stellar_xdr::{Int256Parts, ScVal, UInt256Parts};

declare_tag_based_wrapper!(U32Val);
declare_tag_based_wrapper!(I32Val);
Expand Down
2 changes: 1 addition & 1 deletion soroban-env-common/src/object.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::xdr::{Duration, ScVal, TimePoint};
use crate::{
impl_rawval_wrapper_base, num, val::ValConvert, Compare, ConversionError, Convert, Env, Tag,
TryFromVal, Val,
};
use core::{cmp::Ordering, fmt::Debug};
use stellar_xdr::{Duration, ScVal, TimePoint};

/// Wrapper for a [Val] that is tagged with one of the object types,
/// interpreting the [Val]'s body as containing a 32-bit object-code handle
Expand Down
4 changes: 2 additions & 2 deletions soroban-env-common/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ impl TryFrom<&[u8]> for SymbolSmall {
}

#[cfg(feature = "std")]
use stellar_xdr::StringM;
use stellar_xdr::SCSYMBOL_LIMIT;
use crate::xdr::StringM;
use crate::xdr::SCSYMBOL_LIMIT;
#[cfg(feature = "std")]
impl<const N: u32> TryFrom<StringM<N>> for SymbolSmall {
type Error = SymbolError;
Expand Down
8 changes: 4 additions & 4 deletions soroban-env-common/src/val.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
// This permits globals prouced by derive(num_enum::TryFromPrimitive) below.
#![cfg_attr(test, allow(non_upper_case_globals))]

use crate::xdr::{ScError, ScValType};
use crate::{
declare_tag_based_object_wrapper, declare_tag_based_wrapper, impl_rawval_wrapper_base,
impl_tryfroms_and_tryfromvals_delegating_to_rawvalconvertible, Compare, I32Val, SymbolSmall,
SymbolStr, U32Val,
};
use stellar_xdr::{ScError, ScValType};

use super::{Env, Error, TryFromVal};
use core::{cmp::Ordering, convert::Infallible, fmt::Debug};
Expand Down Expand Up @@ -97,7 +97,7 @@ pub enum Tag {
SymbolSmall = 14,

/// Tag for a [Val] that corresponds to
/// [stellar_xdr::ScVal::LedgerKeyContractInstance]
/// [crate::xdr::ScVal::LedgerKeyContractInstance]
LedgerKeyContractInstance = 15,

/// Code delimiting the upper boundary of "small" types.
Expand Down Expand Up @@ -338,8 +338,8 @@ impl From<Infallible> for ConversionError {
}
}

impl From<stellar_xdr::Error> for ConversionError {
fn from(_: stellar_xdr::Error) -> Self {
impl From<crate::xdr::Error> for ConversionError {
fn from(_: crate::xdr::Error) -> Self {
ConversionError
}
}
Expand Down
2 changes: 1 addition & 1 deletion soroban-env-common/src/vmcaller_env.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#[cfg(feature = "wasmi")]
use stellar_xdr::{ScErrorCode, ScErrorType};
use crate::xdr::{ScErrorCode, ScErrorType};

use super::{
AddressObject, Bool, BytesObject, DurationObject, Error, I128Object, I256Object, I256Val,
Expand Down
1 change: 1 addition & 0 deletions soroban-env-guest/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ all-features = true

[features]
testutils = ["soroban-env-common/testutils"]
next = ["soroban-env-common/next"]
1 change: 1 addition & 0 deletions soroban-env-host/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ linregress = "0.5.1"

[features]
testutils = ["soroban-env-common/testutils"]
next = ["soroban-env-common/next", "soroban-test-wasms/next"]
tracy = ["dep:tracy-client"]

[[bench]]
Expand Down
3 changes: 3 additions & 0 deletions soroban-env-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,8 @@ itertools = "0.10.3"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"

[features]
next = ["stellar-xdr/next"]

[package.metadata.docs.rs]
all-features = true
10 changes: 8 additions & 2 deletions soroban-env-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ use proc_macro::TokenStream;
use quote::{quote, ToTokens};
use syn::{parse::Parse, parse_macro_input, Ident, LitInt, LitStr, Token};

use stellar_xdr::{ScEnvMetaEntry, WriteXdr};
// Import the XDR definitions of a specific version -- curr or next -- of the xdr crate.
#[cfg(not(feature = "next"))]
use stellar_xdr::curr as xdr;
#[cfg(feature = "next")]
use stellar_xdr::next as xdr;

use crate::xdr::{ScEnvMetaEntry, WriteXdr};

struct MetaInput {
pub interface_version: u64,
Expand Down Expand Up @@ -55,7 +61,7 @@ impl ToTokens for MetaConstsOutput {
.to_meta_entries()
.into_iter()
.map(|entry| entry.to_xdr())
.collect::<Result<Vec<Vec<u8>>, stellar_xdr::Error>>()
.collect::<Result<Vec<Vec<u8>>, crate::xdr::Error>>()
.unwrap()
.concat();
let meta_xdr_len = meta_xdr.len();
Expand Down
3 changes: 3 additions & 0 deletions soroban-synth-wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ wasm-encoder = "0.18.0"
wasmparser = "0.106.0"
soroban-env-common = { workspace = true }

[features]
next = ["soroban-env-common/next"]

[dev-dependencies]
expect-test = "1.4.0"
wasmprinter = "0.2.41"
3 changes: 3 additions & 0 deletions soroban-test-wasms/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ description = "crate full of precompiled test WASM binaries for soroban -- for u
edition = "2021"
publish = false
rust-version = "1.71"

[features]
next = []
Loading

0 comments on commit 0a15ae4

Please sign in to comment.