pub(crate) fn create_canister(
        &self,
        sender: PrincipalId,
        sender_subnet_id: SubnetId,
        funds: Funds,
        settings: CanisterSettings,
        state: &mut ReplicatedState,
    ) -> (Result<CanisterId, CanisterManagerError>, Funds) {
        // Creating a canister is possible only in the following cases:
        // 1. sender is on NNS => it can create canister on any subnet
        // 2. sender is not NNS => can create canister only if sender is on
        // same subnet.
        if sender_subnet_id != state.metadata.network_topology.nns_subnet_id
            && sender_subnet_id != state.metadata.own_subnet_id
        {
            return (
                Err(CanisterManagerError::InvalidSenderSubnet(sender_subnet_id)),
                funds,
            );
        }

        let cycles = funds.cycles();
        if cycles < self.cycles_account_manager.canister_creation_fee() {
            return (
                Err(CanisterManagerError::CreateCanisterNotEnoughCycles {
                    sent: cycles,
                    required: self.cycles_account_manager.canister_creation_fee(),
                }),
                funds,
            );
        }

        // Validate settings before `create_canister_helper` applies them
        match self.validate_settings(settings, state) {
            Err(err) => (Err(err), funds),
            Ok(validate_settings) => {
                // Take the fee out of the cycles that are going to be added as the canister's
                // initial balance.
                let cycles = funds.cycles() - self.cycles_account_manager.canister_creation_fee();
                let canister_id =
                    match self.create_canister_helper(sender, cycles, validate_settings, state) {
                        Ok(canister_id) => canister_id,
                        Err(err) => return (Err(err), funds),
                    };
                (Ok(canister_id), Funds::zero())
            }
        }
    }
/// Creates a new canister and inserts it into `ReplicatedState`.
///
/// Returns the auto-generated id the new canister that has been created.
Creates a new canister and inserts it into `ReplicatedState`.
Returns the auto-generated id the new canister that has been created.
Creates a new canister and inserts it into ` ReplicatedState ` . Returns the auto - generated id the new canister that has been created .
pub(crate) fn create_canister(
        &self,
        sender: PrincipalId,
        sender_subnet_id: SubnetId,
        funds: Funds,
        settings: CanisterSettings,
        state: &mut ReplicatedState,
    ) -> (Result<CanisterId, CanisterManagerError>, Funds) {
        // Creating a canister is possible only in the following cases:
        // 1. sender is on NNS => it can create canister on any subnet
        // 2. sender is not NNS => can create canister only if sender is on
        // same subnet.
        if sender_subnet_id != state.metadata.network_topology.nns_subnet_id
            && sender_subnet_id != state.metadata.own_subnet_id
        {
            return (
                Err(CanisterManagerError::InvalidSenderSubnet(sender_subnet_id)),
                funds,
            );
        }
        let cycles = funds.cycles();
        if cycles < self.cycles_account_manager.canister_creation_fee() {
            return (
                Err(CanisterManagerError::CreateCanisterNotEnoughCycles {
                    sent: cycles,
                    required: self.cycles_account_manager.canister_creation_fee(),
                }),
                funds,
            );
        }
        // Validate settings before `create_canister_helper` applies them
        match self.validate_settings(settings, state) {
            Err(err) => (Err(err), funds),
            Ok(validate_settings) => {
                // Take the fee out of the cycles that are going to be added as the canister's
                // initial balance.
                let cycles = funds.cycles() - self.cycles_account_manager.canister_creation_fee();
                let canister_id =
                    match self.create_canister_helper(sender, cycles, validate_settings, state) {
                        Ok(canister_id) => canister_id,
                        Err(err) => return (Err(err), funds),
                    };
                (Ok(canister_id), Funds::zero())
            }
        }
    }
pub ( crate ) fn create_canister ( & self , sender : PrincipalId , sender_subnet_id : SubnetId , funds : Funds , settings : CanisterSettings , state : & mut ReplicatedState , ) -> ( Result < CanisterId , CanisterManagerError > , Funds ) { // Creating a canister is possible only in the following cases: // 1. sender is on NNS => it can create canister on any subnet // 2. sender is not NNS => can create canister only if sender is on // same subnet. if sender_subnet_id != state . metadata . network_topology . nns_subnet_id && sender_subnet_id != state . metadata . own_subnet_id { return ( Err ( CanisterManagerError :: InvalidSenderSubnet ( sender_subnet_id ) ) , funds , ) ; } let cycles = funds . cycles ( ) ; if cycles < self . cycles_account_manager . canister_creation_fee ( ) { return ( Err ( CanisterManagerError :: CreateCanisterNotEnoughCycles { sent : cycles , required : self . cycles_account_manager . canister_creation_fee ( ) , } ) , funds , ) ; } // Validate settings before `create_canister_helper` applies them match self . validate_settings ( settings , state ) { Err ( err ) => ( Err ( err ) , funds ) , Ok ( validate_settings ) => { // Take the fee out of the cycles that are going to be added as the canister's // initial balance. let cycles = funds . cycles ( ) - self . cycles_account_manager . canister_creation_fee ( ) ; let canister_id = match self . create_canister_helper ( sender , cycles , validate_settings , state ) { Ok ( canister_id ) => canister_id , Err ( err ) => return ( Err ( err ) , funds ) , } ; ( Ok ( canister_id ) , Funds :: zero ( ) ) } } }
Creates a new canister and inserts it into `ReplicatedState`.
Creates a new canister and inserts it into ` ReplicatedState ` .
&self
sender
PrincipalId
sender_subnet_id
SubnetId
funds
Funds
settings
CanisterSettings
state
&mut ReplicatedState
&self
sender
PrincipalId
sender_subnet_id
SubnetId
funds
Funds
settings
CanisterSettings
state
&mut ReplicatedState