-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontract.sol
79 lines (70 loc) · 1.93 KB
/
contract.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
contract ScrapBook {
struct Identity {
address identityAddress;
uint registrationTimestamp;
Charity identityCharity;
bool exists;
uint latestEntryTimestamp;
mapping (uint => Entry) entries;
mapping (address => Identity) parents;
}
struct Charity {
bytes16 charityName;
bytes16 storeName;
bytes32 baseUrl;
bool exists;
}
struct Entry {
bytes32 hashValue;
bytes32 comment;
uint previousEntryTimestamp;
}
mapping (address => Identity) identities;
mapping (bytes16 => Charity) charities;
address public owner;
modifier isAdmin { if (owner == msg.sender) _ }
function ScrapBook() { owner = msg.sender; }
function registerCharity(bytes16 charityName, bytes16 storeName, bytes32 baseUrl) isAdmin public returns (bool) {
Charity c = charities[charityName];
if (c.exists) {
return false;
}
c.storeName = storeName;
c.baseUrl = baseUrl;
return true;
}
function registerIdentity(bytes16 charityName) public returns (bool) {
Identity i = identities[msg.sender];
Charity c = charities[charityName];
// check and see if user not already registered and store is known
if (i.exists || !c.exists) {
return false;
}
i.registrationTimestamp = now;
i.identityCharity = c;
i.exists = true;
return true;
}
function registerChild(address childAddress) public returns (bool) {
Identity p = identities[msg.sender];
Identity c = identities[childAddress];
// check and see if parent and child are already registered
if (!p.exists || c.exists) {
return false;
}
c.parents[msg.sender] = p;
return true;
}
function createScrapBookEntry(bytes32 hashValue, bytes32 comment) public returns (bool) {
Identity i = identities[msg.sender];
if (!i.exists) {
return false;
}
uint nowTimeStamp = now;
Entry next = i.entries[nowTimeStamp];
next.previousEntryTimestamp = i.latestEntryTimestamp;
next.hashValue = hashValue;
next.comment = comment;
i.latestEntryTimestamp = nowTimeStamp;
}
}