mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-29 00:57:57 +00:00
Use frame-decode for core extrinsic decode logic (#1785)
* WIP using frame-decode for core extrinsic decode logic * fmt * Fix dependabot config * clippy * tidy some imports * Fix a couple of tests * Update to frame-decode 0.0.7 * fix docs * Decode exts earlier to avoid doing it every iter/find step * frame-decode to 0.1.0 * fmt * clippy * fix wasm example * doc test fixes * Fix test * Fix a couple of subxt_core tests
This commit is contained in:
@@ -84,12 +84,12 @@ where
|
||||
return Err(BlockError::not_found(block_hash).into());
|
||||
};
|
||||
|
||||
Ok(Extrinsics::new(
|
||||
Extrinsics::new(
|
||||
self.client.clone(),
|
||||
extrinsics,
|
||||
self.cached_events.clone(),
|
||||
block_hash,
|
||||
)?)
|
||||
)
|
||||
}
|
||||
|
||||
/// Work with storage.
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::{
|
||||
blocks::block_types::{get_events, CachedEvents},
|
||||
client::{OfflineClientT, OnlineClientT},
|
||||
config::{Config, Hasher},
|
||||
error::{BlockError, Error},
|
||||
error::Error,
|
||||
events,
|
||||
};
|
||||
|
||||
@@ -37,7 +37,7 @@ where
|
||||
extrinsics: Vec<Vec<u8>>,
|
||||
cached_events: CachedEvents<T>,
|
||||
hash: T::Hash,
|
||||
) -> Result<Self, BlockError> {
|
||||
) -> Result<Self, Error> {
|
||||
let inner = CoreExtrinsics::decode_from(extrinsics, client.metadata())?;
|
||||
Ok(Self {
|
||||
inner,
|
||||
@@ -65,21 +65,13 @@ where
|
||||
/// Returns an iterator over the extrinsics in the block body.
|
||||
// Dev note: The returned iterator is 'static + Send so that we can box it up and make
|
||||
// use of it with our `FilterExtrinsic` stuff.
|
||||
pub fn iter(
|
||||
&self,
|
||||
) -> impl Iterator<Item = Result<ExtrinsicDetails<T, C>, Error>> + Send + Sync + 'static {
|
||||
pub fn iter(&self) -> impl Iterator<Item = ExtrinsicDetails<T, C>> + Send + Sync + 'static {
|
||||
let client = self.client.clone();
|
||||
let cached_events = self.cached_events.clone();
|
||||
let block_hash = self.hash;
|
||||
|
||||
self.inner.iter().map(move |res| {
|
||||
let inner = res?;
|
||||
Ok(ExtrinsicDetails::new(
|
||||
inner,
|
||||
client.clone(),
|
||||
block_hash,
|
||||
cached_events.clone(),
|
||||
))
|
||||
self.inner.iter().map(move |inner| {
|
||||
ExtrinsicDetails::new(inner, client.clone(), block_hash, cached_events.clone())
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
+7
-12
@@ -165,30 +165,25 @@ impl RpcError {
|
||||
}
|
||||
|
||||
/// Block error
|
||||
#[derive(Clone, Debug, Eq, thiserror::Error, PartialEq)]
|
||||
#[derive(Clone, Debug, thiserror::Error)]
|
||||
#[non_exhaustive]
|
||||
pub enum BlockError {
|
||||
/// An error containing the hash of the block that was not found.
|
||||
#[error("Could not find a block with hash {0} (perhaps it was on a non-finalized fork?)")]
|
||||
NotFound(String),
|
||||
/// Extrinsic type ID cannot be resolved with the provided metadata.
|
||||
#[error("Extrinsic type ID cannot be resolved with the provided metadata. Make sure this is a valid metadata")]
|
||||
MissingType,
|
||||
/// Unsupported signature.
|
||||
#[error("Unsupported extrinsic version, only version 4 is supported currently")]
|
||||
/// The extrinsic has an unsupported version.
|
||||
UnsupportedVersion(u8),
|
||||
/// Leftover bytes found after decoding the extrinsic.
|
||||
#[error("After decoding, {0} bytes were left, suggesting that decoding may have failed")]
|
||||
LeftoverBytes(usize),
|
||||
/// Decoding error.
|
||||
#[error("Cannot decode extrinsic: {0}")]
|
||||
DecodingError(codec::Error),
|
||||
ExtrinsicDecodeError(subxt_core::error::ExtrinsicDecodeError),
|
||||
}
|
||||
|
||||
impl From<CoreBlockError> for BlockError {
|
||||
fn from(value: CoreBlockError) -> Self {
|
||||
match value {
|
||||
CoreBlockError::MissingType => BlockError::MissingType,
|
||||
CoreBlockError::UnsupportedVersion(n) => BlockError::UnsupportedVersion(n),
|
||||
CoreBlockError::DecodingError(e) => BlockError::DecodingError(e),
|
||||
CoreBlockError::LeftoverBytes(n) => BlockError::LeftoverBytes(n),
|
||||
CoreBlockError::ExtrinsicDecodeError(e) => BlockError::ExtrinsicDecodeError(e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user