pub fn on_block_insert(
		mut self,
		parent: ComplexBlockId<Block>,
		block: ComplexBlockId<Block>,
		data_at: HashMap<CacheKeyId, Vec<u8>>,
		is_final: bool,
	) -> ClientResult<Self> {
		assert!(self.cache_at_op.is_empty());

		// prepare list of caches that are not update
		// (we might still need to do some cache maintenance in this case)
		let missed_caches = self.cache.cache_at.keys()
			.filter(|cache| !data_at.contains_key(cache.clone()))
			.cloned()
			.collect::<Vec<_>>();

		let mut insert_op = |name: CacheKeyId, value: Option<Vec<u8>>| -> Result<(), client::error::Error> {
			let cache = self.cache.get_cache(name);
			let op = cache.on_block_insert(
				&mut self::list_storage::DbStorageTransaction::new(
					cache.storage(),
					&mut self.tx,
				),
				parent.clone(),
				block.clone(),
				value.or(cache.value_at_block(&parent)?),
				is_final,
			)?;
			if let Some(op) = op {
				self.cache_at_op.insert(name, op);
			}
			Ok(())
		};

		data_at.into_iter().try_for_each(|(name, data)| insert_op(name, Some(data)))?;
		missed_caches.into_iter().try_for_each(|name| insert_op(name, None))?;

		if is_final {
			self.best_finalized_block = Some(block);
		}

		Ok(self)
	}
/// When new block is inserted into database.
When new block is inserted into database.
When new block is inserted into database .
pub fn on_block_insert(
		mut self,
		parent: ComplexBlockId<Block>,
		block: ComplexBlockId<Block>,
		data_at: HashMap<CacheKeyId, Vec<u8>>,
		is_final: bool,
	) -> ClientResult<Self> {
		assert!(self.cache_at_op.is_empty());
		// prepare list of caches that are not update
		// (we might still need to do some cache maintenance in this case)
		let missed_caches = self.cache.cache_at.keys()
			.filter(|cache| !data_at.contains_key(cache.clone()))
			.cloned()
			.collect::<Vec<_>>();
		let mut insert_op = |name: CacheKeyId, value: Option<Vec<u8>>| -> Result<(), client::error::Error> {
			let cache = self.cache.get_cache(name);
			let op = cache.on_block_insert(
				&mut self::list_storage::DbStorageTransaction::new(
					cache.storage(),
					&mut self.tx,
				),
				parent.clone(),
				block.clone(),
				value.or(cache.value_at_block(&parent)?),
				is_final,
			)?;
			if let Some(op) = op {
				self.cache_at_op.insert(name, op);
			}
			Ok(())
		};
		data_at.into_iter().try_for_each(|(name, data)| insert_op(name, Some(data)))?;
		missed_caches.into_iter().try_for_each(|name| insert_op(name, None))?;
		if is_final {
			self.best_finalized_block = Some(block);
		}
		Ok(self)
	}
pub fn on_block_insert ( mut self , parent : ComplexBlockId < Block > , block : ComplexBlockId < Block > , data_at : HashMap < CacheKeyId , Vec < u8 > > , is_final : bool , ) -> ClientResult < Self > { assert ! ( self cache_at_op is_empty ( ) ) ; // prepare list of caches that are not update // (we might still need to do some cache maintenance in this case) let missed_caches = self . cache . cache_at . keys ( ) . filter ( | cache | ! data_at . contains_key ( cache . clone ( ) ) ) . cloned ( ) . collect :: < Vec < _ > > ( ) ; let mut insert_op = | name : CacheKeyId , value : Option < Vec < u8 > > | -> Result < ( ) , client :: error :: Error > { let cache = self . cache . get_cache ( name ) ; let op = cache . on_block_insert ( & mut self :: list_storage :: DbStorageTransaction :: new ( cache . storage ( ) , & mut self . tx , ) , parent . clone ( ) , block . clone ( ) , value . or ( cache . value_at_block ( & parent ) ? ) , is_final , ) ? ; if let Some ( op ) = op { self . cache_at_op . insert ( name , op ) ; } Ok ( ( ) ) } ; data_at . into_iter ( ) . try_for_each ( | ( name , data ) | insert_op ( name , Some ( data ) ) ) ? ; missed_caches . into_iter ( ) . try_for_each ( | name | insert_op ( name , None ) ) ? ; if is_final { self . best_finalized_block = Some ( block ) ; } Ok ( self ) }
When new block is inserted into database.
When new block is inserted into database .
mut self
parent
ComplexBlockId<Block>
block
ComplexBlockId<Block>
data_at
HashMap<CacheKeyId, Vec<u8>>
is_final
bool
mut self
parent
ComplexBlockId<Block>
block
ComplexBlockId<Block>
data_at
HashMap<CacheKeyId, Vec<u8>>
is_final
bool