pub(crate) fn create_canister(
        &self,
        sender: PrincipalId,
        sender_subnet_id: SubnetId,
        cycles: Cycles,
        settings: CanisterSettings,
        max_number_of_canisters: u64,
        state: &mut ReplicatedState,
    ) -> (Result<CanisterId, CanisterManagerError>, Cycles) {
        // 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 != self.config.own_subnet_id
        {
            return (
                Err(CanisterManagerError::InvalidSenderSubnet(sender_subnet_id)),
                cycles,
            );
        }

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

        // Validate settings before `create_canister_helper` applies them
        match self.validate_settings(
            settings,
            state.total_compute_allocation(),
            state.total_memory_taken(),
        ) {
            Err(err) => (Err(err), cycles),
            Ok(validate_settings) => {
                let canister_id = match self.create_canister_helper(
                    sender,
                    cycles,
                    self.cycles_account_manager.canister_creation_fee(),
                    validate_settings,
                    max_number_of_canisters,
                    state,
                ) {
                    Ok(canister_id) => canister_id,
                    Err(err) => return (Err(err), cycles),
                };
                (Ok(canister_id), Cycles::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,
        cycles: Cycles,
        settings: CanisterSettings,
        max_number_of_canisters: u64,
        state: &mut ReplicatedState,
    ) -> (Result<CanisterId, CanisterManagerError>, Cycles) {
        // 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 != self.config.own_subnet_id
        {
            return (
                Err(CanisterManagerError::InvalidSenderSubnet(sender_subnet_id)),
                cycles,
            );
        }
        if cycles < self.cycles_account_manager.canister_creation_fee() {
            return (
                Err(CanisterManagerError::CreateCanisterNotEnoughCycles {
                    sent: cycles,
                    required: self.cycles_account_manager.canister_creation_fee(),
                }),
                cycles,
            );
        }
        // Validate settings before `create_canister_helper` applies them
        match self.validate_settings(
            settings,
            state.total_compute_allocation(),
            state.total_memory_taken(),
        ) {
            Err(err) => (Err(err), cycles),
            Ok(validate_settings) => {
                let canister_id = match self.create_canister_helper(
                    sender,
                    cycles,
                    self.cycles_account_manager.canister_creation_fee(),
                    validate_settings,
                    max_number_of_canisters,
                    state,
                ) {
                    Ok(canister_id) => canister_id,
                    Err(err) => return (Err(err), cycles),
                };
                (Ok(canister_id), Cycles::zero())
            }
        }
    }
pub ( crate ) fn create_canister ( & self , sender : PrincipalId , sender_subnet_id : SubnetId , cycles : Cycles , settings : CanisterSettings , max_number_of_canisters : u64 , state : & mut ReplicatedState , ) -> ( Result < CanisterId , CanisterManagerError > , Cycles ) { // 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 != self . config . own_subnet_id { return ( Err ( CanisterManagerError :: InvalidSenderSubnet ( sender_subnet_id ) ) , cycles , ) ; } if cycles < self . cycles_account_manager . canister_creation_fee ( ) { return ( Err ( CanisterManagerError :: CreateCanisterNotEnoughCycles { sent : cycles , required : self . cycles_account_manager . canister_creation_fee ( ) , } ) , cycles , ) ; } // Validate settings before `create_canister_helper` applies them match self . validate_settings ( settings , state . total_compute_allocation ( ) , state . total_memory_taken ( ) , ) { Err ( err ) => ( Err ( err ) , cycles ) , Ok ( validate_settings ) => { let canister_id = match self . create_canister_helper ( sender , cycles , self . cycles_account_manager . canister_creation_fee ( ) , validate_settings , max_number_of_canisters , state , ) { Ok ( canister_id ) => canister_id , Err ( err ) => return ( Err ( err ) , cycles ) , } ; ( Ok ( canister_id ) , Cycles :: 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
cycles
Cycles
settings
CanisterSettings
max_number_of_canisters
u64
state
&mut ReplicatedState
&self
sender
PrincipalId
sender_subnet_id
SubnetId
cycles
Cycles
settings
CanisterSettings
max_number_of_canisters
u64
state
&mut ReplicatedState