paritytech / subxt

Interact with Substrate based nodes in Rust or WebAssembly
Other
425 stars 248 forks source link

`RUNTIME_APIS` is empty when expanded with wasm path #1858

Closed ShoyuVanilla closed 22 hours ago

ShoyuVanilla commented 4 days ago

1720 introduced a way to generate metadata from runtime wasm files, but when I try generate it like;

#[subxt_macro::subxt(
    runtime_path = "<my wasm path>"
)]
pub mod foo {}

The resulting code expanded with cargo-expand shows as

#[allow(dead_code, unused_imports, non_camel_case_types, unreachable_patterns)]
#[allow(clippy::all)]
#[allow(rustdoc::broken_intra_doc_links)]
pub mod foo {
    #[allow(unused_imports)]
    mod root_mod {
        pub use super::*;
    }
    pub static PALLETS: [&str; 63usize] = [
..
    ];
    // This is empty!
    pub static RUNTIME_APIS: [&str; 0usize] = [];

while expanding macros in previous ways like

#[subxt_macro::subxt(
    runtime_metadata_insecure_url = "wss://westend-rpc.polkadot.io")
]
pub mod foo {}

the RUNTIME_APIS is filled like

...
    pub static RUNTIME_APIS: [&str; 22usize] = [
        "Core",
        "Metadata",
        "BlockBuilder",
...

I've tried with wasm files from https://github.com/polkadot-fellows/runtimes/releases/ and https://github.com/paritytech/subxt/blob/master/artifacts/westend_runtime.wasm but all of them are expanded into empty RUNTIME_APIS

niklasad1 commented 4 days ago

/cc @pkhry any idea?

pkhry commented 4 days ago

/cc @pkhry any idea?

Let me take a quick look

jsdw commented 4 days ago

The reason for this is that the WASM loader thing calls Metadata_metadata, which only returns V14 metadata. We should use Metadata_metadata_at_version and Metadata_versions to extract the appropriate metadata (V15 is possible, V14 if not)

jsdw commented 22 hours ago

@ShoyuVanilla if you get the chance, would you be able to try again with the master branch of Subxt? Things should work properly for you now :)

ShoyuVanilla commented 22 hours ago

@ShoyuVanilla if you get the chance, would you be able to try again with the master branch of Subxt? Things should work properly for you now :)

Actually, I've tried with pkhry's PR branch already and it worked nicely 😄 Thanks for your great work!