-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathabacAccessControl.sol
More file actions
74 lines (58 loc) · 2.16 KB
/
abacAccessControl.sol
File metadata and controls
74 lines (58 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.7;
// Abstract contract
abstract contract abacAccessControl {
struct Permissions {
bool canRead;
bool canWrite;
uint256 remainingOperations;
}
mapping(address => Permissions) internal _permissions;
string private result;
constructor() {
_permissions[msg.sender] = Permissions(true, true, 3);
}
// Function: Get the permissions for an address
function getPermissions(address account) external view returns (Permissions memory) {
return _permissions[account];
}
// Abstract function: Update the permissions for an address
function updatePermissions(address account, bool canRead, bool canWrite, uint256 remainingOperations) external virtual;
}
contract MyContract is abacAccessControl {
// Modifier: Only the contract owner can call the function
address owner;
bool public isExecuted;
constructor() {
owner = msg.sender;
isExecuted = false;
}
event AccessStatus (address indexed user, string reason);
modifier onlyOwner() {
require(msg.sender == owner, "Only the contract owner can call this function");
_;
}
// Override the abstract function and provide a concrete implementation
function updatePermissions(address account, bool canRead, bool canWrite, uint256 remainingOperations) external override onlyOwner {
_permissions[account] = Permissions({
canRead: canRead,
canWrite: canWrite,
remainingOperations: remainingOperations
});
}
function foo() public returns (bool){
require (_permissions[msg.sender].canWrite, "Visitor does not have write permission");
require(_permissions[msg.sender].remainingOperations > 0, "Visitor has no remaining operations");
isExecuted = true;
_permissions[msg.sender].remainingOperations --;
return isExecuted;
}
function isFooExecuted() public {
if (isExecuted) {
emit AccessStatus(msg.sender, "true");
isExecuted = false;
} else {
emit AccessStatus(msg.sender, "false");
}
}
}