-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGroupManager.sol
53 lines (45 loc) · 1.38 KB
/
GroupManager.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
pragma solidity ^0.4.0;
contract GroupManager {
struct Group {
bytes32 groupName;
uint groupFee;
uint groupExpiry;
uint groupCreated;
uint groupStatus;
uint totalAmount;
uint memberCount;
mapping (uint => GroupMember) GroupMembers;
}
struct GroupMember {
address memberAddress;
}
uint groupId;
address AdminGroupManager;
mapping (uint => Group) Groups;
function GroupManager() {
AdminGroupManager = msg.sender;
}
function CreateGroup (bytes32 groupName, uint groupFee, uint groupSeconds) public returns (uint thisGroupId){
if (AdminGroupManager != msg.sender) throw;
thisGroupId = groupId++;
Group memory thisMember;
thisMember.groupName = groupName;
thisMember.groupFee = groupFee;
thisMember.groupCreated = now;
thisMember.groupExpiry = now + groupSeconds;
thisMember.groupStatus = 0;
Groups[thisGroupId] = thisMember;
}
function MemberJoin (uint groupId) payable {
if (AdminGroupManager == msg.sender) throw;
Group id = Groups[groupId];
if (msg.value != id.groupFee) throw;
id.GroupMembers[id.memberCount++] = GroupMember(msg.sender);
id.totalAmount += msg.value;
}
function closeGroup (uint groupId) payable {
if (AdminGroupManager != msg.sender) throw;
Group id = Groups[groupId];
id.groupStatus = 1;
}
}