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 for runtime RPC APIs #631

Closed
niklasad1 opened this issue Aug 23, 2022 · 4 comments
Closed

support for runtime RPC APIs #631

niklasad1 opened this issue Aug 23, 2022 · 4 comments
Labels
needs thought We need to resolve some questions before we can work on this

Comments

@niklasad1
Copy link
Member

niklasad1 commented Aug 23, 2022

Currently subxt is great of supporting storage and transactions but as substrate is increasingly moving towards these runtime RPC APIs which is a bit more work to use in context of subxt.

The runtime RPC APIs works as follows:

  • make a RPC call to state_call(method, call_data)
  • method: is the name of the runtime API such as TransactionPaymentCallApi_query_call_info
  • call_data: is the custom types that the certain runtime API takes as input (encoded/decoded as a tuple in the same order as they are defined)

One is example is when I tried to get TransactionPaymentCallApi::query_call_info(call: Call, len: u32) working:

    let tx = runtime::tx().election_provider_multi_phase().submit_unsigned(Default::default(), SolutionOrSnapshotSize { voters, targets });
    
    // call_data is (Call, len)
    let call_data = {
        let mut buffer = Vec::new();

        // this is already encoded so just push it to buffer directly
        let encoded_call = client.tx().call_data(&tx).unwrap();
        // this needs to be encoded....
        let encoded_len = encoded_call.len() as u32;

        buffer.extend(encoded_call);
        encoded_len.encode_to(&mut buffer);

        Bytes(buffer)
    };

    let bytes: Bytes = client
        .rpc()
        .client
        .request(
            "state_call",
            rpc_params!["TransactionPaymentCallApi_query_call_info", call_data],
        )
        .await
        .unwrap();

It's easy to get wrong if you are not really familiar how scale encoding works

Thus, it would be great if subxt could generate these runtime APIs similar to how transactions and storage are supported by subxt but I don't know whether it possible to fetch these via the metadata or something else like inspecting the WASM blob.....

@niklasad1
Copy link
Member Author

Ok, this seems depend on paritytech/substrate#11648

@jsdw
Copy link
Collaborator

jsdw commented Aug 23, 2022

I'd love this too. I could see an api.call().submit(SomeCall { foo: 2, bar: true }) sort of API that was a similar to the api.tx() one and let you submit dynamic or static call data and decoded the results.

@ascjones
Copy link
Contributor

See use-ink/cargo-contract#701 for an example of manual code it would replace

@jsdw
Copy link
Collaborator

jsdw commented May 3, 2023

This is closed by #918 :)

The node will need to support the (currently unstable) V15 metadata at the right version for it to work, but the logic exists in Subxt master to codegen Runtime API calls now at least (albeit behind an "unstable-metadata" flag.

When V15 metadata stabillises in Substrate, so will this ability in Subxt.

@jsdw jsdw closed this as completed May 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs thought We need to resolve some questions before we can work on this
Projects
None yet
Development

No branches or pull requests

3 participants