polkadot-js / tools

Various cli tools for Polkadot and Substrate chains, including basic node monitoring, making API queries via a cli app and other command-line tools
Apache License 2.0
278 stars 69 forks source link

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

Open mgravitt opened 3 years ago

mgravitt commented 3 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 1 year ago

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

jacogr commented 1 year ago

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.