-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGamesHistory.sol
120 lines (97 loc) · 2.82 KB
/
GamesHistory.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
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
pragma ton-solidity ^0.42.0;
pragma AbiHeader expire;
pragma AbiHeader time;
pragma AbiHeader pubkey;
import 'interfaces/LotteryInterface.sol';
import 'utils/ArrayUtil.sol';
/**
* Error codes
* • 100 — Method only for owner
* • 101 — Method only for root
*/
contract GamesHistory is ArrayUtil {
/*************
* CONSTANTS *
*************/
/**************
* STRUCTURES *
**************/
struct GameInfo {
address game;
address winner;
uint128 reward;
uint128 amount;
uint64 count;
}
/*************
* VARIABLES *
*************/
address private _rootAddress;
GameInfo[] private _games;
uint64 static _seed;
/*************
* MODIFIERS *
*************/
modifier accept {
tvm.accept();
_;
}
modifier onlyOwner {
require(msg.pubkey() == tvm.pubkey(), 100, "Method only for owner");
_;
}
modifier onlyRoot {
require(msg.sender == _rootAddress, 101, "Method only for root");
_;
}
/***************
* CONSTRUCTOR *
***************/
constructor(
address rootAddress
) public accept {
_rootAddress = rootAddress;
}
/***********
* GETTERS *
***********/
function getRootAddress() public view returns (address rootAddress) { return _rootAddress; }
function getGamesCount() public view returns (uint64 gamesCount) { return uint64(_games.length); }
function getGames(uint64 offset, uint64 limit) public view returns (
address[] games,
address[] winners,
uint128[] rewards,
uint128[] amounts,
uint64[] counts,
uint64 totalLength
) {
GameInfo[] gamesArr = _games;
uint64 endIndex = _getEndIndex(offset, limit, gamesArr.length);
for (uint64 i = offset; i < endIndex; i++) {
GameInfo game = gamesArr[i];
games.push(game.game);
winners.push(game.winner);
rewards.push(game.reward);
amounts.push(game.amount);
counts.push(game.count);
}
return (games, winners, rewards, amounts, counts, uint64(games.length));
}
/***********************
* PUBLIC * ONLY OWNER *
***********************/
function setRoot(address rootAddress) public onlyOwner accept {
_rootAddress = rootAddress;
}
/************
* EXTERNAL *
************/
function save(address game, address winner, uint128 reward, uint128 amount, uint64 count) external onlyRoot {
GameInfo _game = GameInfo(game, winner, reward, amount, count);
_games.push(_game);
LotteryInterface(_rootAddress).returnChange{value: 0, flag: 128}();
}
/***********
* PRIVATE *
***********/
}