-
Notifications
You must be signed in to change notification settings - Fork 254
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
Use frame-decode for core extrinsic decode logic #1785
Conversation
_marker: core::marker::PhantomData<T>, | ||
} | ||
|
||
impl<T: Config> Extrinsics<T> { | ||
/// Instantiate a new [`Extrinsics`] object, given a vector containing | ||
/// each extrinsic hash (in the form of bytes) and some metadata that | ||
/// we'll use to decode them. | ||
pub fn decode_from(extrinsics: Vec<Vec<u8>>, metadata: Metadata) -> Result<Self, BlockError> { | ||
let ids = ExtrinsicPartTypeIds::new(&metadata)?; | ||
pub fn decode_from(extrinsics: Vec<Vec<u8>>, metadata: Metadata) -> Result<Self, Error> { |
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 moved the decoding work to this initial step.
This means that on the downside we:
- try to decode everything straight away, even if the user doesn't care (though I suspect they usually would)
- an error decoding an extrinsic will lead to a failure early on, preventing eg getting the extrinsic bytes
On the plus side, we:
- Can iterate over or
find
or whatever multiple times without re-doing the decoding work each time we do these things. - Don't need to handle Results in a couple of places, since we did the work once up front.
@@ -61,6 +65,63 @@ pub struct Metadata { | |||
custom: frame_metadata::v15::CustomMetadata<PortableForm>, | |||
} | |||
|
|||
// Since we've abstracted away from frame-metadatas, we impl this on our custom Metadata | |||
// so that it can be used by `frame-decode` to obtain the relevant extrinsic info. | |||
impl frame_decode::extrinsics::ExtrinsicTypeInfo for Metadata { |
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.
We wouldn't normally need this if we used frame_metadata's RuntimeMetadataV15
or whatever directly, but since we abstracted it into our own Metadata crate so as to not care about the underlying version, we need to be able to get the info we need from this via the impl here.
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.
LGTM! 👍
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.
LGTM
This pull request has been mentioned on Polkadot Forum. There might be relevant details there: |
frame-decode
is a crate to handle decoding historic or modern extrinsics and storage keys/values. (https://docs.rs/frame-decode/latest/frame_decode/)