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

Support Runtime Api calls #520

Closed
haerdib opened this issue Apr 5, 2023 · 3 comments · Fixed by #703
Closed

Support Runtime Api calls #520

haerdib opened this issue Apr 5, 2023 · 3 comments · Fixed by #703
Assignees
Labels
F8-newfeature Introduces a new feature Q9-needsdesign

Comments

@haerdib
Copy link
Contributor

haerdib commented Apr 5, 2023

So far the api-client does not support runtime api calls. The goal of this issue is to facilitate runtime api calls, in general, and provide helper functions for the runtime api calls of the most commonly used pallets.

Available Runtime Calls: https://polkadot.js.org/docs/polkadot/runtime

Hands on testing: https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Frpc.dotters.network%2Fkusama#/runtime

Subxt has already put some thoughts into it: see paritytech/subxt#918

Task description

Implement helper functions, just like our rpc calls

async fn get_account_info(
&self,
address: &Self::AccountId,
) -> Result<Option<AccountInfo<Self::Index, Self::AccountData>>> {
let storagekey: StorageKey = self.metadata().storage_map_key::<Self::AccountId>(
"System",
"Account",
address.clone(),
)?;

that directly access the node api and return the information.

Example code from subxt:

// Create a dynamically runtime API payload that calls the
// `AccountNonceApi_account_nonce` function.
let account = dev::alice().public_key();
let runtime_api_call = subxt::dynamic::runtime_api_call(
    "AccountNonceApi",
    "account_nonce",
    vec![Value::from_bytes(account)],
);

And as reference: here's the call executed by the rpc: https://github.com/paritytech/subxt/blob/9a8fc33f2fe830009011e997773071099101d69b/subxt/src/runtime_api/runtime_types.rs#L43-L106

Already implemented:

@haerdib
Copy link
Contributor Author

haerdib commented Jul 10, 2023

Up to date Substrate nodes should already include metadata v15 by default. So this feature should (once the Susbtrate deps are upgraded) already be testable by CI (see PR paritytech/substrate#14481 for more information)

@masapr
Copy link
Collaborator

masapr commented Jul 10, 2023

To me it's not clear: do we implement all calls manually? Or do we generate code? If we generate code automatically, do we do this frequently/whenever there are changes in the runtime api call?

@haerdib
Copy link
Contributor Author

haerdib commented Jul 10, 2023

Currently, we are not generating code at all in the api-client. So for now, I'd stick to hard coded helper functions and one function that allows a generic "String" input... or Probably two Strings, as in polkadot.js:
grafik

If we want to go more in the direction of code producing code, I believe that should be addressed in a different issue, as it also affects the already implemented RPC calls.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F8-newfeature Introduces a new feature Q9-needsdesign
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants