forked from l-henri/solidity-101
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex07.sol
78 lines (63 loc) · 1.96 KB
/
ex07.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
pragma solidity ^0.6.0;
import "../exerciceTemplate.sol";
/*
Exercice 7: Events
In this exercice, you need to:
- Use function assignRank() to receive a rank in the random value store
- Use a function to trigger an event
- Use Etherscan to analyse this event
- Use a function to show you know the correct value of a private variable
- Your points are credited by the contract
DONE
*/
/*
What you need to know to complete this exercice
A) What was included in the previous exercices
B) Events are used to log data that is accessible from a full node, but not stored in the contracts variables.
https://solidity.readthedocs.io/en/develop/introduction-to-smart-contracts.html#index-2
C) Etherscan.io https://etherscan.io/ lets you visualize events that were fired during a given transaction
*/
contract ex07 is exerciceTemplate {
mapping(address => uint) private privateValues;
mapping(address => bool) public exerciceWasStarted;
uint[20] private randomValuesStore;
uint public nextValueStoreRank;
event showPrivateVariableInEvent(uint myVariable);
constructor(ERC20TD _TDERC20)
public
exerciceTemplate(_TDERC20)
{
}
function setRandomValueStore(uint[20] memory _randomValuesStore)
public
onlyTeachers
{
randomValuesStore = _randomValuesStore;
nextValueStoreRank = 0;
}
function assignRank()
public
{
privateValues[msg.sender] = randomValuesStore[nextValueStoreRank];
nextValueStoreRank += 1;
if (nextValueStoreRank >= randomValuesStore.length)
{
nextValueStoreRank = 0;
}
exerciceWasStarted[msg.sender] = true;
}
function fireEvent()
public
{
emit showPrivateVariableInEvent(privateValues[msg.sender]+32);
}
function showYouKnowPrivateValue(uint _privateValue)
public
{
require(privateValues[msg.sender] == _privateValue);
require(exerciceWasStarted[msg.sender] == true);
// Validating exercice
creditStudent(2, msg.sender);
validateExercice(msg.sender);
}
}