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

Bug 1076 conversion error flattening 2 #1218

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
28 changes: 14 additions & 14 deletions Cargo.lock

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

12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,19 @@ soroban-ledger-snapshot = { version = "20.2.0", path = "soroban-ledger-snapshot"
soroban-token-sdk = { version = "20.2.0", path = "soroban-token-sdk" }

[workspace.dependencies.soroban-env-common]
version = "=20.1.0"
version = "=20.1.1"
git = "https://github.com/stellar/rs-soroban-env"
rev = "c1b238b65bfd13666be4ac14e0e390c31b549caf"
rev = "096d4614299ac08c93d255a5482dd079873265dd"

[workspace.dependencies.soroban-env-guest]
version = "=20.1.0"
version = "=20.1.1"
git = "https://github.com/stellar/rs-soroban-env"
rev = "c1b238b65bfd13666be4ac14e0e390c31b549caf"
rev = "096d4614299ac08c93d255a5482dd079873265dd"

[workspace.dependencies.soroban-env-host]
version = "=20.1.0"
version = "=20.1.1"
git = "https://github.com/stellar/rs-soroban-env"
rev = "c1b238b65bfd13666be4ac14e0e390c31b549caf"
rev = "096d4614299ac08c93d255a5482dd079873265dd"

[workspace.dependencies.stellar-strkey]
version = "=0.0.8"
Expand Down
18 changes: 9 additions & 9 deletions soroban-sdk/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,23 +125,23 @@ impl TryFromVal<Env, &Address> for Val {

#[cfg(not(target_family = "wasm"))]
impl TryFrom<&Address> for ScVal {
type Error = ConversionError;
fn try_from(v: &Address) -> Result<Self, ConversionError> {
type Error = super::env::Error;
fn try_from(v: &Address) -> Result<Self, super::env::Error> {
ScVal::try_from_val(&v.env, &v.obj.to_val())
}
}

#[cfg(not(target_family = "wasm"))]
impl TryFrom<Address> for ScVal {
type Error = ConversionError;
fn try_from(v: Address) -> Result<Self, ConversionError> {
type Error = super::env::Error;
fn try_from(v: Address) -> Result<Self, super::env::Error> {
(&v).try_into()
}
}

#[cfg(not(target_family = "wasm"))]
impl TryFromVal<Env, ScVal> for Address {
type Error = ConversionError;
type Error = super::env::Error;
fn try_from_val(env: &Env, val: &ScVal) -> Result<Self, Self::Error> {
Ok(
AddressObject::try_from_val(env, &Val::try_from_val(env, val)?)?
Expand All @@ -153,26 +153,26 @@ impl TryFromVal<Env, ScVal> for Address {

#[cfg(not(target_family = "wasm"))]
impl TryFrom<&Address> for ScAddress {
type Error = ConversionError;
type Error = super::env::Error;
fn try_from(v: &Address) -> Result<Self, Self::Error> {
match ScVal::try_from_val(&v.env, &v.obj.to_val())? {
ScVal::Address(a) => Ok(a),
_ => Err(ConversionError),
_ => Err(ConversionError.into()),
}
}
}

#[cfg(not(target_family = "wasm"))]
impl TryFrom<Address> for ScAddress {
type Error = ConversionError;
type Error = super::env::Error;
fn try_from(v: Address) -> Result<Self, Self::Error> {
(&v).try_into()
}
}

#[cfg(not(target_family = "wasm"))]
impl TryFromVal<Env, ScAddress> for Address {
type Error = ConversionError;
type Error = super::env::Error;
fn try_from_val(env: &Env, val: &ScAddress) -> Result<Self, Self::Error> {
Ok(AddressObject::try_from_val(
env,
Expand Down
22 changes: 11 additions & 11 deletions soroban-sdk/src/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,23 +230,23 @@ impl From<&Bytes> for Bytes {

#[cfg(not(target_family = "wasm"))]
impl TryFrom<&Bytes> for ScVal {
type Error = ConversionError;
fn try_from(v: &Bytes) -> Result<Self, ConversionError> {
type Error = super::env::Error;
fn try_from(v: &Bytes) -> Result<Self, super::env::Error> {
ScVal::try_from_val(&v.env, &v.obj.to_val())
}
}

#[cfg(not(target_family = "wasm"))]
impl TryFrom<Bytes> for ScVal {
type Error = ConversionError;
fn try_from(v: Bytes) -> Result<Self, ConversionError> {
type Error = super::env::Error;
fn try_from(v: Bytes) -> Result<Self, super::env::Error> {
(&v).try_into()
}
}

#[cfg(not(target_family = "wasm"))]
impl TryFromVal<Env, ScVal> for Bytes {
type Error = ConversionError;
type Error = super::env::Error;
fn try_from_val(env: &Env, val: &ScVal) -> Result<Self, Self::Error> {
Ok(
BytesObject::try_from_val(env, &Val::try_from_val(env, val)?)?
Expand Down Expand Up @@ -892,25 +892,25 @@ impl<const N: usize> From<&BytesN<N>> for Bytes {

#[cfg(not(target_family = "wasm"))]
impl<const N: usize> TryFrom<&BytesN<N>> for ScVal {
type Error = ConversionError;
fn try_from(v: &BytesN<N>) -> Result<Self, ConversionError> {
type Error = super::env::Error;
fn try_from(v: &BytesN<N>) -> Result<Self, super::env::Error> {
ScVal::try_from_val(&v.0.env, &v.0.obj.to_val())
}
}

#[cfg(not(target_family = "wasm"))]
impl<const N: usize> TryFrom<BytesN<N>> for ScVal {
type Error = ConversionError;
fn try_from(v: BytesN<N>) -> Result<Self, ConversionError> {
type Error = super::env::Error;
fn try_from(v: BytesN<N>) -> Result<Self, super::env::Error> {
(&v).try_into()
}
}

#[cfg(not(target_family = "wasm"))]
impl<const N: usize> TryFromVal<Env, ScVal> for BytesN<N> {
type Error = ConversionError;
type Error = super::env::Error;
fn try_from_val(env: &Env, val: &ScVal) -> Result<Self, Self::Error> {
Bytes::try_from_val(env, val)?.try_into()
Ok(Bytes::try_from_val(env, val)?.try_into()?)
}
}

Expand Down
14 changes: 7 additions & 7 deletions soroban-sdk/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,24 +226,24 @@ where

#[cfg(not(target_family = "wasm"))]
impl<K, V> TryFrom<&Map<K, V>> for ScVal {
type Error = ConversionError;
fn try_from(v: &Map<K, V>) -> Result<Self, ConversionError> {
type Error = super::env::Error;
fn try_from(v: &Map<K, V>) -> Result<Self, super::env::Error> {
ScVal::try_from_val(&v.env, &v.obj.to_val())
}
}

#[cfg(not(target_family = "wasm"))]
impl<K, V> TryFrom<Map<K, V>> for ScVal {
type Error = ConversionError;
fn try_from(v: Map<K, V>) -> Result<Self, ConversionError> {
type Error = super::env::Error;
fn try_from(v: Map<K, V>) -> Result<Self, super::env::Error> {
(&v).try_into()
}
}

#[cfg(not(target_family = "wasm"))]
impl<K, V> TryFromVal<Env, Map<K, V>> for ScVal {
type Error = ConversionError;
fn try_from_val(_e: &Env, v: &Map<K, V>) -> Result<Self, ConversionError> {
type Error = super::env::Error;
fn try_from_val(_e: &Env, v: &Map<K, V>) -> Result<Self, super::env::Error> {
v.try_into()
}
}
Expand All @@ -254,7 +254,7 @@ where
K: IntoVal<Env, Val> + TryFromVal<Env, Val>,
V: IntoVal<Env, Val> + TryFromVal<Env, Val>,
{
type Error = ConversionError;
type Error = super::env::Error;
fn try_from_val(env: &Env, val: &ScVal) -> Result<Self, Self::Error> {
Ok(MapObject::try_from_val(env, &Val::try_from_val(env, val)?)?
.try_into_val(env)
Expand Down
12 changes: 6 additions & 6 deletions soroban-sdk/src/num.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ macro_rules! impl_num_wrapping_val_type {

#[cfg(not(target_family = "wasm"))]
impl TryFrom<&$wrapper> for ScVal {
type Error = ConversionError;
fn try_from(v: &$wrapper) -> Result<Self, ConversionError> {
type Error = super::env::Error;
fn try_from(v: &$wrapper) -> Result<Self, super::env::Error> {
if let Ok(ss) = <$small>::try_from(v.val) {
ScVal::try_from(ss)
Ok(ScVal::try_from(ss)?)
} else {
ScVal::try_from_val(&v.env, &v.to_val())
}
Expand All @@ -102,15 +102,15 @@ macro_rules! impl_num_wrapping_val_type {

#[cfg(not(target_family = "wasm"))]
impl TryFrom<$wrapper> for ScVal {
type Error = ConversionError;
fn try_from(v: $wrapper) -> Result<Self, ConversionError> {
type Error = super::env::Error;
fn try_from(v: $wrapper) -> Result<Self, super::env::Error> {
(&v).try_into()
}
}

#[cfg(not(target_family = "wasm"))]
impl TryFromVal<Env, ScVal> for $wrapper {
type Error = ConversionError;
type Error = super::env::Error;
fn try_from_val(env: &Env, val: &ScVal) -> Result<Self, Self::Error> {
Ok(<$val>::try_from_val(env, &Val::try_from_val(env, val)?)?
.try_into_val(env)
Expand Down
10 changes: 5 additions & 5 deletions soroban-sdk/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,23 +135,23 @@ impl From<&String> for String {

#[cfg(not(target_family = "wasm"))]
impl TryFrom<&String> for ScVal {
type Error = ConversionError;
fn try_from(v: &String) -> Result<Self, ConversionError> {
type Error = super::env::Error;
fn try_from(v: &String) -> Result<Self, super::env::Error> {
ScVal::try_from_val(&v.env, &v.obj.to_val())
}
}

#[cfg(not(target_family = "wasm"))]
impl TryFrom<String> for ScVal {
type Error = ConversionError;
fn try_from(v: String) -> Result<Self, ConversionError> {
type Error = super::env::Error;
fn try_from(v: String) -> Result<Self, super::env::Error> {
(&v).try_into()
}
}

#[cfg(not(target_family = "wasm"))]
impl TryFromVal<Env, ScVal> for String {
type Error = ConversionError;
type Error = super::env::Error;
fn try_from_val(env: &Env, val: &ScVal) -> Result<Self, Self::Error> {
Ok(
StringObject::try_from_val(env, &Val::try_from_val(env, val)?)?
Expand Down
18 changes: 9 additions & 9 deletions soroban-sdk/src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,10 @@ impl TryFromVal<Env, &str> for Symbol {

#[cfg(not(target_family = "wasm"))]
impl TryFrom<&Symbol> for ScVal {
type Error = ConversionError;
fn try_from(v: &Symbol) -> Result<Self, ConversionError> {
type Error = super::env::Error;
fn try_from(v: &Symbol) -> Result<Self, super::env::Error> {
if let Ok(ss) = SymbolSmall::try_from(v.val) {
Ok(ScVal::try_from(ss)?)
ScVal::try_from(ss)
} else {
let e: Env = v.env.clone().try_into()?;
ScVal::try_from_val(&e, &v.to_val())
Expand All @@ -150,23 +150,23 @@ impl TryFrom<&Symbol> for ScVal {

#[cfg(not(target_family = "wasm"))]
impl TryFrom<Symbol> for ScVal {
type Error = ConversionError;
fn try_from(v: Symbol) -> Result<Self, ConversionError> {
type Error = super::env::Error;
fn try_from(v: Symbol) -> Result<Self, super::env::Error> {
(&v).try_into()
}
}

#[cfg(not(target_family = "wasm"))]
impl TryFromVal<Env, Symbol> for ScVal {
type Error = ConversionError;
fn try_from_val(_e: &Env, v: &Symbol) -> Result<Self, ConversionError> {
type Error = super::env::Error;
fn try_from_val(_e: &Env, v: &Symbol) -> Result<Self, super::env::Error> {
v.try_into()
}
}

#[cfg(not(target_family = "wasm"))]
impl TryFromVal<Env, ScVal> for Symbol {
type Error = ConversionError;
type Error = super::env::Error;
fn try_from_val(env: &Env, val: &ScVal) -> Result<Self, Self::Error> {
Ok(SymbolVal::try_from_val(env, &Val::try_from_val(env, val)?)?
.try_into_val(env)
Expand All @@ -176,7 +176,7 @@ impl TryFromVal<Env, ScVal> for Symbol {

#[cfg(not(target_family = "wasm"))]
impl TryFromVal<Env, ScSymbol> for Symbol {
type Error = ConversionError;
type Error = super::env::Error;
fn try_from_val(env: &Env, val: &ScSymbol) -> Result<Self, Self::Error> {
Ok(SymbolVal::try_from_val(env, val)?
.try_into_val(env)
Expand Down
4 changes: 2 additions & 2 deletions soroban-sdk/src/tests/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ fn default_and_from_snapshot_same_settings() {

let logs1 = env1.logs().all();
let logs2 = env2.logs().all();
assert_eq!(logs1, &["[Diagnostic Event] contract:0000000000000000000000000000000000000000000000000000000000000001, topics:[log], data:\"test\""]);
assert_eq!(logs2, &["[Diagnostic Event] contract:0000000000000000000000000000000000000000000000000000000000000001, topics:[log], data:\"test\""]);
assert_eq!(logs1, &["[Diagnostic Event] contract:CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM, topics:[log], data:\"test\""]);
assert_eq!(logs2, &["[Diagnostic Event] contract:CAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD2KM, topics:[log], data:\"test\""]);
}

#[test]
Expand Down
Loading
Loading