-
Notifications
You must be signed in to change notification settings - Fork 355
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
Deprecate IntKey #547
Deprecate IntKey #547
Changes from all commits
af0be03
6a77a4a
c1e1462
c2a288c
3594c02
18a48a9
d2c4e69
7c4b4d7
599b60d
d3fab98
a086fc9
db47152
6cdc823
38c6a58
f0cfa5c
61dbbd1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ | |
use serde::de::DeserializeOwned; | ||
use std::any::type_name; | ||
|
||
use crate::keys::Key; | ||
|
||
use cosmwasm_std::{ | ||
from_slice, to_vec, Addr, Binary, ContractResult, Empty, QuerierWrapper, QueryRequest, | ||
StdError, StdResult, SystemResult, WasmQuery, | ||
|
@@ -20,15 +22,15 @@ pub(crate) fn may_deserialize<T: DeserializeOwned>( | |
value: &Option<Vec<u8>>, | ||
) -> StdResult<Option<T>> { | ||
match value { | ||
Some(vec) => Ok(Some(from_slice(&vec)?)), | ||
Some(vec) => Ok(Some(from_slice(vec)?)), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think Any idea when this changed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No idea. One way to check it could be compiling with different versions, and see in which one this started to work. The match is producing a ref, and that ref is being converted to slice without any help. Not sure this wasn't supported earlier... |
||
None => Ok(None), | ||
} | ||
} | ||
|
||
/// must_deserialize parses json bytes from storage (Option), returning NotFound error if no data present | ||
pub(crate) fn must_deserialize<T: DeserializeOwned>(value: &Option<Vec<u8>>) -> StdResult<T> { | ||
match value { | ||
Some(vec) => from_slice(&vec), | ||
Some(vec) => from_slice(vec), | ||
None => Err(StdError::not_found(type_name::<T>())), | ||
} | ||
} | ||
|
@@ -54,25 +56,25 @@ pub(crate) fn namespaces_with_key(namespaces: &[&[u8]], key: &[u8]) -> Vec<u8> { | |
/// there are multiple sets we do not want to combine just to call this | ||
pub(crate) fn nested_namespaces_with_key( | ||
top_names: &[&[u8]], | ||
sub_names: &[&[u8]], | ||
sub_names: &[Key], | ||
key: &[u8], | ||
) -> Vec<u8> { | ||
let mut size = key.len(); | ||
for &namespace in top_names { | ||
size += namespace.len() + 2; | ||
} | ||
for &namespace in sub_names { | ||
size += namespace.len() + 2; | ||
for namespace in sub_names { | ||
size += namespace.as_ref().len() + 2; | ||
} | ||
|
||
let mut out = Vec::with_capacity(size); | ||
for &namespace in top_names { | ||
out.extend_from_slice(&encode_length(namespace)); | ||
out.extend_from_slice(namespace); | ||
} | ||
for &namespace in sub_names { | ||
out.extend_from_slice(&encode_length(namespace)); | ||
out.extend_from_slice(namespace); | ||
for namespace in sub_names { | ||
out.extend_from_slice(&encode_length(namespace.as_ref())); | ||
out.extend_from_slice(namespace.as_ref()); | ||
} | ||
out.extend_from_slice(key); | ||
out | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, cool.. just started commenting how we need both. Then see how we do.
Nice!