Skip to content
This repository has been archived by the owner on Sep 14, 2023. It is now read-only.

Fetch all the items from a StorageMap #643

Closed
lrazovic opened this issue Feb 22, 2023 · 1 comment · Fixed by #644
Closed

Fetch all the items from a StorageMap #643

lrazovic opened this issue Feb 22, 2023 · 1 comment · Fixed by #644
Assignees
Labels

Comments

@lrazovic
Copy link
Contributor

Feature Request

I have the following FRAME Storage Item: A StorageMap with an id as key and a struct as a value.

#[pallet::storage]
#[pallet::getter(fn projects)]
pub type Projects<T: Config> =
    StorageMap<_, Blake2_128Concat, T::ProjectIdentifier, ProjectOf<T>>;

It's very easy to fetch a single value using Capi:

const result = await Funding.Projects.entry([project_identifier]).run()

On polkadot.js you can also omit the key and get back all the content of the storage item. e.g.

I'm trying to replicate the same behaviour using Capi, without success. I tried:

const assets = await Assets.Asset.entry([]).run()

but the parameter of the entry(...) method should be a [number] | Rune<[number], never>.

I also tried

const assets = await Assets.Asset.entry([] as any).run()

But I'm getting undefined as result.

It would be very useful to be able to fetch an unknown quantity of elements as is done on polkadot.js, perhaps even implementing some kind of pagination. I am available for further details or necessary tests.

@harrysolovay harrysolovay self-assigned this Feb 22, 2023
@harrysolovay
Copy link
Contributor

The ability to retrieve the entire map could be a foot gun. In the interest of explicit control over the retrieval size, we'll opt for a StorageRune entryPage method to complement keyPage. This will be complemented by #567.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

2 participants