-
Notifications
You must be signed in to change notification settings - Fork 38
/
ex08.sol
90 lines (69 loc) · 2.14 KB
/
ex08.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import "../exerciceTemplate.sol";
/*
Exercice 8: structures
In this exercice, you need to:
- Create an object using a structure
- Modify it
- Claim your points
- Your points are credited by the contract
*/
/*
What you need to know to complete this exercice
A) What was included in the previous exercices
B) What a structure is https://solidity.readthedocs.io/en/develop/types.html#index-14
*/
contract ex08 is exerciceTemplate {
struct studentObject
{
address owner;
address creator;
string name;
bool hasBeenModified;
}
studentObject[] public studentObjects;
event createdAnObject(uint objectNumber);
constructor(ERC20TD _TDERC20)
exerciceTemplate(_TDERC20)
{
}
function createObject(string memory _name)
public
{
studentObject memory _studentObject;
_studentObject.owner = msg.sender;
_studentObject.creator = msg.sender;
_studentObject.name = _name;
_studentObject.hasBeenModified = false;
studentObjects.push(_studentObject);
uint objectNumber = studentObjects.length - 1;
emit createdAnObject(objectNumber);
}
function changeObjectName(uint _objectNumber, string memory _name)
public
{
require(studentObjects[_objectNumber].owner == msg.sender);
studentObjects[_objectNumber].name = _name;
studentObjects[_objectNumber].hasBeenModified = true;
}
function transfer(uint _objectNumber, address _recipient)
public
{
require(studentObjects[_objectNumber].owner == msg.sender);
studentObjects[_objectNumber].owner = _recipient;
}
function claimPoints(uint _objectNumber)
public
{
// Check that you are validating with an object you created
require(studentObjects[_objectNumber].creator == msg.sender);
// Check that the object has been modified at some pooint
require(studentObjects[_objectNumber].hasBeenModified == true);
// Check that the current owner of the object is a teacher/exercise
require(TDERC20.teachers(studentObjects[_objectNumber].owner));
// Validating exercice
creditStudent(2, msg.sender);
validateExercice(msg.sender);
}
}