tools icon indicating copy to clipboard operation
tools copied to clipboard

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

Open mgravitt opened this issue 3 years ago • 4 comments

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 avatar Mar 19 '21 21:03 mgravitt

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

mgravitt avatar Jan 06 '22 15:01 mgravitt

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 -

  • add an additional param in the split linked above
  • if a query (only on queries) and the additional param is keys or entries do api[type][section][method][extra] here https://github.com/polkadot-js/tools/blob/master/packages/api-cli/src/api.ts#L191

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

jacogr avatar Jan 06 '22 15:01 jacogr

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

didiermis avatar Jan 03 '23 23:01 didiermis

This is where the parts are split - https://github.com/polkadot-js/tools/blob/ed3c79339aac4a9469a8474bc8484ddd4055647b/packages/api-cli/src/runcli.ts#L187

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 avatar Jan 04 '23 06:01 jacogr