This repository has been archived by the owner on Jun 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathFractalRegistry.sol
89 lines (77 loc) · 2.88 KB
/
FractalRegistry.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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// SPDX-License-Identifier: MIT
pragma solidity >=0.7.0 <0.9.0;
/// @title Fractal registry v0
/// @author Antoni Dikov and Shelby Doolittle
contract FractalRegistry {
address root;
mapping(address => bool) delegates;
mapping(address => bytes32) fractalIdForAddress;
mapping(string => mapping(bytes32 => bool)) userLists;
constructor(address _root) {
root = _root;
}
/// @param addr is Eth address
/// @return FractalId as bytes32
function getFractalId(address addr) external view returns (bytes32) {
return fractalIdForAddress[addr];
}
/// @notice Adds a user to the mapping of Eth address to FractalId.
/// @param addr is Eth address.
/// @param fractalId is FractalId in bytes32.
function addUserAddress(address addr, bytes32 fractalId) external {
requireMutatePermission();
fractalIdForAddress[addr] = fractalId;
}
/// @notice Removes an address from the mapping of Eth address to FractalId.
/// @param addr is Eth address.
function removeUserAddress(address addr) external {
requireMutatePermission();
delete fractalIdForAddress[addr];
}
/// @notice Checks if a user by FractalId exists in a specific list.
/// @param userId is FractalId in bytes32.
/// @param listId is the list id.
/// @return bool if the user is the specified list.
function isUserInList(bytes32 userId, string memory listId)
external
view
returns (bool)
{
return userLists[listId][userId];
}
/// @notice Add user by FractalId to a specific list.
/// @param userId is FractalId in bytes32.
/// @param listId is the list id.
function addUserToList(bytes32 userId, string memory listId) external {
requireMutatePermission();
userLists[listId][userId] = true;
}
/// @notice Remove user by FractalId from a specific list.
/// @param userId is FractalId in bytes32.
/// @param listId is the list id.
function removeUserFromList(bytes32 userId, string memory listId) external {
requireMutatePermission();
delete userLists[listId][userId];
}
/// @notice Only root can add delegates. Delegates have mutate permissions.
/// @param addr is Eth address
function addDelegate(address addr) external {
require(msg.sender == root, "Must be root");
delegates[addr] = true;
}
/// @notice Removing delegates is only posible from root or by himself.
/// @param addr is Eth address
function removeDelegate(address addr) external {
require(
msg.sender == root || msg.sender == addr,
"Not allowed to remove address"
);
delete delegates[addr];
}
function requireMutatePermission() private view {
require(
msg.sender == root || delegates[msg.sender],
"Not allowed to mutate"
);
}
}