-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload.sol
46 lines (43 loc) · 1.54 KB
/
upload.sol
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
// SPDX-License-Identifier: GPL-3.0
pragma solidity 0.8.19;
contract Upload {
struct Access{
address user;
bool access;
}
mapping(address=>string[]) value;
mapping(address=>mapping(address=>bool)) ownership;
mapping(address=>Access[]) accessList;
mapping(address=>mapping(address=>bool)) previousData;
function add(address _user, string memory url) external{
value[_user].push(url);
}
function allow(address user) external{
ownership[msg.sender][user]=true;
if(previousData[msg.sender][user]){
for(uint i=0;i<accessList[msg.sender].length;i++){
if(accessList[msg.sender][i].user==user){
accessList[msg.sender][i].access=true;
}
}
}else{
accessList[msg.sender].push(Access(user,true));
previousData[msg.sender][user]=true;
}
}
function disallow(address user) public{
ownership[msg.sender][user]=false;
for(uint i=0;i<accessList[msg.sender].length;i++){
if(accessList[msg.sender][i].user==user){
accessList[msg.sender][i].access=false;
}
}
}
function display(address _user) external view returns(string[] memory){
require(_user==msg.sender || ownership[_user][msg.sender],"You don't have access");
return value[_user];
}
function shareAccess() public view returns(Access[] memory){
return accessList[msg.sender];
}
}