Adds try_get for StorageMap and StorageDoubleMap (#7774)

* Adds `try_get` for `StorageMap` and `StorageDoubleMap`

* Switch to Value as return type
This commit is contained in:
Bastian Köcher
2020-12-22 15:41:49 +01:00
committed by GitHub
parent 29498f4cbe
commit a6c392d0cc
5 changed files with 54 additions and 9 deletions
@@ -153,6 +153,13 @@ impl<K1, K2, V, G> storage::StorageDoubleMap<K1, K2, V> for G where
G::from_optional_value_to_query(unhashed::get(&Self::storage_double_map_final_key(k1, k2)))
}
fn try_get<KArg1, KArg2>(k1: KArg1, k2: KArg2) -> Result<V, ()>
where
KArg1: EncodeLike<K1>,
KArg2: EncodeLike<K2> {
unhashed::get(&Self::storage_double_map_final_key(k1, k2)).ok_or(())
}
fn take<KArg1, KArg2>(k1: KArg1, k2: KArg2) -> Self::Query where
KArg1: EncodeLike<K1>,
KArg2: EncodeLike<K2>,
@@ -226,6 +226,10 @@ impl<K: FullEncode, V: FullCodec, G: StorageMap<K, V>> storage::StorageMap<K, V>
G::from_optional_value_to_query(unhashed::get(Self::storage_map_final_key(key).as_ref()))
}
fn try_get<KeyArg: EncodeLike<K>>(key: KeyArg) -> Result<V, ()> {
unhashed::get(Self::storage_map_final_key(key).as_ref()).ok_or(())
}
fn insert<KeyArg: EncodeLike<K>, ValArg: EncodeLike<V>>(key: KeyArg, val: ValArg) {
unhashed::put(Self::storage_map_final_key(key).as_ref(), &val)
}