Skip to content

Commit

Permalink
Improve contract data (#149)
Browse files Browse the repository at this point in the history
* Improve Env contract data interface

* Implement Env::has_contract_data

* Avoid using map_err in get_contract_data

* Revert "Avoid using map_err in get_contract_data"

This reverts commit 71d637d.
  • Loading branch information
jonjove authored Jun 27, 2022
1 parent d993e91 commit b1fa1b4
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions sdk/src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,21 @@ impl Env {
bin.try_into().unwrap()
}

pub fn put_contract_data<K: IntoTryFromVal, V: IntoTryFromVal>(&self, key: K, val: V) {
pub fn has_contract_data<K: IntoVal<Env, RawVal>>(&self, key: K) -> bool {
let rv = internal::Env::has_contract_data(self, key.into_val(self));
rv.try_into().unwrap()
}

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

pub fn put_contract_data<K: IntoVal<Env, RawVal>, V: IntoTryFromVal>(&self, key: K, val: V) {
internal::Env::put_contract_data(self, key.into_val(self), val.into_val(self));
}

pub fn del_contract_data<K: IntoTryFromVal>(&self, key: K) {
pub fn del_contract_data<K: IntoVal<Env, RawVal>>(&self, key: K) {
internal::Env::del_contract_data(self, key.into_val(self));
}
}
Expand Down

0 comments on commit b1fa1b4

Please sign in to comment.