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

Require TryFrom::Error to impl Debug #162

Merged
merged 3 commits into from
Jul 5, 2022
Merged
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
20 changes: 13 additions & 7 deletions sdk/src/env.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use core::fmt::Debug;

#[cfg(target_family = "wasm")]
pub mod internal {
pub use stellar_contract_env_guest::*;
Expand Down Expand Up @@ -84,7 +86,7 @@ impl Env {

pub fn get_invoking_contract(&self) -> ArrayBinary<32> {
let rv = internal::Env::get_invoking_contract(self).to_raw();
let bin = Binary::try_from_val(self, rv).map_err(|_| ()).unwrap();
let bin = Binary::try_from_val(self, rv).unwrap();
bin.try_into().unwrap()
}

Expand All @@ -93,9 +95,12 @@ impl Env {
rv.try_into().unwrap()
}

pub fn get_contract_data<K: IntoVal<Env, RawVal>, V: IntoTryFromVal>(&self, key: K) -> V {
pub fn get_contract_data<K: IntoVal<Env, RawVal>, V: IntoTryFromVal>(&self, key: K) -> V
where
V::Error: Debug,
{
let rv = internal::Env::get_contract_data(self, key.into_val(self));
V::try_from_val(&self, rv).map_err(|_| ()).unwrap()
V::try_from_val(self, rv).unwrap()
}

pub fn put_contract_data<K: IntoVal<Env, RawVal>, V: IntoTryFromVal>(&self, key: K, val: V) {
Expand All @@ -112,12 +117,13 @@ impl Env {
bin_obj.in_env(self).try_into().unwrap()
}

pub fn deserialize_from_binary<V: IntoTryFromVal>(&self, bin: Binary) -> V {
pub fn deserialize_from_binary<V: IntoTryFromVal>(&self, bin: Binary) -> V
where
V::Error: Debug,
{
let bin_obj: Object = RawVal::from(bin).try_into().unwrap();
let val_obj = internal::Env::deserialize_from_binary(self, bin_obj);
V::try_from_val(&self, val_obj.into_val(self))
.map_err(|_| ())
.unwrap()
V::try_from_val(self, val_obj.into_val(self)).unwrap()
}

pub fn compute_hash_sha256(&self, msg: Binary) -> Binary {
Expand Down