forked from mikedeshazer/OrFeed
-
Notifications
You must be signed in to change notification settings - Fork 152
/
Copy pathdataAndEventOracleRegistry.sol
190 lines (128 loc) · 5.26 KB
/
dataAndEventOracleRegistry.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
//oracle for event and data registry
//Example: https://etherscan.io/address/0xd754f58d9d6d705b98bde698f9f9cec0bded1b8a#readContract
pragma experimental ABIEncoderV2;
interface DataOracleInterface{
function getResultFromOracle (string theEvent) returns (string);
}
// oracle registery main
contract oracleForDataRegistry {
mapping (string=>address) oracleMapping;
mapping (string=>address) oracleOwners;
mapping (string=>string) oracleOwnersInfo;
string [] oracleNamesArr;
address [] oracleOwnersArr;
string [] oracleOwnersInfoArr;
uint256 purchaseFee;
address owner;
modifier onlyOwner() {
if (msg.sender != owner) {
throw;
}
_;
}
constructor() public payable {
owner = msg.sender;
//default .001
purchaseFee = 1000000000000000;
}
function getEventResult(string selectedEventOrData, string selectedOracle) public constant returns (string){
selectedOracle = toLower(selectedOracle);
address oracleAddress = getOracleAddress(selectedOracle);
if (oracleAddress <= 0){
//The requested provider is not registered in this oracle registry
return "";
}
DataOracleInterface p = DataOracleInterface(oracleAddress);
return p.getResultFromOracle(selectedEventOrData);
}
function changeOwner(address newOwner) onlyOwner returns(bool){
owner = newOwner;
return true;
}
function changeFee(uint256 newFee) onlyOwner returns(bool){
purchaseFee = newFee;
return true;
}
function withdrawBalance() onlyOwner returns(bool) {
uint amount = this.balance;
msg.sender.transfer(amount);
return true;
}
function registerOracle(string name, address requestedAddress, string info ) payable returns (bool){
require(msg.value >= purchaseFee, "Please send .05 ETH to register an oracle. This is to prevent registration spam");
name = toLower(name);
if(oracleMapping[name] > 1){
//you cant update/re-register an address
throw;
}
if(oracleMapping[name] != 0x0 && oracleOwners[name] != msg.sender){
//you cant update this because you did not register this name
throw;
}
string memory theDetails = info;
oracleMapping[name] = requestedAddress;
oracleOwners[name] = msg.sender;
oracleOwnersInfo[name] = theDetails;
oracleNamesArr.push(name);
oracleOwnersArr.push(msg.sender);
oracleOwnersInfoArr.push(theDetails);
return true;
}
function transferOracleName(string name, address toAddress) returns(bool){
if(oracleMapping[name] != 0x0 && oracleOwners[name] != msg.sender){
//you cant transfer this because you did not register this name
throw;
}
oracleOwners[name] = toAddress;
return true;
}
function editOracleInfo(string name, string info) payable returns (bool){
name = toLower(name);
if(oracleMapping[name] != 0x0 && oracleOwners[name] != msg.sender){
//you cant update this because you did not register this name
throw;
}
string memory theDetails = info;
oracleOwnersInfo[name] = theDetails;
return true;
}
function editOracleAddress(string name, address newOrSameOracleAddress) payable returns (bool){
name = toLower(name);
if(oracleMapping[name] != 0x0 && oracleOwners[name] != msg.sender){
//you cant update this because you did not register this name
throw;
}
oracleMapping[name] = newOrSameOracleAddress;
return true;
}
function getAllOracles() constant returns (string []){
return oracleNamesArr;
}
function getPurchaseFee() constant returns (uint256){
return purchaseFee;
}
function getOracleAddress(string nameReference) constant returns (address){
nameReference = toLower(nameReference);
return oracleMapping[nameReference];
}
function getOracleOwner(string nameReference) constant returns (address){
nameReference = toLower(nameReference);
return oracleOwners[nameReference];
}
function getOracleInfo(string nameReference) constant returns (string){
nameReference = toLower(nameReference);
return oracleOwnersInfo[nameReference];
}
function toLower(string str) internal returns (string) {
bytes memory bStr = bytes(str);
bytes memory bLower = new bytes(bStr.length);
for (uint i = 0; i < bStr.length; i++) {
if ((bStr[i] >= 65) && (bStr[i] <= 90)) {
bLower[i] = bytes1(int(bStr[i]) + 32);
} else {
bLower[i] = bStr[i];
}
}
return string(bLower);
}
}