-
Notifications
You must be signed in to change notification settings - Fork 262
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
extrinsics: Decode extrinsics from blocks #929
Conversation
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
subxt/src/blocks/block_types.rs
Outdated
/// Return the extrinsics associated with the block. | ||
pub async fn extrinsics(&self) -> Result<extrinsics::Extrinsics<T>, Error> { | ||
let block_details = self.block_details().await?; | ||
extrinsics::Extrinsics::new(self.client.metadata(), block_details.block) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was expecting all of this extrinsics stuff to end up coming from BlockBody
, below, with the idea that:
- you get hold of a block, and then load the body with
block.bocy().await?
- and then from the body you can iterate thorugh extrinsics already with
body.extrinsics()
- and then each extrinsic you get back can be decoded (and that
Extrinsic
thing can have an interface that is inspired byEventDetails
.
I don't think it really makes sense to have a separate top level extrinsics
folder, because we already have a tx
folder for constructing transactions (extrinsics) anyway, and then this blocks
folder is all about getting and working with blocks, whose bodies are simply a list of extrinsics :)
So yeah I guess I'd probably:
- move the
Extrinsic
type defined already below into a separate file in this folder if it'll be getting quite big and then - add to that type the logic for decoding them
- and then no need for eg an
ExtrinsicsClient
- no need for this
extrinsics
method (that's whatbody()
is for; downloading the block body which then contains the extrinsics)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have moved the extrinsic to the BlocksBody
to iterate over them as extrinsics()
One other thing is that we still have the find
apis that we want to mirror from the events.
Have added them with _extrinsic
prefix as in find_extrisic
, for extra clarity.
That makes me think that we could add something of the following:
struct BlockBody {
fn extrinsics() -> Extrinsics
}
struct Extrinsics {
fn find() ...
fn find_first() ...
fn iter() -> ExtrinsicDetails
}
However, the Extrinsics
struct from here would contain almost the same information as the BlockBody
in this example.
Let me know what you think of it 🙏
/// information needed to decode and iterate over them. | ||
#[derive(Derivative)] | ||
#[derivative(Debug(bound = ""), Clone(bound = ""))] | ||
pub struct Extrinsics<T: Config> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In block_types.rs
we have a BlockBody
and then an Extrinsic
when we iter over the extrinsics.
The type IDs (ExteinsicIds
are probably useful to get hold of once you load the BlockBody, so you're ready to iterate and decode extrinsics.
The hash we don't need, and then the actual bytes we could put in an Arc<[u8]>
perhaps as we do with EventDetails
(I'm not sure why it's a Vec<Arc..>
here), in order that Extrinsic
does not have any lifetime connecting it to BlockBody
(same as why we did it in eventdetails).
Then, the methods in ExtrinsicDetails
could be put onto that Extrinsic
struct that already exists (or just replace it with this one; since we have EventDetails
, ExtrinsicDetails
is consistent name wise :))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That makes sense!
The hash from the extrinsics is used to fetch the events in the implementation with OnlineClient
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
subxt/src/metadata/metadata_type.rs
Outdated
return Err(InvalidMetadataError::MissingCallType); | ||
}; | ||
|
||
let type_def_variant = get_type_def_variant(call_id)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: maybe call this something more descriptive like call_type_variants
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me :)
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
Signed-off-by: Alexandru Vasile <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
another really solid PR, good stuff
Signed-off-by: Alexandru Vasile <[email protected]>
* Update polkadot.scale Signed-off-by: Alexandru Vasile <[email protected]> * extrinsics: Add extrinsics client Signed-off-by: Alexandru Vasile <[email protected]> * extrinsics: Decode extrinsics Signed-off-by: Alexandru Vasile <[email protected]> * subxt: Add extrinsic error Signed-off-by: Alexandru Vasile <[email protected]> * blocks: Expose extrinsics Signed-off-by: Alexandru Vasile <[email protected]> * examples: Fetch and decode block extrinsics Signed-off-by: Alexandru Vasile <[email protected]> * Fix clippy Signed-off-by: Alexandru Vasile <[email protected]> * extrinsics: Fetch pallet and variant index Signed-off-by: Alexandru Vasile <[email protected]> * subxt: Move extrinsics on the subxt::blocks Signed-off-by: Alexandru Vasile <[email protected]> * example: Adjust example Signed-off-by: Alexandru Vasile <[email protected]> * metadata: Collect ExtrinsicMetadata Signed-off-by: Alexandru Vasile <[email protected]> * subxt: Implement StaticExtrinsic for the calls Signed-off-by: Alexandru Vasile <[email protected]> * Adjust examples Signed-off-by: Alexandru Vasile <[email protected]> * codegen: Add root level Call enum Signed-off-by: Alexandru Vasile <[email protected]> * Adjust testing Signed-off-by: Alexandru Vasile <[email protected]> * subxt: Add new decode interface Signed-off-by: Alexandru Vasile <[email protected]> * subxt: Merge ExtrinsicError with BlockError Signed-off-by: Alexandru Vasile <[email protected]> * examples: Find first extrinsic Signed-off-by: Alexandru Vasile <[email protected]> * Move code to extrinsic_types Signed-off-by: Alexandru Vasile <[email protected]> * Add Extrinsic struct Signed-off-by: Alexandru Vasile <[email protected]> * Adjust examples Signed-off-by: Alexandru Vasile <[email protected]> * test: Decode extinsics Signed-off-by: Alexandru Vasile <[email protected]> * extrinsics/test: Add fake metadata for static decoding Signed-off-by: Alexandru Vasile <[email protected]> * extrinsics/test: Decode from insufficient bytes Signed-off-by: Alexandru Vasile <[email protected]> * extrinsics/test: Check unsupported versions Signed-off-by: Alexandru Vasile <[email protected]> * extrinsics/test: Statically decode to root and pallet enums Signed-off-by: Alexandru Vasile <[email protected]> * extrinsics/tests: Remove clones Signed-off-by: Alexandru Vasile <[email protected]> * blocks: Fetch block body inline Signed-off-by: Alexandru Vasile <[email protected]> * blocks: Rename ExtrinsicIds to ExtrinsicPartTypeIds Signed-off-by: Alexandru Vasile <[email protected]> * extrinsics/test: Check decode as_extrinsic Signed-off-by: Alexandru Vasile <[email protected]> * blocks: Remove InsufficientData error Signed-off-by: Alexandru Vasile <[email protected]> * blocks: Return error from extrinsic_metadata Signed-off-by: Alexandru Vasile <[email protected]> * extrinsics: Postpone decoding of call bytes Signed-off-by: Alexandru Vasile <[email protected]> * metadata_type: Rename variables Signed-off-by: Alexandru Vasile <[email protected]> * Adjust calls path for example and tests Signed-off-by: Alexandru Vasile <[email protected]> * examples: Remove traces Signed-off-by: Alexandru Vasile <[email protected]> * book: Add extrinsics documentation Signed-off-by: Alexandru Vasile <[email protected]> * book: Improve extrinsics docs Signed-off-by: Alexandru Vasile <[email protected]> --------- Signed-off-by: Alexandru Vasile <[email protected]> Co-authored-by: James Wilson <[email protected]>
* Update polkadot.scale Signed-off-by: Alexandru Vasile <[email protected]> * extrinsics: Add extrinsics client Signed-off-by: Alexandru Vasile <[email protected]> * extrinsics: Decode extrinsics Signed-off-by: Alexandru Vasile <[email protected]> * subxt: Add extrinsic error Signed-off-by: Alexandru Vasile <[email protected]> * blocks: Expose extrinsics Signed-off-by: Alexandru Vasile <[email protected]> * examples: Fetch and decode block extrinsics Signed-off-by: Alexandru Vasile <[email protected]> * Fix clippy Signed-off-by: Alexandru Vasile <[email protected]> * extrinsics: Fetch pallet and variant index Signed-off-by: Alexandru Vasile <[email protected]> * subxt: Move extrinsics on the subxt::blocks Signed-off-by: Alexandru Vasile <[email protected]> * example: Adjust example Signed-off-by: Alexandru Vasile <[email protected]> * metadata: Collect ExtrinsicMetadata Signed-off-by: Alexandru Vasile <[email protected]> * subxt: Implement StaticExtrinsic for the calls Signed-off-by: Alexandru Vasile <[email protected]> * Adjust examples Signed-off-by: Alexandru Vasile <[email protected]> * codegen: Add root level Call enum Signed-off-by: Alexandru Vasile <[email protected]> * Adjust testing Signed-off-by: Alexandru Vasile <[email protected]> * subxt: Add new decode interface Signed-off-by: Alexandru Vasile <[email protected]> * subxt: Merge ExtrinsicError with BlockError Signed-off-by: Alexandru Vasile <[email protected]> * examples: Find first extrinsic Signed-off-by: Alexandru Vasile <[email protected]> * Move code to extrinsic_types Signed-off-by: Alexandru Vasile <[email protected]> * Add Extrinsic struct Signed-off-by: Alexandru Vasile <[email protected]> * Adjust examples Signed-off-by: Alexandru Vasile <[email protected]> * test: Decode extinsics Signed-off-by: Alexandru Vasile <[email protected]> * extrinsics/test: Add fake metadata for static decoding Signed-off-by: Alexandru Vasile <[email protected]> * extrinsics/test: Decode from insufficient bytes Signed-off-by: Alexandru Vasile <[email protected]> * extrinsics/test: Check unsupported versions Signed-off-by: Alexandru Vasile <[email protected]> * extrinsics/test: Statically decode to root and pallet enums Signed-off-by: Alexandru Vasile <[email protected]> * extrinsics/tests: Remove clones Signed-off-by: Alexandru Vasile <[email protected]> * blocks: Fetch block body inline Signed-off-by: Alexandru Vasile <[email protected]> * blocks: Rename ExtrinsicIds to ExtrinsicPartTypeIds Signed-off-by: Alexandru Vasile <[email protected]> * extrinsics/test: Check decode as_extrinsic Signed-off-by: Alexandru Vasile <[email protected]> * blocks: Remove InsufficientData error Signed-off-by: Alexandru Vasile <[email protected]> * blocks: Return error from extrinsic_metadata Signed-off-by: Alexandru Vasile <[email protected]> * extrinsics: Postpone decoding of call bytes Signed-off-by: Alexandru Vasile <[email protected]> * metadata_type: Rename variables Signed-off-by: Alexandru Vasile <[email protected]> * Adjust calls path for example and tests Signed-off-by: Alexandru Vasile <[email protected]> * examples: Remove traces Signed-off-by: Alexandru Vasile <[email protected]> * book: Add extrinsics documentation Signed-off-by: Alexandru Vasile <[email protected]> * book: Improve extrinsics docs Signed-off-by: Alexandru Vasile <[email protected]> --------- Signed-off-by: Alexandru Vasile <[email protected]> Co-authored-by: James Wilson <[email protected]>
* add cli command to explore metadata * fmt and clippy * Bump serde from 1.0.160 to 1.0.162 (#948) Bumps [serde](https://github.com/serde-rs/serde) from 1.0.160 to 1.0.162. - [Release notes](https://github.com/serde-rs/serde/releases) - [Commits](serde-rs/serde@v1.0.160...1.0.162) --- updated-dependencies: - dependency-name: serde dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * extrinsics: Decode extrinsics from blocks (#929) * Update polkadot.scale Signed-off-by: Alexandru Vasile <[email protected]> * extrinsics: Add extrinsics client Signed-off-by: Alexandru Vasile <[email protected]> * extrinsics: Decode extrinsics Signed-off-by: Alexandru Vasile <[email protected]> * subxt: Add extrinsic error Signed-off-by: Alexandru Vasile <[email protected]> * blocks: Expose extrinsics Signed-off-by: Alexandru Vasile <[email protected]> * examples: Fetch and decode block extrinsics Signed-off-by: Alexandru Vasile <[email protected]> * Fix clippy Signed-off-by: Alexandru Vasile <[email protected]> * extrinsics: Fetch pallet and variant index Signed-off-by: Alexandru Vasile <[email protected]> * subxt: Move extrinsics on the subxt::blocks Signed-off-by: Alexandru Vasile <[email protected]> * example: Adjust example Signed-off-by: Alexandru Vasile <[email protected]> * metadata: Collect ExtrinsicMetadata Signed-off-by: Alexandru Vasile <[email protected]> * subxt: Implement StaticExtrinsic for the calls Signed-off-by: Alexandru Vasile <[email protected]> * Adjust examples Signed-off-by: Alexandru Vasile <[email protected]> * codegen: Add root level Call enum Signed-off-by: Alexandru Vasile <[email protected]> * Adjust testing Signed-off-by: Alexandru Vasile <[email protected]> * subxt: Add new decode interface Signed-off-by: Alexandru Vasile <[email protected]> * subxt: Merge ExtrinsicError with BlockError Signed-off-by: Alexandru Vasile <[email protected]> * examples: Find first extrinsic Signed-off-by: Alexandru Vasile <[email protected]> * Move code to extrinsic_types Signed-off-by: Alexandru Vasile <[email protected]> * Add Extrinsic struct Signed-off-by: Alexandru Vasile <[email protected]> * Adjust examples Signed-off-by: Alexandru Vasile <[email protected]> * test: Decode extinsics Signed-off-by: Alexandru Vasile <[email protected]> * extrinsics/test: Add fake metadata for static decoding Signed-off-by: Alexandru Vasile <[email protected]> * extrinsics/test: Decode from insufficient bytes Signed-off-by: Alexandru Vasile <[email protected]> * extrinsics/test: Check unsupported versions Signed-off-by: Alexandru Vasile <[email protected]> * extrinsics/test: Statically decode to root and pallet enums Signed-off-by: Alexandru Vasile <[email protected]> * extrinsics/tests: Remove clones Signed-off-by: Alexandru Vasile <[email protected]> * blocks: Fetch block body inline Signed-off-by: Alexandru Vasile <[email protected]> * blocks: Rename ExtrinsicIds to ExtrinsicPartTypeIds Signed-off-by: Alexandru Vasile <[email protected]> * extrinsics/test: Check decode as_extrinsic Signed-off-by: Alexandru Vasile <[email protected]> * blocks: Remove InsufficientData error Signed-off-by: Alexandru Vasile <[email protected]> * blocks: Return error from extrinsic_metadata Signed-off-by: Alexandru Vasile <[email protected]> * extrinsics: Postpone decoding of call bytes Signed-off-by: Alexandru Vasile <[email protected]> * metadata_type: Rename variables Signed-off-by: Alexandru Vasile <[email protected]> * Adjust calls path for example and tests Signed-off-by: Alexandru Vasile <[email protected]> * examples: Remove traces Signed-off-by: Alexandru Vasile <[email protected]> * book: Add extrinsics documentation Signed-off-by: Alexandru Vasile <[email protected]> * book: Improve extrinsics docs Signed-off-by: Alexandru Vasile <[email protected]> --------- Signed-off-by: Alexandru Vasile <[email protected]> Co-authored-by: James Wilson <[email protected]> * change doc comments * add constants exploration * add storage access interface but not done yet * add storage exploration * formatting * remove dbg * some small tweaks * fix formatting and scale value for storage * split up files, sort entries, change formatting * fmt and clippy fix * fix minor formatting issue * implement suggestions * implement other suggestion, fix bug --------- Signed-off-by: dependabot[bot] <[email protected]> Signed-off-by: Alexandru Vasile <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Alexandru Vasile <[email protected]> Co-authored-by: James Wilson <[email protected]>
This PR adds support to decode extrinsics from blocks.
The extrinsic is composed of:
The type IDs of the Address, Signature, Extra and Call data are dynamically extracted from the metadata.
This is used then during the raw decoding to skip over those fields.
Currently, the Signature and Extra fields are not exposed or tracked internally.
The interface exposes the ability to fetch bytes or decode on a custom type the
Address
signer of the extrinsic payloadCall
the raw function of the extrinsicOutput from the added example
Next Steps
ExtrinsicMetadata
StaticExtrinsic
trait to identify pallets and variant indexStaticExtrinsic
after changes in codegen