paritytech / subxt

Interact with Substrate based nodes in Rust or WebAssembly
Other
407 stars 244 forks source link

Generate the client from the metadata #97

Closed Demi-Marie closed 2 years ago

Demi-Marie commented 4 years ago

Currently, all client implementations are written by hand. This works, but is very tedious and won’t scale to large runtimes.

A better option is to generate the client. This is already done by the TypeScript client implementation, so it should be quite doable for the Rust one.

jiyilanzhou commented 3 years ago

Currently, all client implementations are written by hand. This works, but is very tedious and won’t scale to large runtimes.

If I want send a pallet method transaction, How can I accomplish this.

gregdhill commented 3 years ago

I've been working on subxt-gen to do exactly this, but it's still very much a work-in-progress (constructed from parts of subsee and substrate-subxt/proc-macro). @ascjones would you be interested in integrating this upstream (alongside proc-macro)? My goal is to provide a builder similar to how tonic uses prost for generating code from protobuf so that a client library only needs to download the encoded metadata.

ascjones commented 3 years ago

Yes indeed @gregdhill, that has always been the long term goal, the main issue being the lack of rich type metadata. However I am making steady progress on that front, I have just been able to produce v13 metadata for the whole substrate node-runtime (calls and events only for now). See https://github.com/paritytech/substrate/discussions/8370#discussioncomment-547988.

Some work I have done a long time ago on consuming that metadata and generating types can be found here https://github.com/ascjones/chameleon. It's purely proof of concept atm but could eventually be used as part of the API generation from the metadata.

olanod commented 2 years ago

For dynamic clients like sube(no code generation) another approach is to use scales that can be used to serialize the storage items directly to JSON(or other formats) or some JSON input try to coerce it to the correct SCALE format following the specified type info.