// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; // Define the contract contract BlockchainBasedSecurity { // State variables address public admin; // Address of the admin address[] public trustedControllers; // List of trusted controllers string[] private messages; // List of messages sent by controllers mapping(address => bool) private isTrustedController; // Mapping to check if an address is a trusted controller mapping(address => bool) private blacklist; // Mapping to check if an address is blacklisted // Events event ControllerRegistered(address indexed controller); // Event emitted when a controller is registered event ControllerDeleted(address indexed controller); // Event emitted when a controller is deleted event MessageSent(address indexed sender, string message); // Event emitted when a message is sent event Blacklisted(address indexed controller); // Event emitted when a controller is blacklisted // Constructor to set the admin as the contract deployer constructor() { admin = msg.sender; } // Modifier to allow only the admin to execute certain functions modifier onlyAdmin() { require(msg.sender == admin, "Only Admin is Allowed to Add new Controllers"); _; } // Modifier to allow only trusted controllers to execute certain functions modifier onlyTrustedController() { require(isTrustedController[msg.sender], "Only Trusted Controllers can send messages"); _; } // Function to register a new controller, only callable by the admin function registerController(address id) public onlyAdmin { require(id != address(0), "Invalid address"); // Ensure the address is valid require(!isTrustedController[id], "Controller is already registered"); // Ensure the controller is not already registered trustedControllers.push(id); // Add the controller to the list isTrustedController[id] = true; // Mark the controller as trusted emit ControllerRegistered(id); // Emit the ControllerRegistered event } // Function to remove a specific controller, only callable by the admin function removeSpecificController(address controller) public onlyAdmin { require(isTrustedController[controller], "Controller is not registered"); // Ensure the controller is registered for (uint i = 0; i < trustedControllers.length; i++) { // Loop through the list of controllers if (trustedControllers[i] == controller) { // Find the controller to remove trustedControllers[i] = trustedControllers[trustedControllers.length - 1]; // Replace it with the last controller trustedControllers.pop(); // Remove the last controller break; // Exit the loop } } isTrustedController[controller] = false; // Mark the controller as not trusted emit ControllerDeleted(controller); // Emit the ControllerDeleted event } }