/// Calls service hooks of the specified type for all active services.
Calls service hooks of the specified type for all active services.
Calls service hooks of the specified type for all active services .
fn call_service_hooks(
        &self,
        fork: &mut Fork,
        call_type: &CallType,
    ) -> Vec<(CallInBlock, ExecutionError)> {
        self.service_infos
            .active_instances()
            .filter_map(|(instance, runtime_id)| {
                let mut should_rollback = false;
                let context = ExecutionContext::for_block_call(
                    self,
                    fork,
                    &mut should_rollback,
                    instance.clone(),
                );
                let call_fn = match &call_type {
                    CallType::BeforeTransactions => Runtime::before_transactions,
                    CallType::AfterTransactions => Runtime::after_transactions,
                    _ => unreachable!(),
                };
                let mut res = call_fn(self.runtimes[&runtime_id].as_ref(), context);
                if should_rollback && res.is_ok() {
                    res = Err(CoreError::IncorrectCall.into());
                }
                if let Err(mut err) = res {
                    fork.rollback();
                    err.set_runtime_id(runtime_id)
                        .set_call_site(|| CallSite::new(instance.id, call_type.clone()));
                    let call = match &call_type {
                        CallType::BeforeTransactions => {
                            CallInBlock::before_transactions(instance.id)
                        }
                        CallType::AfterTransactions => CallInBlock::after_transactions(instance.id),
                        _ => unreachable!(),
                    };
                    Self::report_error(&err, fork, call);
                    Some((call, err))
                } else {
                    fork.flush();
                    None
                }
            })
            .collect()
    }
fn call_service_hooks ( & self , fork : & mut Fork , call_type : & CallType , ) -> Vec < ( CallInBlock , ExecutionError ) > { self . service_infos . active_instances ( ) . filter_map ( | ( instance , runtime_id ) | { let mut should_rollback = false ; let context = ExecutionContext :: for_block_call ( self , fork , & mut should_rollback , instance . clone ( ) , ) ; let call_fn = match & call_type { CallType :: BeforeTransactions => Runtime :: before_transactions , CallType :: AfterTransactions => Runtime :: after_transactions , _ => unreachable ! ( ) , } ; let mut res = call_fn ( self . runtimes [ & runtime_id ] . as_ref ( ) , context ) ; if should_rollback && res . is_ok ( ) { res = Err ( CoreError :: IncorrectCall . into ( ) ) ; } if let Err ( mut err ) = res { fork . rollback ( ) ; err . set_runtime_id ( runtime_id ) . set_call_site ( | | CallSite :: new ( instance . id , call_type . clone ( ) ) ) ; let call = match & call_type { CallType :: BeforeTransactions => { CallInBlock :: before_transactions ( instance . id ) } CallType :: AfterTransactions => CallInBlock :: after_transactions ( instance . id ) , _ => unreachable ! ( ) , } ; Self :: report_error ( & err , fork , call ) ; Some ( ( call , err ) ) } else { fork . flush ( ) ; None } } ) . collect ( ) }
Calls service hooks of the specified type for all active services.
Calls service hooks of the specified type for all active services .
&self
fork
&mut Fork
call_type
&CallType