Repository navigation
Expand file tree
/
Copy pathscCourse.sol
More file actions
174 lines (141 loc) · 4.61 KB
/
Copy pathscCourse.sol
File metadata and controls
174 lines (141 loc) · 4.61 KB
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
pragma solidity ^0.4.17;
pragma experimental ABIEncoderV2;
contract EduBase{
struct CreditCoin
{
string subject;
string institute;
uint256 grade;
uint256 ects;
}
}
/*
holds an array of all CreditCoins of a student
*/
contract Record is EduBase { // TODO: rename to AcademicRecord
CreditCoin[] private diploma;
uint256 public numberOfCC;
address private owner;
function Record() public{
owner=msg.sender;
numberOfCC=0;
}
// string private name; // probably not needed
//address private addr;
/*function Record(address a) {
addr = a;
}
function getAddress() view public returns (address a) {
a = addr;
}*/
/*
function getName() view public returns(string studentName) {
studentName = name;
}
*/
function returnTotalNumberOfCC() view public returns(uint256){
return numberOfCC;
}
function addCreditCoin(CreditCoin cc, address _add) public {
require(owner == _add);
diploma.push(cc);
numberOfCC++;
}
//TODO
function readEntry(uint256 index) view public returns(string, string, uint256, uint256) {
return (diploma[index].subject,diploma[index].institute,diploma[index].grade,diploma[index].ects);
}
// TODO: good idea to return credit coin??
// consider returning only grades for example
// TODO: consider renaming CreditCoin (remove coin from the name)
function getCreditCoins() view public returns(CreditCoin[]) {
return diploma;
}
}
/*
holds mapping from each student to academic record
*/
contract WorldEducation is EduBase {
// map from student address to academic record of student
mapping (address => address) private student_record;
function addCreditCoin(address student, CreditCoin cc) public {
Record(student_record[student]).addCreditCoin(cc,student);
}
function getDiploma(address student) view public returns(CreditCoin[]) {
Record(student_record[student]).getCreditCoins();
}
function addStudentRecord(address student, address record) public {
student_record[student] = record;
}
}
contract PriorityCoin{
mapping(address => uint256) private spentOf;
address public owner = msg.sender;
uint256 constant initialBalance = 100;
function consumeAmount(address to, uint256 amount) public{
require(initialBalance - spentOf[msg.sender] >= amount);
spentOf[msg.sender] += amount;
// TODO implement that the course receives amount of spent bids
}
}
contract Course is EduBase{
PriorityCoin pc;
WorldEducation we;
address public owner;
string public subject;
string public institute;
uint256 public ects;
uint256 public maxNumberOfStudents;
uint256 public curNumberOfStudents;
mapping(address => uint256) private studentBids;
mapping(uint256 => address) public studentList;
function Course(string _subject, address _pc, address _we, uint256 _maxNumberOfStudents) public{
owner = msg.sender;
subject = _subject;
institute = "ETH";
ects = 3;
pc = PriorityCoin(_pc);
we = WorldEducation(_we);
maxNumberOfStudents = _maxNumberOfStudents;
curNumberOfStudents = 0;
}
function bidForCourse(uint256 bid, address record) public{
// Only increase the student number counter if it is the first bid
// Condition for a new student is that the field is initialized to 0
require(bid > 0);
we.addStudentRecord(msg.sender, record);
if(studentBids[msg.sender] == 0){
studentList[curNumberOfStudents] = msg.sender;
curNumberOfStudents++;
}
pc.consumeAmount(owner,bid);
studentBids[msg.sender]=bid;
}
function performAuction() public {
// TODO Actuall need to find the maxNumberOfStudents highest
// Instead currently: First-come-first-serve
for(uint256 i = maxNumberOfStudents; i < curNumberOfStudents; ++i){
delete(studentList[i]);
}
if(maxNumberOfStudents < curNumberOfStudents){
curNumberOfStudents = maxNumberOfStudents;
}
}
function getTotalNumberOfStudents() public view returns(uint256){
return curNumberOfStudents;
}
function getStudentAddress(uint256 _num) public view returns (address) {
return studentList[_num];
}
function grade(address _address,uint256 mark) public {
CreditCoin memory creditCoin = CreditCoin(subject, institute, mark, ects);
we.addCreditCoin(_address,creditCoin);
}
/*function distributeCredits() public{
}
function feedback(uint256 score) public{
}
function getAverageFeedback() public returns (uint256) {
return 0;
}*/
}