forked from provable-things/ethereum-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oraclizeAPI.se
171 lines (139 loc) · 6.79 KB
/
oraclizeAPI.se
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
# <ORACLIZE_API>
# IMPORTANT NOTICE: THIS ORACLIZE_API VERSION IS DEPRECATED AND IS NOT ACTIVELY MAINTAINED ANYMORE
# THIS IS STAYING HERE FOR COMPATIBILITY/HISTORICAL REASONS WITH SERPENT
# PLEASE ALWAYS REFER TO THE LATEST ORACLIZE-API CODE FOR SOLIDITY:
# https://github.com/oraclize/ethereum-api/blob/master/oraclizeAPI.sol
# Copyright (c) 2015-2016 Oraclize SRL
# Copyright (c) 2016-2019 Oraclize LTD
# Copyright (c) 2019 Provable Things Limited
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
extern OraclizeAddrResolverI: [getAddress:[]:int256]
extern OraclizeI: [cbAddress:[]:int256,query:[uint256,string,string]:bytes32,query2:[uint256,string,string,string]:bytes32,query_withGasLimit:[uint256,string,string,uint256]:bytes32,query2_withGasLimit:[uint256,string,string,string,uint256]:bytes32,getPrice:[string,uint256]:uint256,useCoupon:[string]:_,setProofType:[bytes1]:_]
macro day: 60*60*24
macro week: 60*60*24*7
macro month: 60*60*24*30
macro proofType_NONE: 0x0000000000000000000000000000000000000000000000000000000000000000
macro proofType_TLSNotary: 0x1000000000000000000000000000000000000000000000000000000000000000
macro proofStorage_IPFS: 0x0100000000000000000000000000000000000000000000000000000000000000
macro networkID_mainnet: 1
macro networkID_testnet: 2
macro networkID_morden: 2
macro networkID_ropsten: 2
macro networkID_consensys: 161
macro networkID_auto: 0
data OAR
macro oraclize_setNetwork(networkID_auto):
if(~extcodesize(0x1d3b2638a7cc9f2cb3d298a3da7a90b67e5506ed)>0):
self.OAR = 0x1d3b2638a7cc9f2cb3d298a3da7a90b67e5506ed
elif(~extcodesize(0xc03a2615d5efaf5f49f60b7bb6583eaec212fdf1)>0):
self.OAR = 0xc03a2615d5efaf5f49f60b7bb6583eaec212fdf1
elif(~extcodesize(0x20e12a1f859b3feae5fb2a0a32c18f5a65555bbf)>0):
self.OAR = 0x20e12a1f859b3feae5fb2a0a32c18f5a65555bbf
macro oraclize_setNetwork(networkID_mainnet):
self.OAR = 0x1d3b2638a7cc9f2cb3d298a3da7a90b67e5506ed
macro oraclize_setNetwork(networkID_testnet):
self.OAR = 0xc03a2615d5efaf5f49f60b7bb6583eaec212fdf1
macro oraclize_setNetwork(networkID_consensys):
self.OAR = 0x20e12a1f859b3feae5fb2a0a32c18f5a65555bbf
macro oraclize_cbAddress():
self.OAR.getAddress().cbAddress()
macro oraclize_setProof($proofP):
oraclize = self.OAR.getAddress()
oraclize.setProofType($proofP)
macro oraclize_query($datasource, $arg):
oraclize = self.OAR.getAddress()
price = oraclize.getPrice($datasource,200000)
if (price > 10^18 + tx.gasprice*200000):
0 # unexpectedly high price
else:
oraclize.query(0, $datasource, $arg, value=price)
macro oraclize_query($timestamp, $datasource, $arg):
oraclize = self.OAR.getAddress()
if(len($timestamp)==0 && len($arg)>0):
price = oraclize.getPrice($datasource,200000)
if (price > 10^18 + tx.gasprice*200000):
0 # unexpectedly high price
else:
oraclize.query($timestamp, $datasource, $arg, value=price)
elif(len($timestamp)>0 && len($arg)==0):
# $timestamp is datasource
# $datasource is arg
# $arg is gasLimit
price = oraclize.getPrice($timestamp, $arg)
if (price > 10^18 + tx.gasprice*$arg):
0 # unexpectedly high price
else:
oraclize.query_withGasLimit(0, $timestamp, $datasource, $arg, value=price)
else:
# $timestamp is datasource
# $datasource is arg
# $arg is 2nd arg
price = oraclize.getPrice($timestamp,200000)
if (price > 10^18 + tx.gasprice*200000):
0 # unexpectedly high price
else:
oraclize.query2(0, $timestamp, $datasource, $arg, value=price)
macro oraclize_query($timestamp, $datasource, $arg, $gasLimit):
oraclize = self.OAR.getAddress()
if(len($timestamp)==0 && len($gasLimit)==0):
price = oraclize.getPrice($datasource, $gasLimit)
if (price > 10^18 + tx.gasprice*$gasLimit):
0 # unexpectedly high price
else:
oraclize.query_withGasLimit($timestamp, $datasource, $arg, $gasLimit, value=price)
elif(len($timestamp)>0 && len($gasLimit)==0):
# $timestamp is datasource
# $datasource is arg
# $arg is the 2nd arg
# $gasLimit is gasLimit
price = oraclize.getPrice($timestamp, $gasLimit)
if (price > 10^18 + tx.gasprice*$gasLimit):
0 # unexpectedly high price
else:
oraclize.query2_withGasLimit(0, $timestamp, $datasource, $arg, $gasLimit, value=price)
elif(len($gasLimit)>0 && len($timestamp)==0):
price = oraclize.getPrice($datasource,200000)
if (price > 10^18 + tx.gasprice*200000):
0 # unexpectedly high price
else:
# $timestamp is timestamp
# $datasource is datasource
# $arg is arg
# $gasLimit is 2nd arg
oraclize.query2($timestamp, $datasource, $arg, $gasLimit, value=price)
macro oraclize_query($timestamp, $datasource, $arg1, $arg2, $gasLimit):
oraclize = self.OAR.getAddress()
price = oraclize.getPrice($datasource, $gasLimit)
if (price > 10^18 + tx.gasprice*$gasLimit):
0 # unexpectedly high price
else:
oraclize.query2_withGasLimit($timestamp, $datasource, $arg1, $arg2, $gasLimit, value=price)
macro strConcat($a, $b, $c, $d, $e):
with $z = string(len($a) + len($b) + len($c) + len($d) + len($e)):
mcopy($z, $a, len($a))
mcopy($z + len($a), $b, len($b))
mcopy($z + len($a) + len($b), $c, len($c))
mcopy($z + len($a) + len($b) + len($c), $d, len($d))
mcopy($z + len($a) + len($b) + len($c) + len($d), $e, len($e))
$z
macro strConcat($a, $b, $c, $d):
strConcat($a, $b, $c, $d, text(""))
macro strConcat($a, $b, $c):
strConcat($a, $b, $c, text(""), text(""))
macro strConcat($a, $b):
strConcat($a, $b, text(""), text(""), text(""))
# </ORACLIZE_API>