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

Keep argument names in for extrinsic calls in v14 #58

Closed

Conversation

elliot-u410
Copy link

@elliot-u410 elliot-u410 commented Oct 26, 2021

Fixes #57

@cla-bot-2021
Copy link

cla-bot-2021 bot commented Oct 26, 2021

User @Noch3, please sign the CLA here.

@insipx insipx requested a review from jsdw October 27, 2021 14:13
Copy link
Contributor

@insipx insipx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -48,7 +48,7 @@ pub fn decode(meta: RuntimeMetadataV14) -> Result<Metadata, MetadataError> {
for variant in call_variant.variants() {
// Allow case insensitive matching; lowercase the name:
let name = variant.name().to_ascii_lowercase();
let args = variant.fields().iter().map(|field| *field.ty()).collect();
let args = variant.fields().iter().map(|field| (*field.ty(), field.name().map(|x| x.clone()))).collect();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let args = variant.fields().iter().map(|field| (*field.ty(), field.name().map(|x| x.clone()))).collect();
let args = variant.fields().iter().map(|field| (*field.ty(), field.name().cloned()))).collect();

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh I suspected this would work but forgot to try. Thanks.

@elliot-u410
Copy link
Author

Now I'm wondering if there's a way we can just keep all of the Field data instead of only the name. Eventually I'd like the parsed Extrinsic to have all this as annotations so one can easily display a very verbose description of the extrinsic.

@@ -151,7 +151,7 @@ impl MetadataCall {
/// The types expected to be provided as arguments to this call.
/// [`TypeId`]'s can be resolved into [`Type`]'s using
/// [`Metadata::resolve_type`]
Copy link
Contributor

@insipx insipx Oct 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, not part of your PR but this comment should be:

Suggested change
/// [`Metadata::resolve_type`]
/// [`Metadata::types`]

resolve_type fn does not exist on metadata, instead resolve is accessed by first calling types()

@insipx
Copy link
Contributor

insipx commented Oct 27, 2021

Now I'm wondering if there's a way we can just keep all of the Field data instead of only the name. Eventually I'd like the parsed Extrinsic to have all this as annotations so one can easily display a very verbose description of the extrinsic.

Yeah I think this is definitely possible. I'm not totally clear on what information might be missing, though. Extrinsic is a list of arguments that were executed in a fn call (with a signature/signed extension attached if it's signed)

Maybe you're talking about doc comments and stuff?

@elliot-u410
Copy link
Author

Yes I'm imagining a way to show the tree of calls along with argument names, type names, and docs for each argument. The calls can be nested (if you use batch or proxy) so that the full tree might be rather large. But the goal is to basically give someone a lot of confidence that the thing they plan to sign is in fact what they intended to do.

Copy link
Contributor

@dvdplm dvdplm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to include the docs here as well? Code lgtm modulo the clippy complaints.

@jsdw
Copy link
Collaborator

jsdw commented Oct 28, 2021

I also think that we should look to expose as best as possible all of the information one might need. To avoid copying too much data out of the type registry, I'd lean towards exposing the type information fairly directly, possibly starting with the call variant information. Thst way, you can dig through the types as much as you like to get out the information you need.

So far, the metadata struct has been kept deliberately fairly opaque (see the pub crate fns), and the scale-info types kept hidden away, but I definitely see the value in exposing access to the type information stored in the metadata!

@elliot-u410
Copy link
Author

I'll close this in favor of a better design that keeps everything!

@jsdw
Copy link
Collaborator

jsdw commented Nov 1, 2021

My plan is to work on that quite shortly; there is some other refactoring I might do as part of such a change :)

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

Successfully merging this pull request may close these issues.

Parse and retain metadata call argument names
5 participants