Skip to content

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

@harsh-supra

Description

@harsh-supra

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>,
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions