cw-paginate-storage

Crates.iocw-paginate-storage
lib.rscw-paginate-storage
version2.6.0
sourcesrc
created_at2023-07-03 10:53:50.061276
updated_at2024-11-07 23:38:37.612519
descriptionA package for paginating cosmwasm maps.
homepage
repositoryhttps://github.com/DA0-DA0/dao-contracts
max_upload_size
id906887
size20,007
publishers (github:da0-da0:publishers)

documentation

README

CosmWasm Map Pagination

This package provides generic convienence methods for paginating keys and values in a CosmWasm Map or SnapshotMap. If you use these methods to paginate the maps in your contract you may make larry0x happy.

Example

Given a map like:

use cw_storage_plus::Map;

pub const ITEMS: Map<String, String> = Map::new("items");

You can use this package to write a query to list it's contents like:

use cosmwasm_std::{Deps, Binary, to_json_binary, StdResult};
use cw_storage_plus::Map;
use cw_paginate_storage::paginate_map;                         

pub const ITEMS: Map<String, String> = Map::new("items");

pub fn query_list_items(
    deps: Deps,
    start_after: Option<String>,
    limit: Option<u32>,
) -> StdResult<Binary> {
    to_json_binary(&paginate_map(
        deps,
        &ITEMS,
        start_after,
        limit,
        cosmwasm_std::Order::Descending,
    )?)
}
Commit count: 879

cargo fmt