From b0fb96afd9ce901ab89e09bde8b611e226f940f0 Mon Sep 17 00:00:00 2001 From: Tadeo hepperle Date: Mon, 16 Oct 2023 10:09:26 +0200 Subject: [PATCH] fix some minor things --- subxt/src/blocks/extrinsic_types.rs | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/subxt/src/blocks/extrinsic_types.rs b/subxt/src/blocks/extrinsic_types.rs index 62496f6222..1d1a2ca9bc 100644 --- a/subxt/src/blocks/extrinsic_types.rs +++ b/subxt/src/blocks/extrinsic_types.rs @@ -12,7 +12,6 @@ use crate::{ Metadata, }; use std::marker::PhantomData; -use std::ops::Range; use crate::dynamic::{DecodedValue, DecodedValueThunk}; use crate::metadata::DecodeWithMetadata; @@ -20,8 +19,8 @@ use crate::utils::strip_compact_prefix; use codec::{Compact, Decode}; use derivative::Derivative; use scale_decode::{DecodeAsFields, DecodeAsType}; -use scale_info::form::PortableForm; -use scale_info::{PortableRegistry, TypeDef}; + +use scale_info::TypeDef; use std::sync::Arc; /// Trait to uniquely identify the extrinsic's identity from the runtime metadata. @@ -398,7 +397,7 @@ where let mut signed_extensions: Vec> = vec![]; - let mut cursor: &mut &[u8] = &mut &extra_bytes[..]; + let cursor: &mut &[u8] = &mut &extra_bytes[..]; let mut start_idx: usize = 0; for field in extra_tuple_type_def.fields.iter() { let ty_id = field.id; @@ -429,6 +428,7 @@ where Ok(ExtrinsicSignedExtensions { bytes: extra_bytes, signed_extensions, + ty_id: extra_ty_id, metadata, phantom: PhantomData, }) @@ -675,6 +675,7 @@ impl ExtrinsicEvents { pub struct ExtrinsicSignedExtensions<'a, T: Config> { signed_extensions: Vec>, bytes: &'a [u8], + ty_id: u32, metadata: &'a Metadata, phantom: PhantomData, } @@ -694,6 +695,17 @@ impl<'a, T: Config> ExtrinsicSignedExtensions<'a, T> { self.bytes } + /// Returns a DecodedValueThunk of the signed extensions type. + /// Can be used to get all signed extensions as a scale value. + pub fn decoded(&self) -> Result { + let decoded_value_thunk = DecodedValueThunk::decode_with_metadata( + &mut &self.bytes[..], + self.ty_id, + self.metadata, + )?; + Ok(decoded_value_thunk) + } + /// Returns a slice of all signed extensions pub fn signed_extensions(&self) -> &[ExtrinsicSignedExtension] { &self.signed_extensions @@ -722,18 +734,22 @@ impl<'a, T: Config> ExtrinsicSignedExtensions<'a, T> { } impl<'a, T: Config> ExtrinsicSignedExtension<'a, T> { + /// The extra bytes associated with the signed extension. pub fn bytes(&self) -> &[u8] { self.bytes } + /// The name of the signed extension. pub fn name(&self) -> &str { self.name } + /// The type id of the signed extension. pub fn type_id(&self) -> u32 { self.ty_id } + /// DecodedValueThunk representing the type of the extra of this signed extension. pub fn decoded(&self) -> Result { let decoded_value_thunk = DecodedValueThunk::decode_with_metadata( &mut &self.bytes[..], @@ -742,6 +758,8 @@ impl<'a, T: Config> ExtrinsicSignedExtension<'a, T> { )?; Ok(decoded_value_thunk) } + + /// Signed Extension as a [`scale_value::Value`] pub fn value(&self) -> Result { let value = self.decoded()?.to_value()?; Ok(value)