-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdedrive.sol
More file actions
50 lines (43 loc) · 1.46 KB
/
dedrive.sol
File metadata and controls
50 lines (43 loc) · 1.46 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
// SPDX-License-Identifier: GPL-3.0
pragma solidity >=0.7.0 <0.9.0;
contract Upload {
struct Access{
address user;
bool access; //true or false
}
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 {//def
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];
}
}