4 | | - | func decodeInt8 (data,offset) = if ((1 > size(data))) |
---|
5 | | - | then throw("decode u8 error, data must be at least 1 byte") |
---|
6 | | - | else if ((offset > size(data))) |
---|
7 | | - | then throw("decode u8 error, decoding is finish") |
---|
8 | | - | else { |
---|
9 | | - | let x0 = take(drop(data, offset), 1) |
---|
10 | | - | let x1 = toInt((base58'1111111' + x0), 0) |
---|
11 | | - | [toInt((base58'1111111' + x0), 0), (offset + 1)] |
---|
12 | | - | } |
---|
13 | | - | |
---|
14 | | - | |
---|
15 | | - | func decodeInt16 (data,offset) = if ((2 > size(data))) |
---|
16 | | - | then throw("decode u16 error, data must be at least 2 bytes") |
---|
17 | | - | else if ((offset > size(data))) |
---|
18 | | - | then throw("decode u16 error, decoding is finish") |
---|
19 | | - | else { |
---|
20 | | - | let x0 = drop(data, offset) |
---|
21 | | - | let x1 = take(x0, 2) |
---|
22 | | - | [toInt((base58'111111' + x1), 0), (offset + 2)] |
---|
23 | | - | } |
---|
24 | | - | |
---|
25 | | - | |
---|
26 | | - | func decodeInt32 (data,offset) = if ((4 > size(data))) |
---|
27 | | - | then throw("decode u32 error, data must be at least 4 bytes") |
---|
28 | | - | else if ((offset > size(data))) |
---|
29 | | - | then throw("decode u32 error, decoding is finish") |
---|
30 | | - | else { |
---|
31 | | - | let x0 = drop(data, offset) |
---|
32 | | - | let x1 = take(x0, 4) |
---|
33 | | - | [toInt((base58'1111' + x1), 0), (offset + 4)] |
---|
34 | | - | } |
---|
35 | | - | |
---|
36 | | - | |
---|
37 | | - | func decodeInt64 (data,offset) = if ((8 > size(data))) |
---|
38 | | - | then throw("decode u32 error, data must be at least 8 bytes") |
---|
39 | | - | else if ((offset > size(data))) |
---|
40 | | - | then throw("decode u32 error, decoding is finish") |
---|
41 | | - | else { |
---|
42 | | - | let x0 = drop(data, offset) |
---|
43 | | - | let x1 = take(x0, 8) |
---|
44 | | - | [toInt(x1, 0), (offset + 8)] |
---|
45 | | - | } |
---|
46 | | - | |
---|
47 | | - | |
---|
48 | | - | func decodeBool (data,offset) = { |
---|
49 | | - | let decoded1 = decodeInt8(data, offset) |
---|
50 | | - | [DataEntry("bool", (decoded1[0] != 0)), DataEntry("int", decoded1[1])] |
---|
51 | | - | } |
---|
52 | | - | |
---|
53 | | - | |
---|
54 | | - | func decodeBytes32 (data,offset) = if ((32 > size(data))) |
---|
55 | | - | then throw("decode bytes32 error, data must be at least 32 bytes") |
---|
56 | | - | else [DataEntry("byte_vector", take(drop(data, offset), 32)), DataEntry("int", (offset + 32))] |
---|
57 | | - | |
---|
58 | | - | |
---|
59 | | - | func decodeBytes64 (data,offset) = if ((64 > size(data))) |
---|
60 | | - | then throw("decode bytes64 error, data must be at least 64 bytes") |
---|
61 | | - | else [DataEntry("byte_vector", take(drop(data, offset), 64)), DataEntry("int", (offset + 64))] |
---|
62 | | - | |
---|
63 | | - | |
---|
64 | | - | func decodeBytes65 (data,offset) = if ((65 > size(data))) |
---|
65 | | - | then throw("decode bytes65 error, data must be at least 65 bytes") |
---|
66 | | - | else [DataEntry("byte_vector", take(drop(data, offset), 65)), DataEntry("int", (offset + 65))] |
---|
67 | | - | |
---|
68 | | - | |
---|
69 | | - | func decodeBytes (data,offset) = { |
---|
70 | | - | let decoded1 = decodeInt32(data, offset) |
---|
71 | | - | let bytesSize = decoded1[0] |
---|
72 | | - | let nextOffset = decoded1[1] |
---|
73 | | - | [DataEntry("byte_vector", take(drop(data, nextOffset), bytesSize)), DataEntry("int", (nextOffset + bytesSize))] |
---|
74 | | - | } |
---|
75 | | - | |
---|
76 | | - | |
---|
77 | | - | func decodeString (data,offset) = { |
---|
78 | | - | let decoded1 = decodeInt32(data, offset) |
---|
79 | | - | let bytesSize = decoded1[0] |
---|
80 | | - | let nextOffset = decoded1[1] |
---|
81 | | - | [DataEntry("string", toUtf8String(take(drop(data, nextOffset), bytesSize))), DataEntry("int", (nextOffset + bytesSize))] |
---|
82 | | - | } |
---|
83 | | - | |
---|
84 | | - | |
---|
85 | | - | func getAsBool (tuple) = match tuple[0].value { |
---|
86 | | - | case b: Boolean => |
---|
87 | | - | b |
---|
| 4 | + | func getBridgeAddress () = match addressFromString("3N54eKW5ZucDaRaGVUfzX8xRXv6Ve8M71tM") { |
---|
| 5 | + | case a: Address => |
---|
| 6 | + | a |
---|
129 | | - | let req1 = decodeString(data, 0) |
---|
130 | | - | let req2 = decodeInt64(data, getOffset(req1)) |
---|
131 | | - | let req3 = decodeBytes(data, req2[1]) |
---|
132 | | - | let req4 = decodeInt64(data, getOffset(req3)) |
---|
133 | | - | let req5 = decodeInt64(data, req4[1]) |
---|
134 | | - | let res1 = decodeString(data, req5[1]) |
---|
135 | | - | let res2 = decodeInt64(data, getOffset(res1)) |
---|
136 | | - | let res3 = decodeInt64(data, res2[1]) |
---|
137 | | - | let res4 = decodeInt64(data, res3[1]) |
---|
138 | | - | let res5 = decodeInt64(data, res4[1]) |
---|
139 | | - | let res6 = decodeInt8(data, res5[1]) |
---|
140 | | - | let res7 = decodeBytes(data, res6[1]) |
---|
141 | | - | let calldata = getAsByteVector(req3) |
---|
142 | | - | let c1 = decodeString(calldata, 0) |
---|
143 | | - | let c2 = decodeInt64(calldata, getOffset(c1)) |
---|
144 | | - | let symbol = getAsString(c1) |
---|
145 | | - | let multiplier = c2[0] |
---|
146 | | - | if ((req2[0] != 1)) |
---|
147 | | - | then throw("Invalid oracle script") |
---|
148 | | - | else if (if (if ((symbol != "BTC")) |
---|
149 | | - | then (symbol != "WAVES") |
---|
150 | | - | else false) |
---|
151 | | - | then (symbol != "ETH") |
---|
152 | | - | else false) |
---|
153 | | - | then throw("Invalid symbol") |
---|
154 | | - | else if ((multiplier != 1000000)) |
---|
155 | | - | then throw("Invalid multiplier") |
---|
156 | | - | else if ((getLatestUpdateTimeOfSymbol(symbol) >= res5[0])) |
---|
157 | | - | then throw("Not newer than the latest") |
---|
158 | | - | else if ((res6[0] != 1)) |
---|
159 | | - | then throw("Invalid resolve status") |
---|
160 | | - | else { |
---|
161 | | - | let response = getAsByteVector(res7) |
---|
162 | | - | let price = decodeInt64(response, 0) |
---|
163 | | - | WriteSet([DataEntry((symbol + "/latest_update_time"), res5[0]), DataEntry((symbol + "/value"), price[0]), DataEntry((symbol + "/latest_block"), height)]) |
---|
164 | | - | } |
---|
| 20 | + | let price = getIntegerValue(getBridgeAddress(), (symbol + "/value")) |
---|
| 21 | + | WriteSet([DataEntry((symbol + "/price"), price)]) |
---|