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

Basic/configurable no-metadata state_call interfaces #4987

Merged
merged 23 commits into from
Jun 29, 2022
Merged

Conversation

jacogr
Copy link
Member

@jacogr jacogr commented Jun 27, 2022

Will have to see if this actually makes it in - the issue is that 95% of this is throw-away (or needs to be completely moved), so unsure if the maintenance pain on this is actually worth it while there is 0 info from the metadata. (Stuff that goes in has a very long lifetime as we don't want to end up with the current "do everything manually" mess we have elsewhere)

Closes #4930

Tested with -

import '@polkadot/api-augment';
import '@polkadot/api-augment/substrate/runtime';

import { ApiPromise, WsProvider } from '@polkadot/api';

async function main () {
  const api = await ApiPromise.create({
    provider: new WsProvider('wss://kusama-rpc.polkadot.io'),
    runtime: {
      AccountNonceApi: [
        {
          methods: {
            account_nonce: {
              description: 'The API to query account nonce (aka transaction index)',
              params: [
                {
                  name: 'accountId',
                  type: 'AccountId'
                }
              ],
              type: 'Index'
            }
          }
        }
      ],
      GrandpaApi: [
        {
          methods: {
            current_set_id: {
              description: 'Get current GRANDPA authority set id.',
              params: [],
              type: 'SetId'
            },
            grandpa_authorities: {
              description: 'Get the current GRANDPA authorities and weights. This should not change except for when changes are scheduled and the corresponding delay has passed.',
              params: [],
              type: 'AuthorityList'
            }
          },
          version: 3
        }
      ]
    }
  });

  const [gid, gau, non] = await Promise.all([
    api.runtime.grandpaApi.currentSetId(),
    api.runtime.grandpaApi.grandpaAuthorities(),
    api.runtime.accountNonceApi.accountNonce('EQBwtmKWCyRrQ8yGWg7LkB8p7hpEKXZz4qUg9WR8hZmieCM')
  ]);

  console.log(
    'setId=', gid.toHuman(),
    'nonce=', non.toHuman(),
    'authorities=', gau.toHuman()
  );
};

main().then(() => process.exit());

Obviously a bit funny since the augmentation (manually applied) is being generated for all the functions above, however it doesn't get auto-applied to the API config since we really don't want, at this point, to maintain more manual interfaces. At the same point, generation needs to be tested, so some raw definitions which are not applied, do exist. (Only for the functions detailed above)

... if these are contributed and stable, we could change the above an include at least some by default.

@jacogr jacogr added the WIP Work in Progress label Jun 27, 2022
@semgrep-app
Copy link

semgrep-app bot commented Jun 28, 2022

Semgrep found 5 template-explicit-unescape findings:

  • packages/typegen/src/templates/calls.hbs: L3, L8, L11, L11, L11

Detected an explicit unescape in a Mustache template, using triple braces '{{{...}}}' or ampersand '&'. If external data can reach these locations, your application is exposed to a cross-site scripting (XSS) vulnerability. If you must do this, ensure no external data can reach this location.

⚪️ This finding does not block your pull request.
🙈 From javascript.express.security.audit.xss.mustache.explicit-unescape.template-explicit-unescape.

@jacogr jacogr added -auto and removed WIP Work in Progress labels Jun 29, 2022
@jacogr jacogr merged commit ac1837c into master Jun 29, 2022
@jacogr jacogr deleted the jg-state_call branch June 29, 2022 10:12
@polkadot-js-bot
Copy link

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@polkadot-js polkadot-js locked as resolved and limited conversation to collaborators Jul 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Convenient way to invoke runtime API
2 participants