

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Assignment i have Implemented on Blockchain
Typology: Exercises
1 / 3
This page cannot be seen from the preview
Don't miss anything!


// SPDX-License-Identifier: MIT pragma solidity ^0.8.0; contract RBAC { address public admin; mapping(address => bool) public managers; mapping(address => bool) public users; modifier onlyAdmin() { require(msg.sender == admin, "Only admin can execute this function."); _; } modifier onlyManager() { require(managers[msg.sender], "Only manager can execute this function."); _; } modifier onlyUser() { require(users[msg.sender], "Only user can execute this function."); _; } constructor() { admin = msg.sender; } function addManager(address _manager) public onlyAdmin { managers[_manager] = true; } function removeManager(address _manager) public onlyAdmin { managers[_manager] = false; }
function addUser(address _user) public onlyAdmin { users[_user] = true; } function removeUser(address _user) public onlyAdmin { users[_user] = false; } function adminFunction() public onlyAdmin { // Only admin can execute this function emit Log("Admin function executed."); } function managerFunction() public onlyManager { // Only manager can execute this function emit Log("Manager function executed."); } function userFunction() public onlyUser { // Only user can execute this function emit Log("User function executed."); } event Log(string message); }