Substrate.NET.API icon indicating copy to clipboard operation
Substrate.NET.API copied to clipboard

Add a or `string ToJson(Metadata metadata)` method to `Method` class

Open RostislavLitovkin opened this issue 2 years ago • 4 comments

It would be good to show the Method contents so that the users can be sure what he is signing.

It would be able to Decode the pallet name, call name and parameter data according to the provided metadata.

This is an example from HydraDX:

Screenshot 2024-01-30 at 18 50 09

RostislavLitovkin avatar Jan 30 '24 17:01 RostislavLitovkin

If you are using the SignPayloadAsync you get most of the information, But I agree the important ones are encoded in the byte[] parameters. We could allow to use an object, that implements IEncode, which you might be able to cast into the right parameters call. So you would be able to get the necessary information, out of the payload, previous to signing.

darkfriend77 avatar Jan 31 '24 11:01 darkfriend77

It would lead to something like this where the parameters would be an array of ITypes at best

image

you would have to cast it back into the main class, could use reflection.

darkfriend77 avatar Jan 31 '24 13:01 darkfriend77

It would be best if it could be translated from the SCALE encoded Method bytes.

The workaround you are suggesting will not work if the Method bytes are sent from a javascript dApp, which is how I would like to use it.

It would be great to be able to Decode the bytes back into the ITypes. Do you think it would be doable?

RostislavLitovkin avatar Feb 02 '24 17:02 RostislavLitovkin

Yes, depending on what you exactly get, it should be doable to decode it back into the specific Type, format https://github.com/SubstrateGaming/Substrate.NET.API/blob/cafdc160cbcde077fa3f42c0b3168a1b08c448e4/Substrate.NetApi/Model/Extrinsics/Extrinsic.cs#L68

darkfriend77 avatar Feb 05 '24 18:02 darkfriend77