/
RandomOrg.sol
42 lines (34 loc) · 1.05 KB
/
RandomOrg.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
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.13;
import "@qourier/contracts/Hub.sol";
contract RandomOrg {
address public hub;
uint256 public price;
uint256 private id;
uint256 private result;
constructor(address hub_, uint256 price_) {
hub = hub_;
price = price_;
}
function createTask() public payable {
Hub(hub).createTask0{ value: price }(bytes32("random-org"));
}
function completeTask(uint256 id_, bytes memory result_) external {
require(msg.sender == hub, "Only Qourier can change the state.");
id = id_;
result = bytesToUint(result_);
}
function getTask() public view returns(uint256, uint256) {
return (id, result);
}
function bytesToUint(bytes memory b) public pure returns (uint256) {
uint256 res = 0;
for (uint256 i = 0; i < b.length; i++) {
uint256 c = uint256(uint8(b[i]));
if (c >= 48 && c <= 57) {
res = res * 10 + (c - 48);
}
}
return res;
}
}