2

I want to decode the polkadot's extrinsics I received through json-rpc (at rust or java).

But every time I leave a question here, there's no clear answer.

First, I'm using subxt.

(subxt : https://github.com/paritytech/subxt)

They are decoding it through structure unchecked_extrinsic.

What is the difference between check_extrinsic and uncheck_extrinsic and opaque_extrinsic?

And is it the right way to try it? I really want to decode it.

3 Answers 3

3

The correct way to work with data coming from a substrate node is to use a tool or library that uses the Metadata to decode rpc responses correctly, as shown here: https://docs.substrate.io/v3/runtime/metadata/

Virtually everything you get from a substrate node over RPC will be SCALE encoded - SCALE requires that you have knowledge of the types in the data that you are working before trying to decode it. There are implementations available in many languages but it is probably better to use something that handles the process of getting the Metadata for you as well as described previously.

Regarding the specific types you were asking about: an unchecked extrinsic is an extrinsic with all of the extra data required to verify it's validity still included in it - as you can see for example in the subxt codebase here, the general format is:

{
  address, 
  encoded data,
  signature, 
  extra signed data,
}

where the contents of the encoded data and extra signed data depend on the specific substrate chain you are working with.

an opaque extrinsic is the same thing, but the structure is not exposed to the code. It is simply a convention to specify a type as opaque if it's structure is not known or relevant at runtime.

1
  • Thank you so much. It helped.
    – PaperFrog
    Feb 22, 2022 at 3:44
4

UncheckedExtrinsic is the format in which the outside is sending the extrinsic to the node. This extrinsic is aware of the full structure, meaning it knows how to decode the Call signature etc. The UncheckedExtrinsic is converted to a CheckedExtrinsic in the process of applying an extrinsic. These are two structures, that you can not accidentally apply an UncheckedExtrinsic, because that one doesn't implement the required traits. Basically some trick to bring the status of the extrinsic to the type level.

OpaqueExtrinsic is being used on the node side to represent an extrinsic. To support forkless upgrades Substrate has the separation of the node and the runtime. The idea is that the node should not know "anything" about the internals of the runtime. This includes supported Calls etc. The node is only using specified interfaces (called runtime api in the Substrate context) to talk to the runtime. As the node doesn't know the exact structure of the extrinsic and thus, it just keeps the extrinsic as OpaqueExtrinsic. This OpaqueExtrinsic is handling the extrinsic as Vec<u8>, because the UncheckedExtrinsic encoded format is similar to the one of a Vec<u8> (prefixed with a compact length).

However, all of this can be changed. These are just the default types that ship with Substrate. If a Substrate implementer requires a different extrinsic format, they can just implement the required traits and then use this. Maybe this extrinsic format would give the node more insight to the extrinsic etc, but this is up to the implementer.

0

Different checking mechanisms exists within an extrinsic, to provide a way for applications to ensure some requirements for the extrinisic are met and that it's correctly constructed. To answer your first question, these can be:

  • Unchecked: these are signed transactions that require some validation check before they can be accepted in the transaction pool. Any unchecked extrinsic contains the signature for the data being sent plus some extra data.
  • Checked: inherent extrinsics which by definition don't require signature verification. Instead, they carry information on where the extrinsic comes from and some extra data.
  • Opaque: used for cases when an extrinsic hasn't yet been committed to a format but can still be decoded.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.