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.[module].[function].entries support for entries or keys #223

Open
mgravitt opened this issue Mar 19, 2021 · 4 comments
Open

query.[module].[function].entries support for entries or keys #223

mgravitt opened this issue Mar 19, 2021 · 4 comments
Milestone

Comments

@mgravitt
Copy link

When querying the DID pallet attributeNonce storage map/function using the UI, the entries are printed (see screenshot). However, when doing the same with the CLI, I receive the below error. Using v3 of substrate.

The storage definition from pallet DID this:

/// Attribute nonce used to generate a unique hash even if the attribute is deleted and recreated.
pub AttributeNonce get(fn nonce_of): map hasher(twox_64_concat) (T::AccountId, Vec<u8>) => u64;

Here is Element chat on the matter: https://matrix.to/#/!HzySYSaIhtyWrwiwEV:matrix.org/$16161900411781ctEUT:matrix.parity.io?via=matrix.parity.io&via=matrix.org&via=corepaper.org

Screenshot of UI showing the entries being printed:
image

Error message when attempting the same thing from the CLI:

polkadot-js-api query.palletDid.attributeNonce.entries                                                                       1   8370ddd 
2021-03-19 17:41:55        REGISTRY: Unable to resolve type AttributeTransaction, it will fail on construction
2021-03-19 17:41:55        METADATA: Unknown types found, no types for Attribute, AttributeTransaction
Error: palletDid.attributeNonce((AccountId,Bytes)) is a map, requiring 1 argument, 0 found
    at assert (/Users/max/.nvm/versions/node/v12.18.2/lib/node_modules/@polkadot/api-cli/node_modules/@polkadot/util/assert.js:34:11)
    at doMap (/Users/max/.nvm/versions/node/v12.18.2/lib/node_modules/@polkadot/api-cli/node_modules/@polkadot/api/util/validate.js:33:20)
    at extractStorageArgs (/Users/max/.nvm/versions/node/v12.18.2/lib/node_modules/@polkadot/api-cli/node_modules/@polkadot/api/util/validate.js:46:12)
    at overrideNoSub (/Users/max/.nvm/versions/node/v12.18.2/lib/node_modules/@polkadot/api-cli/node_modules/@polkadot/api/base/Decorate.js:418:99)
    at /Users/max/.nvm/versions/node/v12.18.2/lib/node_modules/@polkadot/api-cli/node_modules/@polkadot/api/promise/index.js:73:26
    at new Promise (<anonymous>)
    at decorateCall (/Users/max/.nvm/versions/node/v12.18.2/lib/node_modules/@polkadot/api-cli/node_modules/@polkadot/api/promise/index.js:69:10)
    at /Users/max/.nvm/versions/node/v12.18.2/lib/node_modules/@polkadot/api-cli/node_modules/@polkadot/api/promise/index.js:101:73
    at makeCall (/Users/max/.nvm/versions/node/v12.18.2/lib/node_modules/@polkadot/api-cli/api.js:187:8)
    at main (/Users/max/.nvm/versions/node/v12.18.2/lib/node_modules/@polkadot/api-cli/api.js:204:10)
    ```
@mgravitt
Copy link
Author

mgravitt commented Jan 6, 2022

Hi @jacogr - I am back to working on this. Any update on this? If you can provide a little direction, I can put a PR together.

I am starting to work with a slightly different Map though, the StorageNMap:

	type DocumentID = u32;
	type ContentGroupID = Vec<u8>;
	type ContentLabel = Vec<u8>;
	type ContentValue = Vec<u8>;

	#[pallet::storage]
	#[pallet::getter(fn values)]
	pub(super) type Documents<T> = StorageNMap<
		_, // Prefix
		(
			NMapKey<Blake2_128Concat, DocumentID>,
			NMapKey<Blake2_128Concat, ContentGroupID>,
			NMapKey<Twox64Concat, ContentLabel>,
		),
		ContentValue, // value
		ValueQuery,
	>;

thanks

@jacogr
Copy link
Member

jacogr commented Jan 6, 2022

The problem seems here - https://github.com/polkadot-js/tools/blob/master/packages/api-cli/src/api.ts#L185

it uses query.palletDid.attributeNonce and never .entries (i.e. by default doesn't seem to support .keys or .entries.

So for quick and dirty -

(For bonus on query we could also cater for .size and .hash and .at to make it more rounded)

@didiermis
Copy link

@jacogr Hey, I'm struggling with the same issue, any updates?
Could you repost the links from above? I think they were moved.

@jacogr
Copy link
Member

jacogr commented Jan 4, 2023

This is where the parts are split -

const [type, section, method] = endpoint.split('.') as [keyof ApiExt, string, string];

It only does type, section, method, so basically when you pass api.query.a.b.entries you end up with query (as type), a (as section) and b (as method) and lose the "extra" specifier that is entries.

@jacogr jacogr added this to the todo milestone Mar 14, 2023
@jacogr jacogr removed the -size-s label Mar 14, 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

3 participants