-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMembers.sol
159 lines (140 loc) · 4.41 KB
/
Members.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
pragma solidity ^0.4.4;
contract Members {
/**
* @notice a mapping of organization name to organization public address
*
* @example
* "Medi Corp" -> "0x9L1m03nl0Pc5ns4kh2Kp34kl23fjskoL2m"
* organizationAddress[organization] = Public Key
*/
mapping (bytes32 => address) public organizationAddress;
/**
* @notice a mapping of organization public address to organization name
*
* @example
* "0x123...abc" -> "Medi Corp"
*/
mapping (address => bytes32) public organizations;
/**
* @notice a mapping of organization to
* their hashes of Member Records
*
* @example example
* members[organization][MemberHash] -> Member Hash
*/
mapping (bytes32 => mapping (bytes32 => bytes32)) public members;
/**
* @notice The owner of this contract.
*/
address public owner;
/**
* Events, when triggered, record logs in the blockchain.
* Clients can listen on specific events to fetch data.
*/
event _OrganizationAddressRegistered(bytes32 indexed organization, address indexed memberAddressKey);
event _MemberAdded(bytes32 indexed member, bytes32 indexed memberHash);
event _MemberRemoved(bytes32 indexed member, bytes32 indexed memberHash);
/**
* @notice modifier which limits execution of the function to the owner.
*/
modifier onlyOwner() {
if (msg.sender != owner) {
revert();
}
// continue with code execution
_;
}
/**
* @notice modifier which checks if sender is a registered organizationAddress.
*/
modifier isRegistered() {
if (organizations[msg.sender] == 0) {
revert();
}
// continue with code execution
_;
}
/**
* @notice modifier which checks that organizationAddress doesn't exist.
*/
modifier organizationAddressDoesNotExist(address pubKey) {
if (organizations[pubKey] != 0) {
revert();
}
// continue with code execution
_;
}
/*
* @notice The constructor function,
* called only once when this contract is initially deployed.
*/
constructor() public {
owner = msg.sender;
}
/**
* @notice Register new organizationAddress.
* Only the owner of the contract can register new organizationAddress.
* organizationAddress public key must not already exist in order to
* be added or modified.
* @param organizationName name
* @param pubKey organization public key
*/
function registerOrganizationAddress(bytes32 organizationName, address pubKey) onlyOwner organizationAddressDoesNotExist(pubKey) external {
organizationAddress[keccak256(organizationName)] = pubKey;
organizations[pubKey] = organizationName;
emit _OrganizationAddressRegistered(organizationName, pubKey);
}
/**
* @notice Allow organizationAddress to add a Member by the hash of the Member information.
* @param hash keccak256 hash of Member information
*/
function addMemberRecord(bytes32 hash) isRegistered public {
members[keccak256(organizations[msg.sender])][hash] = hash;
emit _MemberAdded(organizations[msg.sender], hash);
}
/**
* @notice Remove Member from organizationAddress
* @param hash keccak256 hash of Member information
*/
function removeMemberRecord(bytes32 hash) isRegistered public {
delete members[keccak256(organizations[msg.sender])][hash];
emit _MemberRemoved(organizations[msg.sender], hash);
}
/**
* @notice Check if organizationAddress is registered.
* @param pubKey organizationAddress public key
* @return bool
*/
function isRegisteredOrganizationAddress(address pubKey) external constant returns (bool) {
return (organizations[pubKey] != "");
}
/**
* @notice Check if organizationAddress is registered
* @param organizationName name
* @return bool
*/
function isRegisteredOrganization(bytes32 organizationName) external constant returns (bool) {
return (organizationAddress[keccak256(organizationName)] != address(0));
}
/**
* @notice Return true if member record exits for the organizationAddress
* @param pubKey organizationAddress public key
* @param name of member
* @param occupation of member
* @param location of member
* @return boolean
*/
function doesMemberRecordExist(
address pubKey,
string name,
string occupation,
string location
)
external
constant
returns (bool)
{
bytes32 hash = keccak256(name, occupation, location);
return (members[keccak256(organizations[pubKey])][hash] != "");
}
}