Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adapt to RawVal -> Val renaming #993

Merged
merged 3 commits into from
Jun 17, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
584 changes: 384 additions & 200 deletions Cargo.lock

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,17 @@ 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 = "e64000dfed0512ebcf398e65bd5534e898db5951"
rev = "d1bbfe9f37533484adbb74a5f57959a708745e0a"

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

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

[workspace.dependencies.stellar-strkey]
version = "0.0.7"
Expand Down
9 changes: 8 additions & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,14 @@ skip = [
# dependencies starting at the specified crate, up to a certain depth, which is
# by default infinite.
skip-tree = [
# { name = "textplots" },
# while we're waiting for dalek to go to 2.0 we have
# duplicates of a whole lot of ECC dependencies due
# to k256
{ name = "block-buffer", version = "=0.9.0" },
{ name = "sha2", version = "=0.9.9" },
{ name = "signature", version = "=1.6.4" },
{ name = "rand_core", version = "=0.5.1"},
{ name = "digest", version = "=0.9.0" }
]

# This section is considered when running `cargo deny check sources`.
Expand Down
28 changes: 14 additions & 14 deletions soroban-sdk-macros/src/derive_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,13 @@ pub fn derive_type_enum(
quote! {
#spec_gen

impl #path::TryFromVal<#path::Env, #path::RawVal> for #enum_ident {
impl #path::TryFromVal<#path::Env, #path::Val> for #enum_ident {
type Error = #path::ConversionError;
#[inline(always)]
fn try_from_val(env: &#path::Env, val: &#path::RawVal) -> Result<Self, #path::ConversionError> {
fn try_from_val(env: &#path::Env, val: &#path::Val) -> Result<Self, #path::ConversionError> {
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 vec: #path::Vec<#path::Val> = val.try_into_val(env)?;
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 {
Expand All @@ -180,7 +180,7 @@ pub fn derive_type_enum(
}
}

impl #path::TryFromVal<#path::Env, #enum_ident> for #path::RawVal {
impl #path::TryFromVal<#path::Env, #enum_ident> for #path::Val {
type Error = #path::ConversionError;
#[inline(always)]
fn try_from_val(env: &#path::Env, val: &#enum_ident) -> Result<Self, #path::ConversionError> {
Expand Down Expand Up @@ -296,7 +296,7 @@ fn map_empty_variant(
};
let try_into = quote! {
#enum_ident::#case_ident => {
let tup: (#path::RawVal,) = (#path::Symbol::try_from_val(env, &#case_name_str_lit)?.to_raw(),);
let tup: (#path::Val,) = (#path::Symbol::try_from_val(env, &#case_name_str_lit)?.to_raw(),);
tup.try_into_val(env)
}
};
Expand Down Expand Up @@ -400,37 +400,37 @@ fn map_tuple_variant(
#binding_name.try_into_val(env)?
};
let tup_elem_type = quote! {
#path::RawVal
#path::Val
};
(binding_name, field_conv, tup_elem_type)
})
.multiunzip();
let (binding_names, field_convs, tup_elem_types): (Vec<_>, Vec<_>, Vec<_>) = fragments;
quote! {
#enum_ident::#case_ident(#(ref #binding_names,)* ) => {
let tup: (#path::RawVal, #(#tup_elem_types,)* ) = (#path::Symbol::try_from_val(env, &#case_name_str_lit)?.to_raw(), #(#field_convs,)* );
let tup: (#path::Val, #(#tup_elem_types,)* ) = (#path::Symbol::try_from_val(env, &#case_name_str_lit)?.to_raw(), #(#field_convs,)* );
tup.try_into_val(env)
}
}
};
let try_from_xdr = {
let fragments = fields.iter().enumerate().map(|(i, _f)| {
let rawval_name = format_ident!("rv{i}");
let rawval_binding = quote! {
let #rawval_name: #path::RawVal = iter.next().ok_or(#path::xdr::Error::Invalid)?.try_into_val(env).map_err(|_| #path::xdr::Error::Invalid)?;
let val_name = format_ident!("rv{i}");
let val_binding = quote! {
let #val_name: #path::Val = iter.next().ok_or(#path::xdr::Error::Invalid)?.try_into_val(env).map_err(|_| #path::xdr::Error::Invalid)?;
};
let into_field = quote! {
#rawval_name.try_into_val(env).map_err(|_| #path::xdr::Error::Invalid)?
#val_name.try_into_val(env).map_err(|_| #path::xdr::Error::Invalid)?
};
(rawval_binding, into_field)
(val_binding, into_field)
}).multiunzip();
let (rawval_bindings, into_fields): (Vec<_>, Vec<_>) = fragments;
let (val_bindings, into_fields): (Vec<_>, Vec<_>) = fragments;
quote! {
#case_name => {
if iter.len() > #num_fields {
return Err(#path::xdr::Error::Invalid);
}
#(#rawval_bindings)*
#(#val_bindings)*
Self::#case_ident( #(#into_fields,)* )
}
}
Expand Down
6 changes: 3 additions & 3 deletions soroban-sdk-macros/src/derive_enum_int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,10 @@ pub fn derive_type_enum_int(
quote! {
#spec_gen

impl #path::TryFromVal<#path::Env, #path::RawVal> for #enum_ident {
impl #path::TryFromVal<#path::Env, #path::Val> for #enum_ident {
type Error = #path::ConversionError;
#[inline(always)]
fn try_from_val(env: &#path::Env, val: &#path::RawVal) -> Result<Self, #path::ConversionError> {
fn try_from_val(env: &#path::Env, val: &#path::Val) -> Result<Self, #path::ConversionError> {
use #path::TryIntoVal;
let discriminant: u32 = val.try_into_val(env)?;
Ok(match discriminant {
Expand All @@ -106,7 +106,7 @@ pub fn derive_type_enum_int(
}
}

impl #path::TryFromVal<#path::Env, #enum_ident> for #path::RawVal {
impl #path::TryFromVal<#path::Env, #enum_ident> for #path::Val {
type Error = #path::ConversionError;
#[inline(always)]
fn try_from_val(env: &#path::Env, val: &#enum_ident) -> Result<Self, #path::ConversionError> {
Expand Down
6 changes: 3 additions & 3 deletions soroban-sdk-macros/src/derive_error_enum_int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,16 +130,16 @@ pub fn derive_type_error_enum_int(
}
}

impl #path::TryFromVal<#path::Env, #path::RawVal> for #enum_ident {
impl #path::TryFromVal<#path::Env, #path::Val> for #enum_ident {
type Error = #path::ConversionError;
#[inline(always)]
fn try_from_val(env: &#path::Env, val: &#path::RawVal) -> Result<Self, #path::ConversionError> {
fn try_from_val(env: &#path::Env, val: &#path::Val) -> Result<Self, #path::ConversionError> {
use #path::TryIntoVal;
let error: #path::Error = val.try_into_val(env)?;
error.try_into().map_err(|_| #path::ConversionError)
}
}
impl #path::TryFromVal<#path::Env, #enum_ident> for #path::RawVal {
impl #path::TryFromVal<#path::Env, #enum_ident> for #path::Val {
type Error = #path::ConversionError;
#[inline(always)]
fn try_from_val(env: &#path::Env, val: &#enum_ident) -> Result<Self, #path::ConversionError> {
Expand Down
16 changes: 8 additions & 8 deletions soroban-sdk-macros/src/derive_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,11 @@ pub fn derive_fn(
subpat: None,
})),
colon_token: Colon::default(),
ty: Box::new(Type::Verbatim(quote! { #crate_path::RawVal })),
ty: Box::new(Type::Verbatim(quote! { #crate_path::Val })),
});
let call = quote! {
<_ as #crate_path::unwrap::UnwrapOptimized>::unwrap_optimized(
<_ as #crate_path::TryFromVal<#crate_path::Env, #crate_path::RawVal>>::try_from_val(
<_ as #crate_path::TryFromVal<#crate_path::Env, #crate_path::Val>>::try_from_val(
&env,
&#ident
)
Expand Down Expand Up @@ -113,9 +113,9 @@ pub fn derive_fn(

#[deprecated(note = #deprecated_note)]
#[cfg_attr(target_family = "wasm", export_name = #wrap_export_name)]
pub fn invoke_raw(env: #crate_path::Env, #(#wrap_args),*) -> #crate_path::RawVal {
pub fn invoke_raw(env: #crate_path::Env, #(#wrap_args),*) -> #crate_path::Val {
#use_trait;
<_ as #crate_path::IntoVal<#crate_path::Env, #crate_path::RawVal>>::into_val(
<_ as #crate_path::IntoVal<#crate_path::Env, #crate_path::Val>>::into_val(
#[allow(deprecated)]
&#call(
#env_call
Expand All @@ -128,8 +128,8 @@ pub fn derive_fn(
#[deprecated(note = #deprecated_note)]
pub fn invoke_raw_slice(
env: #crate_path::Env,
args: &[#crate_path::RawVal],
) -> #crate_path::RawVal {
args: &[#crate_path::Val],
) -> #crate_path::Val {
#[allow(deprecated)]
invoke_raw(env, #(#slice_args),*)
}
Expand Down Expand Up @@ -165,8 +165,8 @@ pub fn derive_contract_function_set<'a>(
&self,
func: &str,
env: #crate_path::Env,
args: &[#crate_path::RawVal],
) -> Option<#crate_path::RawVal> {
args: &[#crate_path::Val],
) -> Option<#crate_path::Val> {
match func {
#(
#(#attrs)*
Expand Down
16 changes: 8 additions & 8 deletions soroban-sdk-macros/src/derive_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub fn derive_type_struct(
#field_ident: {
let key = &#field_name.try_into().map_err(|_| #path::xdr::Error::Invalid)?;
let idx = map.binary_search_by_key(key, |entry| entry.key.clone()).map_err(|_| #path::xdr::Error::Invalid)?;
let rv: #path::RawVal = (&map[idx].val.clone()).try_into_val(env).map_err(|_| #path::xdr::Error::Invalid)?;
let rv: #path::Val = (&map[idx].val.clone()).try_into_val(env).map_err(|_| #path::xdr::Error::Invalid)?;
rv.try_into_val(env).map_err(|_| #path::xdr::Error::Invalid)?
}
};
Expand Down Expand Up @@ -104,12 +104,12 @@ pub fn derive_type_struct(
quote! {
#spec_gen

impl #path::TryFromVal<#path::Env, #path::RawVal> for #ident {
impl #path::TryFromVal<#path::Env, #path::Val> for #ident {
type Error = #path::ConversionError;
fn try_from_val(env: &#path::Env, val: &#path::RawVal) -> Result<Self, #path::ConversionError> {
use #path::{TryIntoVal,EnvBase,ConversionError,RawVal,MapObject};
fn try_from_val(env: &#path::Env, val: &#path::Val) -> Result<Self, #path::ConversionError> {
use #path::{TryIntoVal,EnvBase,ConversionError,Val,MapObject};
const KEYS: [&'static str; #field_count_usize] = [#(#field_names),*];
let mut vals: [RawVal; #field_count_usize] = [RawVal::VOID.to_raw(); #field_count_usize];
let mut vals: [Val; #field_count_usize] = [Val::VOID.to_raw(); #field_count_usize];
let map: MapObject = val.try_into().map_err(|_| ConversionError)?;
env.map_unpack_to_slice(map, &KEYS, &mut vals).map_err(|_| ConversionError)?;
Ok(Self {
Expand All @@ -118,12 +118,12 @@ pub fn derive_type_struct(
}
}

impl #path::TryFromVal<#path::Env, #ident> for #path::RawVal {
impl #path::TryFromVal<#path::Env, #ident> for #path::Val {
type Error = #path::ConversionError;
fn try_from_val(env: &#path::Env, val: &#ident) -> Result<Self, #path::ConversionError> {
use #path::{TryIntoVal,EnvBase,ConversionError,RawVal};
use #path::{TryIntoVal,EnvBase,ConversionError,Val};
const KEYS: [&'static str; #field_count_usize] = [#(#field_names),*];
let vals: [RawVal; #field_count_usize] = [
let vals: [Val; #field_count_usize] = [
#((&val.#field_idents).try_into_val(env).map_err(|_| ConversionError)?),*
];
Ok(env.map_new_from_slices(&KEYS, &vals).map_err(|_| ConversionError)?.into())
Expand Down
16 changes: 8 additions & 8 deletions soroban-sdk-macros/src/derive_struct_tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub fn derive_type_struct_tuple(
};
let try_from_xdr = quote! {
#field_idx_lit: {
let rv: #path::RawVal = (&vec[#field_idx_lit].clone()).try_into_val(env).map_err(|_| #path::xdr::Error::Invalid)?;
let rv: #path::Val = (&vec[#field_idx_lit].clone()).try_into_val(env).map_err(|_| #path::xdr::Error::Invalid)?;
rv.try_into_val(env).map_err(|_| #path::xdr::Error::Invalid)?
}
};
Expand Down Expand Up @@ -91,26 +91,26 @@ pub fn derive_type_struct_tuple(
quote! {
#spec_gen

impl #path::TryFromVal<#path::Env, #path::RawVal> for #ident {
impl #path::TryFromVal<#path::Env, #path::Val> for #ident {
type Error = #path::ConversionError;
#[inline(always)]
fn try_from_val(env: &#path::Env, val: &#path::RawVal) -> Result<Self, #path::ConversionError> {
use #path::{TryIntoVal,EnvBase,ConversionError,VecObject,RawVal};
fn try_from_val(env: &#path::Env, val: &#path::Val) -> Result<Self, #path::ConversionError> {
use #path::{TryIntoVal,EnvBase,ConversionError,VecObject,Val};
let vec: VecObject = (*val).try_into().map_err(|_| ConversionError)?;
let mut vals: [RawVal; #field_count_usize] = [RawVal::VOID.to_raw(); #field_count_usize];
let mut vals: [Val; #field_count_usize] = [Val::VOID.to_raw(); #field_count_usize];
env.vec_unpack_to_slice(vec, &mut vals).map_err(|_| ConversionError)?;
Ok(Self{
#(#field_idx_lits: vals[#field_idx_lits].try_into_val(env).map_err(|_| ConversionError)?),*
})
}
}

impl #path::TryFromVal<#path::Env, #ident> for #path::RawVal {
impl #path::TryFromVal<#path::Env, #ident> for #path::Val {
type Error = #path::ConversionError;
#[inline(always)]
fn try_from_val(env: &#path::Env, val: &#ident) -> Result<Self, #path::ConversionError> {
use #path::{TryIntoVal,EnvBase,ConversionError,RawVal};
let vals: [RawVal; #field_count_usize] = [
use #path::{TryIntoVal,EnvBase,ConversionError,Val};
let vals: [Val; #field_count_usize] = [
#((&val.#field_idx_lits).try_into_val(env).map_err(|_| ConversionError)?),*
];
Ok(env.vec_new_from_slice(&vals).map_err(|_| ConversionError)?.into())
Expand Down
2 changes: 1 addition & 1 deletion soroban-sdk-macros/src/map_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub fn map_type(t: &Type) -> Result<ScSpecTypeDef, Error> {
ident,
arguments: PathArguments::None,
}) => match &ident.to_string()[..] {
"RawVal" => Ok(ScSpecTypeDef::Val),
"Val" => Ok(ScSpecTypeDef::Val),
"u64" => Ok(ScSpecTypeDef::U64),
"i64" => Ok(ScSpecTypeDef::I64),
"u32" => Ok(ScSpecTypeDef::U32),
Expand Down
2 changes: 1 addition & 1 deletion soroban-sdk-macros/src/syn_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ impl<'a> Fn<'a> {
};
Type::Verbatim(quote! {
Result<
Result<#t, <#t as #crate_path::TryFromVal<#crate_path::Env, #crate_path::RawVal>>::Error>,
Result<#t, <#t as #crate_path::TryFromVal<#crate_path::Env, #crate_path::Val>>::Error>,
Result<#e, <#e as TryFrom<#crate_path::Error>>::Error>
>
})
Expand Down
20 changes: 10 additions & 10 deletions soroban-sdk/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use core::{cmp::Ordering, convert::Infallible, fmt::Debug};

use super::{
env::internal::{AddressObject, Env as _, EnvBase as _},
BytesN, ConversionError, Env, RawVal, TryFromVal, TryIntoVal,
BytesN, ConversionError, Env, TryFromVal, TryIntoVal, Val,
};

#[cfg(not(target_family = "wasm"))]
Expand Down Expand Up @@ -100,25 +100,25 @@ impl TryFromVal<Env, AddressObject> for Address {
}
}

impl TryFromVal<Env, RawVal> for Address {
impl TryFromVal<Env, Val> for Address {
type Error = ConversionError;

fn try_from_val(env: &Env, val: &RawVal) -> Result<Self, Self::Error> {
fn try_from_val(env: &Env, val: &Val) -> Result<Self, Self::Error> {
Ok(AddressObject::try_from_val(env, val)?
.try_into_val(env)
.unwrap_infallible())
}
}

impl TryFromVal<Env, Address> for RawVal {
impl TryFromVal<Env, Address> for Val {
type Error = ConversionError;

fn try_from_val(_env: &Env, v: &Address) -> Result<Self, Self::Error> {
Ok(v.to_raw())
}
}

impl TryFromVal<Env, &Address> for RawVal {
impl TryFromVal<Env, &Address> for Val {
type Error = ConversionError;

fn try_from_val(_env: &Env, v: &&Address) -> Result<Self, Self::Error> {
Expand Down Expand Up @@ -147,7 +147,7 @@ impl TryFromVal<Env, ScVal> for Address {
type Error = ConversionError;
fn try_from_val(env: &Env, val: &ScVal) -> Result<Self, Self::Error> {
Ok(
AddressObject::try_from_val(env, &RawVal::try_from_val(env, val)?)?
AddressObject::try_from_val(env, &Val::try_from_val(env, val)?)?
.try_into_val(env)
.unwrap_infallible(),
)
Expand Down Expand Up @@ -179,7 +179,7 @@ impl TryFromVal<Env, ScAddress> for Address {
fn try_from_val(env: &Env, val: &ScAddress) -> Result<Self, Self::Error> {
Ok(AddressObject::try_from_val(
env,
&RawVal::try_from_val(env, &ScVal::Address(val.clone()))?,
&Val::try_from_val(env, &ScVal::Address(val.clone()))?,
)?
.try_into_val(env)
.unwrap_infallible())
Expand All @@ -204,7 +204,7 @@ impl Address {
/// ### Panics
///
/// If the invocation is not authorized.
pub fn require_auth_for_args(&self, args: Vec<RawVal>) {
pub fn require_auth_for_args(&self, args: Vec<Val>) {
self.env.require_auth_for_args(self, args);
}

Expand Down Expand Up @@ -279,11 +279,11 @@ impl Address {
&self.env
}

pub fn as_raw(&self) -> &RawVal {
pub fn as_raw(&self) -> &Val {
self.obj.as_raw()
}

pub fn to_raw(&self) -> RawVal {
pub fn to_raw(&self) -> Val {
self.obj.to_raw()
}

Expand Down
Loading