Block: Implement clone (#2047)

This commit is contained in:
Bastian Köcher
2025-07-31 11:59:12 +02:00
committed by GitHub
parent fdc42f088b
commit 8e162036a1
3 changed files with 16 additions and 1 deletions
+1 -1
View File
@@ -47,7 +47,7 @@ pub trait Config: Sized + Send + Sync + 'static {
type Hasher: Debug + Clone + Copy + Hasher + Send + Sync;
/// The block header.
type Header: Debug + Header<Hasher = Self::Hasher> + Sync + Send + DeserializeOwned;
type Header: Debug + Header<Hasher = Self::Hasher> + Sync + Send + DeserializeOwned + Clone;
/// This type defines the extrinsic extra and additional parameters.
type ExtrinsicParams: ExtrinsicParams<Self>;
+11
View File
@@ -27,6 +27,17 @@ pub struct Block<T: Config, C> {
cached_events: CachedEvents<T>,
}
impl<T: Config, C: Clone> Clone for Block<T, C> {
fn clone(&self) -> Self {
Self {
header: self.header.clone(),
block_ref: self.block_ref.clone(),
client: self.client.clone(),
cached_events: self.cached_events.clone(),
}
}
}
// A cache for our events so we don't fetch them more than once when
// iterating over events for extrinsics.
pub(crate) type CachedEvents<T> = Arc<AsyncMutex<Option<events::Events<T>>>>;
@@ -205,6 +205,10 @@ async fn fetch_block_and_decode_extrinsic_details() {
// Now, separately, download that block. Let's see what it contains..
let block_hash = in_block.block_hash();
let block = api.blocks().at(block_hash).await.unwrap();
// Ensure that we can clone the block.
block.clone();
let extrinsics = block.extrinsics().await.unwrap();
assert_eq!(extrinsics.block_hash(), block_hash);