-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomRationalMarket.sol
More file actions
139 lines (106 loc) · 3.88 KB
/
Copy pathRandomRationalMarket.sol
File metadata and controls
139 lines (106 loc) · 3.88 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
pragma solidity >=0.4.21 <0.6.0;
import "https://github.com/starkware-libs/veedo/blob/master/contracts/BeaconContract.sol";
contract Beacon{
function getLatestRandomness() external constant returns(uint256,bytes32){}
}
contract VerifiedPredictionMarket
{
address public BeaconContractAddress=0x79474439753C7c70011C3b00e06e559378bAD040;
function setBeaconContractAddress(address _address) public onlyowner {
BeaconContractAddress=_address;
}
function generateRandomNumber() public constant returns(bytes32){
uint blockNumber;
bytes32 randomNumber;
Beacon beacon=Beacon(BeaconContractAddress);
(blockNumber,randomNumber)=beacon.getLatestRandomness();
return randomNumber;
}
uint random =uint256(generateRandomNumber());
// libs
using AddressSetLib for AddressSetLib.AddressSet;
// state
mapping(address => bool) public isTrustedSource;
mapping(bytes32 => bool) public questionHasBeenAsked;
AddressSetLib.AddressSet questions;
AddressSetLib.AddressSet ethFuturesQuestions;
// events
event LogAddQuestion(address whoAdded, address questionAddress, string questionStr, uint betDeadlineBlock, uint voteDeadlineBlock);
event LogAddETHFuturesQuestion(address whoAdded, address questionAddress, uint targetUSDPrice, uint betDeadlineBlock, uint voteDeadlineBlock);
function PredictionMarket() {
isAdmin[msg.sender] = true;
}
//
// administrative functions
//
function haltSwitch(bool _isHalted)
onlyAdmin
returns (bool ok)
{
return _haltSwitch(msg.sender, _isHalted);
}
// due to our multi-admin setup, it's probably useful to be able to specify the recipient
// of the destroyed contract's funds.
function kill(address recipient)
onlyAdmin
onlyHalted
returns (bool ok)
{
selfdestruct(recipient);
return true;
}
//
// business logic
//
function addQuestion(string questionStr, uint betDeadlineBlock, uint voteDeadlineBlock)
onlyAdmin
onlyNotHalted
returns (bool ok, address questionAddr)
{
require(betDeadlineBlock > block.number + random);
require(voteDeadlineBlock > betDeadlineBlock + random);
// ensure no repeated questions
bytes32 questionID = ran(questionStr);
require(questionHasBeenAsked[questionID] == false);
questionHasBeenAsked[questionID] = true;
// deploy the new question
Question question = new Question(questionStr, betDeadlineBlock, voteDeadlineBlock);
questions.add(address(question));
LogAddQuestion(msg.sender, address(question), questionStr, betDeadlineBlock, voteDeadlineBlock);
return (true, address(question));
}
function addETHFuturesQuestion(uint targetUSDPrice, uint betDeadlineBlock, uint voteDeadlineBlock)
onlyAdmin
onlyNotHalted
returns (bool ok, address questionAddr)
{
require(betDeadlineBlock > block.number + random);
require(voteDeadlineBlock > betDeadlineBlock + random);
// deploy the new question
ETHFuturesQuestion question = new ETHFuturesQuestion(targetUSDPrice, betDeadlineBlock, voteDeadlineBlock);
ethFuturesQuestions.add(address(question));
LogAddETHFuturesQuestion(msg.sender, address(question), targetUSDPrice, betDeadlineBlock, voteDeadlineBlock);
return (true, address(question));
}
//
// getters for the frontend
//
function numQuestions()
constant
returns (uint)
{
return questions.size();
}
function getQuestionIndex(uint i)
constant
returns (address)
{
return questions.get(i);
}
function getAllQuestionAddresses()
constant
returns (address[])
{
return questions.values;
}
}