pub fn exec_system_contract<R, T>(
        &self,
        direct_system_contract_call: DirectSystemContractCall,
        module: Module,
        runtime_args: RuntimeArgs,
        named_keys: &mut NamedKeys,
        extra_keys: &[Key],
        base_key: Key,
        account: &Account,
        authorization_keys: BTreeSet<AccountHash>,
        blocktime: BlockTime,
        deploy_hash: DeployHash,
        gas_limit: Gas,
        protocol_version: ProtocolVersion,
        correlation_id: CorrelationId,
        tracking_copy: Rc<RefCell<TrackingCopy<R>>>,
        phase: Phase,
        stack: RuntimeStack,
    ) -> (Option<T>, ExecutionResult)
    where
        R: StateReader<Key, StoredValue>,
        R::Error: Into<Error>,
        T: FromBytes + CLTyped,
    {
        // TODO See if these panics can be removed.
        let system_contract_registry = tracking_copy
            .borrow_mut()
            .get_system_contracts(correlation_id)
            .unwrap_or_else(|error| panic!("Could not retrieve system contracts: {:?}", error));

        match direct_system_contract_call {
            DirectSystemContractCall::Slash
            | DirectSystemContractCall::RunAuction
            | DirectSystemContractCall::DistributeRewards => {
                // TODO See if these panics can be removed.
                let auction_hash = system_contract_registry
                    .get(AUCTION)
                    .expect("should have auction hash")
                    .to_owned();

                if Some(auction_hash.value()) != base_key.into_hash() {
                    panic!(
                        "{} should only be called with the auction contract",
                        direct_system_contract_call.entry_point_name()
                    );
                }
            }
            DirectSystemContractCall::FinalizePayment
            | DirectSystemContractCall::GetPaymentPurse => {
                // TODO See if these panics can be removed.
                let handle_payment = system_contract_registry
                    .get(HANDLE_PAYMENT)
                    .expect("should have handle payment");
                if Some(handle_payment.value()) != base_key.into_hash() {
                    panic!(
                        "{} should only be called with the handle payment contract",
                        direct_system_contract_call.entry_point_name()
                    );
                }
            }
            DirectSystemContractCall::CreatePurse | DirectSystemContractCall::Transfer => {
                // TODO See if these panics can be removed.
                let mint_hash = system_contract_registry
                    .get(MINT)
                    .expect("should have mint hash");
                if Some(mint_hash.value()) != base_key.into_hash() {
                    panic!(
                        "{} should only be called with the mint contract",
                        direct_system_contract_call.entry_point_name()
                    );
                }
            }
            DirectSystemContractCall::GetEraValidators => {
                // TODO See if these panics can be removed.
                let auction_hash = system_contract_registry
                    .get(AUCTION)
                    .expect("should have auction hash")
                    .to_owned();
                if Some(auction_hash.value()) != base_key.into_hash() {
                    panic!(
                        "{} should only be called with the auction contract",
                        direct_system_contract_call.entry_point_name()
                    );
                }
            }
        }

        let address_generator = {
            let generator = AddressGenerator::new(deploy_hash.as_bytes(), phase);
            Rc::new(RefCell::new(generator))
        };
        let gas_counter = Gas::default(); // maybe const?

        // Snapshot of effects before execution, so in case of error only nonce update
        // can be returned.
        let execution_journal = tracking_copy.borrow().execution_journal();

        let transfers = Vec::default();

        let (_, runtime) = match self.create_runtime(
            module,
            EntryPointType::Contract,
            runtime_args.clone(),
            named_keys,
            extra_keys,
            base_key,
            account,
            authorization_keys,
            blocktime,
            deploy_hash,
            gas_limit,
            address_generator,
            protocol_version,
            correlation_id,
            tracking_copy,
            phase,
            stack,
        ) {
            Ok((instance, runtime)) => (instance, runtime),
            Err(error) => {
                return ExecutionResult::Failure {
                    execution_journal,
                    transfers,
                    cost: gas_counter,
                    error: error.into(),
                }
                .take_without_ret()
            }
        };

        let mut inner_named_keys = runtime.context().named_keys().clone();
        let ret = direct_system_contract_call.host_exec(
            runtime,
            protocol_version,
            &mut inner_named_keys,
            &runtime_args,
            extra_keys,
            execution_journal,
        );
        *named_keys = inner_named_keys;
        ret
    }
/// Executes a system contract.
///
/// System contracts are implemented as a native code, and no WASM execution is involved at all.
/// This approach has a benefit of speed as compared to executing WASM modules.
///
/// Returns an optional return value from the system contract call, and an [`ExecutionResult`].
Executes a system contract.
System contracts are implemented as a native code, and no WASM execution is involved at all.
This approach has a benefit of speed as compared to executing WASM modules.

Returns an optional return value from the system contract call, and an [`ExecutionResult`].
Executes a system contract . System contracts are implemented as a native code and no WASM execution is involved at all . This approach has a benefit of speed as compared to executing WASM modules . Returns an optional return value from the system contract call and an [ ` ExecutionResult ` ] .
pub fn exec_system_contract<R, T>(
        &self,
        direct_system_contract_call: DirectSystemContractCall,
        module: Module,
        runtime_args: RuntimeArgs,
        named_keys: &mut NamedKeys,
        extra_keys: &[Key],
        base_key: Key,
        account: &Account,
        authorization_keys: BTreeSet<AccountHash>,
        blocktime: BlockTime,
        deploy_hash: DeployHash,
        gas_limit: Gas,
        protocol_version: ProtocolVersion,
        correlation_id: CorrelationId,
        tracking_copy: Rc<RefCell<TrackingCopy<R>>>,
        phase: Phase,
        stack: RuntimeStack,
    ) -> (Option<T>, ExecutionResult)
    where
        R: StateReader<Key, StoredValue>,
        R::Error: Into<Error>,
        T: FromBytes + CLTyped,
    {
        // TODO See if these panics can be removed.
        let system_contract_registry = tracking_copy
            .borrow_mut()
            .get_system_contracts(correlation_id)
            .unwrap_or_else(|error| panic!("Could not retrieve system contracts: {:?}", error));
        match direct_system_contract_call {
            DirectSystemContractCall::Slash
            | DirectSystemContractCall::RunAuction
            | DirectSystemContractCall::DistributeRewards => {
                // TODO See if these panics can be removed.
                let auction_hash = system_contract_registry
                    .get(AUCTION)
                    .expect("should have auction hash")
                    .to_owned();
                if Some(auction_hash.value()) != base_key.into_hash() {
                    panic!(
                        "{} should only be called with the auction contract",
                        direct_system_contract_call.entry_point_name()
                    );
                }
            }
            DirectSystemContractCall::FinalizePayment
            | DirectSystemContractCall::GetPaymentPurse => {
                // TODO See if these panics can be removed.
                let handle_payment = system_contract_registry
                    .get(HANDLE_PAYMENT)
                    .expect("should have handle payment");
                if Some(handle_payment.value()) != base_key.into_hash() {
                    panic!(
                        "{} should only be called with the handle payment contract",
                        direct_system_contract_call.entry_point_name()
                    );
                }
            }
            DirectSystemContractCall::CreatePurse | DirectSystemContractCall::Transfer => {
                // TODO See if these panics can be removed.
                let mint_hash = system_contract_registry
                    .get(MINT)
                    .expect("should have mint hash");
                if Some(mint_hash.value()) != base_key.into_hash() {
                    panic!(
                        "{} should only be called with the mint contract",
                        direct_system_contract_call.entry_point_name()
                    );
                }
            }
            DirectSystemContractCall::GetEraValidators => {
                // TODO See if these panics can be removed.
                let auction_hash = system_contract_registry
                    .get(AUCTION)
                    .expect("should have auction hash")
                    .to_owned();
                if Some(auction_hash.value()) != base_key.into_hash() {
                    panic!(
                        "{} should only be called with the auction contract",
                        direct_system_contract_call.entry_point_name()
                    );
                }
            }
        }
        let address_generator = {
            let generator = AddressGenerator::new(deploy_hash.as_bytes(), phase);
            Rc::new(RefCell::new(generator))
        };
        let gas_counter = Gas::default(); // maybe const?
        // Snapshot of effects before execution, so in case of error only nonce update
        // can be returned.
        let execution_journal = tracking_copy.borrow().execution_journal();
        let transfers = Vec::default();
        let (_, runtime) = match self.create_runtime(
            module,
            EntryPointType::Contract,
            runtime_args.clone(),
            named_keys,
            extra_keys,
            base_key,
            account,
            authorization_keys,
            blocktime,
            deploy_hash,
            gas_limit,
            address_generator,
            protocol_version,
            correlation_id,
            tracking_copy,
            phase,
            stack,
        ) {
            Ok((instance, runtime)) => (instance, runtime),
            Err(error) => {
                return ExecutionResult::Failure {
                    execution_journal,
                    transfers,
                    cost: gas_counter,
                    error: error.into(),
                }
                .take_without_ret()
            }
        };
        let mut inner_named_keys = runtime.context().named_keys().clone();
        let ret = direct_system_contract_call.host_exec(
            runtime,
            protocol_version,
            &mut inner_named_keys,
            &runtime_args,
            extra_keys,
            execution_journal,
        );
        *named_keys = inner_named_keys;
        ret
    }
pub fn exec_system_contract < R , T > ( & self , direct_system_contract_call : DirectSystemContractCall , module : Module , runtime_args : RuntimeArgs , named_keys : & mut NamedKeys , extra_keys : & [ Key ] , base_key : Key , account : & Account , authorization_keys : BTreeSet < AccountHash > , blocktime : BlockTime , deploy_hash : DeployHash , gas_limit : Gas , protocol_version : ProtocolVersion , correlation_id : CorrelationId , tracking_copy : Rc < RefCell < TrackingCopy < R > > > , phase : Phase , stack : RuntimeStack , ) -> ( Option < T > , ExecutionResult ) where R : StateReader < Key , StoredValue > , R :: Error : Into < Error > , T : FromBytes + CLTyped , { // TODO See if these panics can be removed. let system_contract_registry = tracking_copy . borrow_mut ( ) . get_system_contracts ( correlation_id ) . unwrap_or_else ( | error | panic ! ( " " error ) ) ; match direct_system_contract_call { DirectSystemContractCall :: Slash | DirectSystemContractCall :: RunAuction | DirectSystemContractCall :: DistributeRewards => { // TODO See if these panics can be removed. let auction_hash = system_contract_registry . get ( AUCTION ) . expect ( " " ) . to_owned ( ) ; if Some ( auction_hash . value ( ) ) != base_key . into_hash ( ) { panic ! ( " " direct_system_contract_call entry_point_name ( ) ) ; } } DirectSystemContractCall :: FinalizePayment | DirectSystemContractCall :: GetPaymentPurse => { // TODO See if these panics can be removed. let handle_payment = system_contract_registry . get ( HANDLE_PAYMENT ) . expect ( " " ) ; if Some ( handle_payment . value ( ) ) != base_key . into_hash ( ) { panic ! ( " " direct_system_contract_call entry_point_name ( ) ) ; } } DirectSystemContractCall :: CreatePurse | DirectSystemContractCall :: Transfer => { // TODO See if these panics can be removed. let mint_hash = system_contract_registry . get ( MINT ) . expect ( " " ) ; if Some ( mint_hash . value ( ) ) != base_key . into_hash ( ) { panic ! ( " " direct_system_contract_call entry_point_name ( ) ) ; } } DirectSystemContractCall :: GetEraValidators => { // TODO See if these panics can be removed. let auction_hash = system_contract_registry . get ( AUCTION ) . expect ( " " ) . to_owned ( ) ; if Some ( auction_hash . value ( ) ) != base_key . into_hash ( ) { panic ! ( " " direct_system_contract_call entry_point_name ( ) ) ; } } } let address_generator = { let generator = AddressGenerator :: new ( deploy_hash . as_bytes ( ) , phase ) ; Rc :: new ( RefCell :: new ( generator ) ) } ; let gas_counter = Gas :: default ( ) ; // maybe const? // Snapshot of effects before execution, so in case of error only nonce update // can be returned. let execution_journal = tracking_copy . borrow ( ) . execution_journal ( ) ; let transfers = Vec :: default ( ) ; let ( _ , runtime ) = match self . create_runtime ( module , EntryPointType :: Contract , runtime_args . clone ( ) , named_keys , extra_keys , base_key , account , authorization_keys , blocktime , deploy_hash , gas_limit , address_generator , protocol_version , correlation_id , tracking_copy , phase , stack , ) { Ok ( ( instance , runtime ) ) => ( instance , runtime ) , Err ( error ) => { return ExecutionResult :: Failure { execution_journal , transfers , cost : gas_counter , error : error . into ( ) , } . take_without_ret ( ) } } ; let mut inner_named_keys = runtime . context ( ) . named_keys ( ) . clone ( ) ; let ret = direct_system_contract_call . host_exec ( runtime , protocol_version , & mut inner_named_keys , & runtime_args , extra_keys , execution_journal , ) ; * named_keys = inner_named_keys ; ret }
Executes a system contract.
Executes a system contract .
&self
direct_system_contract_call
DirectSystemContractCall
module
Module
runtime_args
RuntimeArgs
named_keys
&mut NamedKeys
extra_keys
&[Key]
base_key
Key
account
&Account
authorization_keys
BTreeSet<AccountHash>
blocktime
BlockTime
deploy_hash
DeployHash
gas_limit
Gas
protocol_version
ProtocolVersion
correlation_id
CorrelationId
tracking_copy
Rc<RefCell<TrackingCopy<R>>>
phase
Phase
stack
RuntimeStack
&self
direct_system_contract_call
DirectSystemContractCall
module
Module
runtime_args
RuntimeArgs
named_keys
&mut NamedKeys
extra_keys
&[Key]
base_key
Key
account
&Account
authorization_keys
BTreeSet<AccountHash>
blocktime
BlockTime
deploy_hash
DeployHash
gas_limit
Gas
protocol_version
ProtocolVersion
correlation_id
CorrelationId
tracking_copy
Rc<RefCell<TrackingCopy<R>>>
phase
Phase
stack
RuntimeStack