-
Notifications
You must be signed in to change notification settings - Fork 0
Showing
351 changed files
with
42,522 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
/** | ||
* @dev This contract provides simple event managing functionality: | ||
* inserting, deleting and polling events. | ||
* | ||
* This module is used through inheritance. | ||
*/ | ||
abstract contract EventManager { | ||
struct Event { | ||
uint64 eventId; | ||
uint16 eventType; | ||
bytes data; | ||
} | ||
|
||
struct EventEntries { | ||
Event[] data; | ||
mapping(uint64 => uint64) dataIdxByEventId; | ||
} | ||
|
||
mapping(uint16 => EventEntries) private _eventsByType; | ||
|
||
uint private _maxEventsPerType; | ||
|
||
constructor(uint maxEventsPerType) { | ||
_maxEventsPerType = maxEventsPerType; | ||
} | ||
|
||
function insertEvent(uint64 eventId, uint16 eventType, bytes memory data) internal { | ||
Event[] storage events = _eventsByType[eventType].data; | ||
require(events.length < _maxEventsPerType, "Event buffer is full"); | ||
|
||
events.push(Event(eventId, eventType, data)); | ||
_eventsByType[eventType].dataIdxByEventId[eventId] = uint64(events.length) - 1; | ||
} | ||
|
||
function eraseEvent(uint64 eventId, uint16 eventType) internal { | ||
EventEntries storage entries = _eventsByType[eventType]; | ||
|
||
uint64 index = entries.dataIdxByEventId[eventId]; | ||
require(index < entries.data.length, "Event does not exist"); | ||
|
||
// Swap the last event with the one to delete and then pop the last | ||
uint64 lastIndex = uint64(entries.data.length) - 1; | ||
if (index != lastIndex) { | ||
Event storage lastEvent = entries.data[lastIndex]; | ||
entries.data[index] = lastEvent; | ||
entries.dataIdxByEventId[lastEvent.eventId] = index; | ||
} | ||
entries.data.pop(); | ||
delete entries.dataIdxByEventId[eventId]; | ||
} | ||
|
||
function getEvents(uint16 eventType) public view returns (Event[] memory) { | ||
EventEntries storage entries = _eventsByType[eventType]; | ||
return entries.data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
import "./EventManager.sol"; | ||
|
||
contract RandomnessGenerator is EventManager { | ||
uint64 public randomnessId; | ||
mapping(uint256 => uint256) public randomnessJobs; | ||
address public writer; | ||
|
||
// Don't change the order of the entries in enum declaration. Backend relies on integer number under the enum | ||
enum EventType { | ||
RandomnessRequested | ||
} | ||
|
||
constructor(address _writer) EventManager(10240) { | ||
randomnessId = 0; | ||
writer = _writer; | ||
} | ||
|
||
function requestRandomness() external returns (uint256) { | ||
randomnessId += 1; | ||
bytes memory requestData = abi.encode(randomnessId); | ||
insertEvent(randomnessId, uint16(EventType.RandomnessRequested), requestData); | ||
return randomnessId; | ||
} | ||
|
||
function postRandomness(uint64 id, uint256 randomness) external { | ||
require(msg.sender == writer, "Only writer can post randomness"); | ||
require(randomnessJobs[id] == 0, "Randomness already posted"); | ||
|
||
randomnessJobs[id] = randomness; | ||
eraseEvent(randomnessId, uint16(EventType.RandomnessRequested)); | ||
} | ||
|
||
function getRandomness(uint256 id) external view returns (uint256) { | ||
uint256 storedRandomness = randomnessJobs[id]; | ||
require(storedRandomness != 0, "Randomness not posted"); | ||
return storedRandomness; | ||
} | ||
|
||
struct UnprocessedRandomness { | ||
uint64 randomnessId; | ||
} | ||
|
||
function decodeUnprocessedRandomness(bytes memory data) internal pure returns (UnprocessedRandomness memory) { | ||
uint64 id; | ||
(id) = abi.decode(data, (uint64)); | ||
return UnprocessedRandomness(id); | ||
} | ||
|
||
function getUnprocessedRandomness() external view returns (UnprocessedRandomness[] memory) { | ||
Event[] memory events = getEvents(uint16(EventType.RandomnessRequested)); | ||
UnprocessedRandomness[] memory res = new UnprocessedRandomness[](events.length); | ||
for (uint64 i = 0; i < events.length; i++) { | ||
res[i] = decodeUnprocessedRandomness(events[i].data); | ||
} | ||
return res; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"pages": { | ||
"/page": [ | ||
"static/chunks/webpack.js", | ||
"static/chunks/main-app.js", | ||
"static/css/app/page.css", | ||
"static/chunks/app/page.js" | ||
], | ||
"/layout": [ | ||
"static/chunks/webpack.js", | ||
"static/chunks/main-app.js", | ||
"static/css/app/layout.css", | ||
"static/chunks/app/layout.js" | ||
] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"polyfillFiles": [ | ||
"static/chunks/polyfills.js" | ||
], | ||
"devFiles": [ | ||
"static/chunks/react-refresh.js" | ||
], | ||
"ampDevFiles": [], | ||
"lowPriorityFiles": [ | ||
"static/development/_buildManifest.js", | ||
"static/development/_ssgManifest.js" | ||
], | ||
"rootMainFiles": [ | ||
"static/chunks/webpack.js", | ||
"static/chunks/main-app.js" | ||
], | ||
"pages": { | ||
"/_app": [ | ||
"static/chunks/webpack.js", | ||
"static/chunks/main.js", | ||
"static/chunks/pages/_app.js" | ||
], | ||
"/_error": [ | ||
"static/chunks/webpack.js", | ||
"static/chunks/main.js", | ||
"static/chunks/pages/_error.js" | ||
] | ||
}, | ||
"ampFirstPages": [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"encryption.key":"X/Lnb33sWqTRshY26L81USriUtm1tFoqhtjOEN/E4gA=","encryption.expire_at":1739299280451} |
Binary file added
BIN
+11.4 MB
lottery-agent/frontend/.next/cache/webpack/client-development-fallback/0.pack.gz
Binary file not shown.
Binary file added
BIN
+26.6 KB
lottery-agent/frontend/.next/cache/webpack/client-development-fallback/1.pack.gz
Binary file not shown.
Binary file added
BIN
+28.7 KB
lottery-agent/frontend/.next/cache/webpack/client-development-fallback/2.pack.gz
Binary file not shown.
Binary file added
BIN
+86.2 KB
lottery-agent/frontend/.next/cache/webpack/client-development-fallback/index.pack.gz
Binary file not shown.
Binary file added
BIN
+85.6 KB
lottery-agent/frontend/.next/cache/webpack/client-development-fallback/index.pack.gz.old
Binary file not shown.
Binary file added
BIN
+252 KB
lottery-agent/frontend/.next/cache/webpack/client-development/0.pack.gz
Binary file not shown.
Binary file added
BIN
+178 KB
lottery-agent/frontend/.next/cache/webpack/client-development/1.pack.gz
Binary file not shown.
Binary file added
BIN
+5.3 KB
lottery-agent/frontend/.next/cache/webpack/client-development/10.pack.gz
Binary file not shown.
Binary file added
BIN
+2.34 KB
lottery-agent/frontend/.next/cache/webpack/client-development/11.pack.gz
Binary file not shown.
Binary file added
BIN
+4.29 KB
lottery-agent/frontend/.next/cache/webpack/client-development/12.pack.gz
Binary file not shown.
Binary file added
BIN
+236 KB
lottery-agent/frontend/.next/cache/webpack/client-development/13.pack.gz
Binary file not shown.
Binary file added
BIN
+217 KB
lottery-agent/frontend/.next/cache/webpack/client-development/14.pack.gz
Binary file not shown.
Binary file added
BIN
+24.9 KB
lottery-agent/frontend/.next/cache/webpack/client-development/15.pack.gz
Binary file not shown.
Binary file added
BIN
+111 KB
lottery-agent/frontend/.next/cache/webpack/client-development/16.pack.gz
Binary file not shown.
Binary file added
BIN
+2.32 KB
lottery-agent/frontend/.next/cache/webpack/client-development/17.pack.gz
Binary file not shown.
Binary file added
BIN
+28.8 KB
lottery-agent/frontend/.next/cache/webpack/client-development/18.pack.gz
Binary file not shown.
Binary file added
BIN
+137 KB
lottery-agent/frontend/.next/cache/webpack/client-development/19.pack.gz
Binary file not shown.
Binary file added
BIN
+3.63 MB
lottery-agent/frontend/.next/cache/webpack/client-development/2.pack.gz
Binary file not shown.
Binary file added
BIN
+5.6 MB
lottery-agent/frontend/.next/cache/webpack/client-development/20.pack.gz
Binary file not shown.
Binary file added
BIN
+5.53 MB
lottery-agent/frontend/.next/cache/webpack/client-development/3.pack.gz
Binary file not shown.
Binary file added
BIN
+29.1 KB
lottery-agent/frontend/.next/cache/webpack/client-development/4.pack.gz
Binary file not shown.
Binary file added
BIN
+1.61 MB
lottery-agent/frontend/.next/cache/webpack/client-development/5.pack.gz
Binary file not shown.
Binary file added
BIN
+5.3 KB
lottery-agent/frontend/.next/cache/webpack/client-development/6.pack.gz
Binary file not shown.
Binary file added
BIN
+523 KB
lottery-agent/frontend/.next/cache/webpack/client-development/7.pack.gz
Binary file not shown.
Binary file added
BIN
+8.58 MB
lottery-agent/frontend/.next/cache/webpack/client-development/8.pack.gz
Binary file not shown.
Binary file added
BIN
+77.7 KB
lottery-agent/frontend/.next/cache/webpack/client-development/9.pack.gz
Binary file not shown.
Binary file added
BIN
+340 KB
lottery-agent/frontend/.next/cache/webpack/client-development/index.pack.gz
Binary file not shown.
Binary file added
BIN
+340 KB
lottery-agent/frontend/.next/cache/webpack/client-development/index.pack.gz.old
Binary file not shown.
Binary file added
BIN
+276 Bytes
lottery-agent/frontend/.next/cache/webpack/edge-server-production/0.pack
Binary file not shown.
Binary file added
BIN
+2.47 KB
lottery-agent/frontend/.next/cache/webpack/edge-server-production/index.pack
Binary file not shown.
Binary file added
BIN
+2.07 KB
lottery-agent/frontend/.next/cache/webpack/server-development/0.pack.gz
Binary file not shown.
Binary file added
BIN
+175 KB
lottery-agent/frontend/.next/cache/webpack/server-development/1.pack.gz
Binary file not shown.
Binary file added
BIN
+356 KB
lottery-agent/frontend/.next/cache/webpack/server-development/10.pack.gz
Binary file not shown.
Binary file added
BIN
+2 KB
lottery-agent/frontend/.next/cache/webpack/server-development/11.pack.gz
Binary file not shown.
Binary file added
BIN
+21.5 KB
lottery-agent/frontend/.next/cache/webpack/server-development/12.pack.gz
Binary file not shown.
Binary file added
BIN
+201 KB
lottery-agent/frontend/.next/cache/webpack/server-development/13.pack.gz
Binary file not shown.
Binary file added
BIN
+178 KB
lottery-agent/frontend/.next/cache/webpack/server-development/14.pack.gz
Binary file not shown.
Binary file added
BIN
+120 KB
lottery-agent/frontend/.next/cache/webpack/server-development/15.pack.gz
Binary file not shown.
Binary file added
BIN
+21.9 KB
lottery-agent/frontend/.next/cache/webpack/server-development/2.pack.gz
Binary file not shown.
Binary file added
BIN
+2.82 KB
lottery-agent/frontend/.next/cache/webpack/server-development/3.pack.gz
Binary file not shown.
Binary file added
BIN
+1.07 MB
lottery-agent/frontend/.next/cache/webpack/server-development/4.pack.gz
Binary file not shown.
Binary file added
BIN
+251 KB
lottery-agent/frontend/.next/cache/webpack/server-development/5.pack.gz
Binary file not shown.
Binary file added
BIN
+7.76 KB
lottery-agent/frontend/.next/cache/webpack/server-development/6.pack.gz
Binary file not shown.
Binary file added
BIN
+2.82 KB
lottery-agent/frontend/.next/cache/webpack/server-development/7.pack.gz
Binary file not shown.
Binary file added
BIN
+8.59 MB
lottery-agent/frontend/.next/cache/webpack/server-development/8.pack.gz
Binary file not shown.
Binary file added
BIN
+1.73 MB
lottery-agent/frontend/.next/cache/webpack/server-development/9.pack.gz
Binary file not shown.
Binary file added
BIN
+292 KB
lottery-agent/frontend/.next/cache/webpack/server-development/index.pack.gz
Binary file not shown.
Binary file added
BIN
+291 KB
lottery-agent/frontend/.next/cache/webpack/server-development/index.pack.gz.old
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+6.07 MB
lottery-agent/frontend/.next/cache/webpack/server-production/index.pack
Binary file not shown.
Oops, something went wrong.