pub(crate) fn should_accept_ingress_message(
        &self,
        state: Arc<ReplicatedState>,
        provisional_whitelist: &ProvisionalWhitelist,
        sender: UserId,
        method_name: &str,
        payload: &[u8],
    ) -> Result<(), MessageAcceptanceError> {
        fn is_sender_controller(
            canister_id: CanisterId,
            sender: UserId,
            state: Arc<ReplicatedState>,
        ) -> Result<(), MessageAcceptanceError> {
            match state.canister_state(&canister_id) {
                Some(canister) => {
                    if sender.get() != canister.controller() {
                        Err(MessageAcceptanceError::CanisterRejected)
                    } else {
                        Ok(())
                    }
                }
                None => Err(MessageAcceptanceError::CanisterNotFound),
            }
        }

        // The message is targetted towards the management canister. The
        // actual type of the method will determine if the message should be
        // accepted or not.
        match Ic00Method::from_str(method_name) {
            // The method is either invalid or it is of a type that users
            // are not allowed to send.
            Err(_)
            | Ok(Ic00Method::CreateCanister)
                | Ok(Ic00Method::SetupInitialDKG)
                // This method is deprecated
                | Ok(Ic00Method::DepositFunds)
                // This can be called by anyone however as ingress message
                // cannot carry cycles, it does not make sense to allow them from users.
            | Ok(Ic00Method::DepositCycles) => Err(MessageAcceptanceError::CanisterRejected),

            // These methods are only valid if they are sent by the controller
            // of the canister. We assume that the canister always wants to
            // accept messages from its controller.
            Ok(Ic00Method::CanisterStatus)
            | Ok(Ic00Method::StartCanister)
            | Ok(Ic00Method::UninstallCode)
            | Ok(Ic00Method::StopCanister)
            | Ok(Ic00Method::DeleteCanister) => match Decode!(&payload, CanisterIdRecord) {
                Err(_) => Err(MessageAcceptanceError::CanisterRejected),
                Ok(args) => is_sender_controller(args.get_canister_id(), sender, state),
            },
            Ok(Ic00Method::UpdateSettings) => match Decode!(&payload, UpdateSettingsArgs) {
                Err(_) => Err(MessageAcceptanceError::CanisterRejected),
                Ok(args) => is_sender_controller(args.get_canister_id(), sender, state),
            },
            Ok(Ic00Method::InstallCode) => match Decode!(&payload, InstallCodeArgs) {
                Err(_) => Err(MessageAcceptanceError::CanisterRejected),
                Ok(args) => is_sender_controller(args.get_canister_id(), sender, state),
            },
            Ok(Ic00Method::SetController) => match Decode!(&payload, SetControllerArgs) {
                Err(_) => Err(MessageAcceptanceError::CanisterRejected),
                Ok(args) => is_sender_controller(args.get_canister_id(), sender, state),
            },

            // Nobody pays for `raw_rand`, so this cannot be used via ingress messages
            Ok(Ic00Method::RawRand) => Err(MessageAcceptanceError::CanisterRejected),

            Ok(Ic00Method::ProvisionalCreateCanisterWithCycles)
                | Ok(Ic00Method::ProvisionalTopUpCanister) => {
                    if provisional_whitelist.contains(sender.get_ref()) {
                        Ok(())
                    } else {
                        Err(MessageAcceptanceError::CanisterRejected)
                    }
                }
        }
    }
/// Checks if a given ingress message directed to the management canister
/// should be accepted or not.
Checks if a given ingress message directed to the management canister
should be accepted or not.
Checks if a given ingress message directed to the management canister should be accepted or not .
pub(crate) fn should_accept_ingress_message(
        &self,
        state: Arc<ReplicatedState>,
        provisional_whitelist: &ProvisionalWhitelist,
        sender: UserId,
        method_name: &str,
        payload: &[u8],
    ) -> Result<(), MessageAcceptanceError> {
        fn is_sender_controller(
            canister_id: CanisterId,
            sender: UserId,
            state: Arc<ReplicatedState>,
        ) -> Result<(), MessageAcceptanceError> {
            match state.canister_state(&canister_id) {
                Some(canister) => {
                    if sender.get() != canister.controller() {
                        Err(MessageAcceptanceError::CanisterRejected)
                    } else {
                        Ok(())
                    }
                }
                None => Err(MessageAcceptanceError::CanisterNotFound),
            }
        }
        // The message is targetted towards the management canister. The
        // actual type of the method will determine if the message should be
        // accepted or not.
        match Ic00Method::from_str(method_name) {
            // The method is either invalid or it is of a type that users
            // are not allowed to send.
            Err(_)
            | Ok(Ic00Method::CreateCanister)
                | Ok(Ic00Method::SetupInitialDKG)
                // This method is deprecated
                | Ok(Ic00Method::DepositFunds)
                // This can be called by anyone however as ingress message
                // cannot carry cycles, it does not make sense to allow them from users.
            | Ok(Ic00Method::DepositCycles) => Err(MessageAcceptanceError::CanisterRejected),
            // These methods are only valid if they are sent by the controller
            // of the canister. We assume that the canister always wants to
            // accept messages from its controller.
            Ok(Ic00Method::CanisterStatus)
            | Ok(Ic00Method::StartCanister)
            | Ok(Ic00Method::UninstallCode)
            | Ok(Ic00Method::StopCanister)
            | Ok(Ic00Method::DeleteCanister) => match Decode!(&payload, CanisterIdRecord) {
                Err(_) => Err(MessageAcceptanceError::CanisterRejected),
                Ok(args) => is_sender_controller(args.get_canister_id(), sender, state),
            },
            Ok(Ic00Method::UpdateSettings) => match Decode!(&payload, UpdateSettingsArgs) {
                Err(_) => Err(MessageAcceptanceError::CanisterRejected),
                Ok(args) => is_sender_controller(args.get_canister_id(), sender, state),
            },
            Ok(Ic00Method::InstallCode) => match Decode!(&payload, InstallCodeArgs) {
                Err(_) => Err(MessageAcceptanceError::CanisterRejected),
                Ok(args) => is_sender_controller(args.get_canister_id(), sender, state),
            },
            Ok(Ic00Method::SetController) => match Decode!(&payload, SetControllerArgs) {
                Err(_) => Err(MessageAcceptanceError::CanisterRejected),
                Ok(args) => is_sender_controller(args.get_canister_id(), sender, state),
            },
            // Nobody pays for `raw_rand`, so this cannot be used via ingress messages
            Ok(Ic00Method::RawRand) => Err(MessageAcceptanceError::CanisterRejected),
            Ok(Ic00Method::ProvisionalCreateCanisterWithCycles)
                | Ok(Ic00Method::ProvisionalTopUpCanister) => {
                    if provisional_whitelist.contains(sender.get_ref()) {
                        Ok(())
                    } else {
                        Err(MessageAcceptanceError::CanisterRejected)
                    }
                }
        }
    }
pub ( crate ) fn should_accept_ingress_message ( & self , state : Arc < ReplicatedState > , provisional_whitelist : & ProvisionalWhitelist , sender : UserId , method_name : & str , payload : & [ u8 ] , ) -> Result < ( ) , MessageAcceptanceError > { fn is_sender_controller ( canister_id : CanisterId , sender : UserId , state : Arc < ReplicatedState > , ) -> Result < ( ) , MessageAcceptanceError > { match state . canister_state ( & canister_id ) { Some ( canister ) => { if sender . get ( ) != canister . controller ( ) { Err ( MessageAcceptanceError :: CanisterRejected ) } else { Ok ( ( ) ) } } None => Err ( MessageAcceptanceError :: CanisterNotFound ) , } } // The message is targetted towards the management canister. The // actual type of the method will determine if the message should be // accepted or not. match Ic00Method :: from_str ( method_name ) { // The method is either invalid or it is of a type that users // are not allowed to send. Err ( _ ) | Ok ( Ic00Method :: CreateCanister ) | Ok ( Ic00Method :: SetupInitialDKG ) // This method is deprecated | Ok ( Ic00Method :: DepositFunds ) // This can be called by anyone however as ingress message // cannot carry cycles, it does not make sense to allow them from users. | Ok ( Ic00Method :: DepositCycles ) => Err ( MessageAcceptanceError :: CanisterRejected ) , // These methods are only valid if they are sent by the controller // of the canister. We assume that the canister always wants to // accept messages from its controller. Ok ( Ic00Method :: CanisterStatus ) | Ok ( Ic00Method :: StartCanister ) | Ok ( Ic00Method :: UninstallCode ) | Ok ( Ic00Method :: StopCanister ) | Ok ( Ic00Method :: DeleteCanister ) => match Decode ! ( payload CanisterIdRecord ) { Err ( _ ) => Err ( MessageAcceptanceError :: CanisterRejected ) , Ok ( args ) => is_sender_controller ( args . get_canister_id ( ) , sender , state ) , } , Ok ( Ic00Method :: UpdateSettings ) => match Decode ! ( payload UpdateSettingsArgs ) { Err ( _ ) => Err ( MessageAcceptanceError :: CanisterRejected ) , Ok ( args ) => is_sender_controller ( args . get_canister_id ( ) , sender , state ) , } , Ok ( Ic00Method :: InstallCode ) => match Decode ! ( payload InstallCodeArgs ) { Err ( _ ) => Err ( MessageAcceptanceError :: CanisterRejected ) , Ok ( args ) => is_sender_controller ( args . get_canister_id ( ) , sender , state ) , } , Ok ( Ic00Method :: SetController ) => match Decode ! ( payload SetControllerArgs ) { Err ( _ ) => Err ( MessageAcceptanceError :: CanisterRejected ) , Ok ( args ) => is_sender_controller ( args . get_canister_id ( ) , sender , state ) , } , // Nobody pays for `raw_rand`, so this cannot be used via ingress messages Ok ( Ic00Method :: RawRand ) => Err ( MessageAcceptanceError :: CanisterRejected ) , Ok ( Ic00Method :: ProvisionalCreateCanisterWithCycles ) | Ok ( Ic00Method :: ProvisionalTopUpCanister ) => { if provisional_whitelist . contains ( sender . get_ref ( ) ) { Ok ( ( ) ) } else { Err ( MessageAcceptanceError :: CanisterRejected ) } } } }
Checks if a given ingress message directed to the management canister
should be accepted or not.
Checks if a given ingress message directed to the management canister should be accepted or not .
&self
state
Arc<ReplicatedState>
provisional_whitelist
&ProvisionalWhitelist
sender
UserId
method_name
&str
payload
&[u8]
&self
state
Arc<ReplicatedState>
provisional_whitelist
&ProvisionalWhitelist
sender
UserId
method_name
&str
payload
&[u8]