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

Query function to fetch the length of HashMap works inefficiently when the key is of type Vec<u8> #67

Open
harsh-supra opened this issue Apr 29, 2024 · 1 comment

Comments

@harsh-supra
Copy link

I have created a contract which requires to query the length of a HashMap, So when the Key of this particular HashMap I use as Vec<u8> , the length is always returned as 0, whereas If I use String as the Key type, the function works perfectly fine. Am I missing something in here? Sharing the Query function snippet below for reference:

pub fn get_no_of_root_hashes(deps: Deps) -> Result<usize, ContractError> {
        let state = STATE.load(deps.storage)?;
        println!("Query: {:?}", state.root_hashes.len());
        Ok(state.root_hashes.len())
    }
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
pub struct State {
    pub owner: cosmwasm_std::Addr,
    pub com_to_pub_key: HashMap<u64, Vec<u8>>,
    pub root_hashes: HashMap<Vec<u8>, u64>,
}
@chipshort
Copy link

chipshort commented Apr 30, 2024

What does the json look like that is saved inside STATE and how do you save it there?
When I try serializing a State struct, it correctly errors with "JSON object key is required to be a string type."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants