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

Subxt parse kilt metadata failed. response: expected u32, found u64 #369

Closed
atenjin opened this issue Dec 14, 2021 · 6 comments
Closed

Subxt parse kilt metadata failed. response: expected u32, found u64 #369

atenjin opened this issue Dec 14, 2021 · 6 comments

Comments

@atenjin
Copy link

atenjin commented Dec 14, 2021

env:
test repo:
git repo: https://github.com/atenjin/kilt-client (https://github.com/atenjin/kilt-client/tree/try/subxt)
branch: try/subxt

metadata: from endpoint wss://peregrine.kilt.io/ directly, it's version is V14.

when call system_version it return v1.1.1, so I guess the runtime source code is related to this https://github.com/KILTprotocol/mashnet-node/commit/ba08a359936846cbfee4b7ebce3af1b0f884f321

and the metadata I get from the endpoint throught subxt-cli is in : https://github.com/atenjin/kilt-client/blob/try%2Fsubxt/res/metadata.scale

subxt version: 78626eb5eef60b52fd199adb26a724e68c4fdb55
substrate version: b9cafba3d0e7a5950ac78d81e4ab7f2074938666

replay method:

git clone https://github.com/atenjin/kilt-client
git checkout -b try/subxt try/subxt

Then compile it, I get an error:

error[E0308]: mismatched types
  --> src/main.rs:12:1
   |
12 | #[subxt::subxt(runtime_metadata_path = "res/metadata.scale")]
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   | |
   | expected `u32`, found `u64`
   | expected `u32` because of return type
   |
   = note: this error originates in the attribute macro `subxt::subxt` (in Nightly builds, run with -Z macro-backtrace for more info)
help: you can convert a `u64` to a `u32` and panic if the converted value doesn't fit
   |
12 | #[subxt::subxt(runtime_metadata_path = "res/metadata.scale")].try_into().unwrap()
   |

For more information about this error, try `rustc --explain E0308`.
error: could not compile `kilt-client` due to previous error

It seems not a custom type error, like not finding the right type path or else. So I'm confused for the converting type error.

@trusch
Copy link

trusch commented Dec 15, 2021

+1 on this, I'm running into the same problem.

@ascjones
Copy link
Contributor

The problem here appears to be that the Index type for the DefaultConfig is u32 whereas it looks to be configured to be a u64 in the kilt runtime.

The way I figure this out was to use subxt-cli like so to generate the code that is normally generated by the macro, and then compile it directly:

subxt-cli -- codegen -f /home/andrew/code/kilt-client/res/metadata.scale | rustfmt --edition=2018 --emit=stdout > kilt.rs

There is an upcoming PR which should allow you to use your own predefined type configuration for your runtime: #373. This likely won't be merged until next year since there is nobody around to review it, but you can try it out with that branch, and supply your own Config impl with type Index = u64.

@trusch
Copy link

trusch commented Jan 12, 2022

@ascjones could your provide an example on how to use the code generation with a custom config in a programatic way?

@jsdw
Copy link
Collaborator

jsdw commented Jan 13, 2022

I had a go at giving you the example code that I thought would suffice, but I wasn't able to make it work offhand and so I've filed #391.

Alas @ascjones is unavailabel for a couple of weeks. I'll probably get the chance to dig into it more in the ocming days but at present it's not obvious what the best solution is!

@ascjones
Copy link
Contributor

#409

@jsdw
Copy link
Collaborator

jsdw commented Feb 1, 2022

I believe that this has been addressed so I'll close the issue now, but please re-open if I was wrong! :)

@jsdw jsdw closed this as completed Feb 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants