| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- pragma solidity ^0.4.0;
- // 独立实现
- contract resume {
- // 众筹项目
- struct Student {
- //学生名
- string name;
- // 学生编号
- string studentNo;
- // 捐赠人数
- uint recordCount;
- // 是否是本校学生
- bool nju;
- // 学习记录
- mapping(uint => Record) records;
- // 原本使用 Record[] records 数组定义
- }
- // 捐赠记录
- struct Record {
- // 学习记录id
- uint id;
- // json格式的学习记录,便于扩展,可以自己定义json格式
- string json;
- // 添加记录时间
- uint time;
- }
- // 学生列表
- Student[] students;
- // 获取学生数量
- function getStudentCount() public view returns (uint) {
- return students.length;
- }
- // 获取学生
- function getStudentInfo(uint studentIndex) public view returns (string, string, uint, bool) {
- Student storage student = students[studentIndex];
- return (student.name, student.studentNo, student.recordCount, student.nju);
- }
- // 获取众筹捐赠人数
- function getRecordCount(uint studentIndex) public view returns (uint) {
- return students[studentIndex].recordCount;
- }
- // 获取学习记录
- // 参数:学生编号 记录编号
- function getRecordInfo(uint studentIndex, uint recordIndex) public view returns (uint, string) {
- Record storage record = students[studentIndex].records[recordIndex];
- return (record.id, record.json);
- }
- // 为自己发起众筹
- function addStudent(string name, string studentNo, bool nju) public {
- students.push(Student(name, studentNo, 0, nju));
- }
- // 新增学习记录
- function addRecord(uint studentIndex, uint id, string json) public payable {
- // 引用拷贝
- Student storage student = students[studentIndex];
- //require(student.nju); //如果添加这一行表示是南京大学本校学生才可以添加记录
- // 更新众筹信息
- student.records[student.recordCount++] = Record(id, json, now);
- }
- // 回退函数 防止抛出异常
- // https://solidity.readthedocs.io/en/latest/contracts.html#fallback-function
- // if you want your contract to receive Ether, you have to implement a fallback function.
- function() public payable { }
- }
|