-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDiplomaWallet.sol
106 lines (83 loc) · 2.5 KB
/
DiplomaWallet.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
pragma solidity ^0.4.10;
contract DimplomaWallet {
enum WalletState { Created, Terminated }
enum DiplomaState { PendingApproval, Approved, Rejected }
struct Diploma {
address institution;
string title;
DiplomaState state;
// todo: for signing the content
string hashCode;
}
address public InstitutionsManagerAddr;
address public Owner;
string public StudentFirstName;
string public StudentLastName;
Diploma[] public Assets;
WalletState public state;
// Ctor
function DimplomaWallet(address instManager) {
Owner = msg.sender;
state = WalletState.Created;
InstitutionsManagerAddr = instManager;
}
function AddDiploma(string title) {
// check that this institue is allowed to add new diplomas
InstitutionsManager mgr = InstitutionsManager(InstitutionsManagerAddr);
bool res = mgr.IsAllowedInst(msg.sender);
if (res == false) {
revert();
}
// Create a new diploma object and push it into the users diploma's list
Diploma memory newDiploma;
newDiploma.institution = msg.sender;
newDiploma.title = title;
newDiploma.state = DiplomaState.PendingApproval;
Assets.push(newDiploma);
}
function ApproveDiploma(uint id) {
if (msg.sender != Owner) {
revert();
}
// invalid id
if (Assets.length - 1 < id) {
revert();
}
// only allow approving diplomas which are pending approval
if (Assets[id].state != DiplomaState.PendingApproval) {
revert();
}
Assets[id].state = DiplomaState.Approved;
}
function RejectDiploma(uint id) {
if (msg.sender != Owner) {
revert();
}
// invalid id
if (Assets.length - 1 < id) {
revert();
}
// only allow rejecting diplomas which are pending approval
if (Assets[id].state != DiplomaState.PendingApproval) {
revert();
}
Assets[id].state = DiplomaState.Rejected;
}
}
///////
contract InstitutionsManager {
mapping (address => bool) addressToIsAllowed;
address Owner;
function InstitutionsManager() {
Owner = msg.sender;
}
function IsAllowedInst(address instAddress) returns (bool ret) {
return addressToIsAllowed[instAddress];
}
function ApproveInstitution(address instAddress) {
if (msg.sender != Owner) {
revert();
}
addressToIsAllowed[instAddress] = true;
}
}