-
Notifications
You must be signed in to change notification settings - Fork 38
/
ex10.sol
73 lines (59 loc) · 1.67 KB
/
ex10.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;
import "../exerciceTemplate.sol";
/*
Exercice 10: Analyzing past transactions
In this exercice, you need to:
- Use Etherscan to visualize this contract's transaction history
- Analyze events
- Use a function
- Your points are credited by the contract
*/
/*
What you need to know to complete this exercice
A) What was included in the previous exercices
*/
contract ex10 is exerciceTemplate {
mapping(address => uint) private privateValues;
mapping(address => bool) public exerciceWasStarted;
uint[20] private randomValuesStore;
uint public nextValueStoreRank;
event showPrivateVariableInEvent(uint i, uint myVariable);
event showUserRank(uint i);
constructor(ERC20TD _TDERC20)
exerciceTemplate(_TDERC20)
{
}
function setRandomValueStore(uint[20] memory _randomValuesStore)
public
onlyTeachers
{
randomValuesStore = _randomValuesStore;
nextValueStoreRank = 0;
for (uint i = 0; i < randomValuesStore.length; i++)
{
emit showPrivateVariableInEvent(i, randomValuesStore[i]+i);
}
}
function assignRank()
public
{
privateValues[msg.sender] = randomValuesStore[nextValueStoreRank];
emit showUserRank(nextValueStoreRank);
nextValueStoreRank += 1;
if (nextValueStoreRank >= randomValuesStore.length)
{
nextValueStoreRank = 0;
}
exerciceWasStarted[msg.sender] = true;
}
function showYouKnowPrivateValue(uint _privateValue)
public
{
require(privateValues[msg.sender] == _privateValue);
require(exerciceWasStarted[msg.sender] == true);
// Validating exercice
creditStudent(2, msg.sender);
validateExercice(msg.sender);
}
}