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

CW20 All accounts query sorting issue #864

Closed
haris8103 opened this issue Mar 20, 2023 · 1 comment
Closed

CW20 All accounts query sorting issue #864

haris8103 opened this issue Mar 20, 2023 · 1 comment

Comments

@haris8103
Copy link

haris8103 commented Mar 20, 2023

Hi team,

Hope you are doing well, I am a beginner in rust and cosmwasm. I am facing an issue in querying all accounts they are not in sorted manner and also there are repeating accounts in query as i am using cw20-base-0.13.4 for this query to being called for cw20 token contract.
Kindly look into it and suggest. Your prompt response will be highly appreciated.

For the reference i have attached the code from cw20-base-0.13.4/src/enumerable.rs .

pub fn query_all_accounts(
    deps: Deps,
    start_after: Option<String>,
    limit: Option<u32>,
) -> StdResult<AllAccountsResponse> {
    let limit = limit.unwrap_or(DEFAULT_LIMIT).min(MAX_LIMIT) as usize;
    let start = start_after.map(|s| Bound::ExclusiveRaw(s.into()));

    let accounts = BALANCES
        .keys(deps.storage, start, None, Order::Ascending)
        .take(limit)
        .map(|item| item.map(Into::into))
        .collect::<StdResult<_>>()?;

    Ok(AllAccountsResponse { accounts })
}

Regards,
Haris.

@ueco-jb
Copy link
Collaborator

ueco-jb commented Mar 20, 2023

This test case https://github.com/CosmWasm/cw-plus/blob/v0.13.4/contracts/cw20-base/src/enumerable.rs#L150-L195
shows that both cases you mentioned are working.

@ueco-jb ueco-jb closed this as completed Mar 20, 2023
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