4 | | - | func a (b,c) = if ((1 > size(b))) |
---|
5 | | - | then throw("decode u8 error, data must be at least 1 byte") |
---|
6 | | - | else if ((c > size(b))) |
---|
7 | | - | then throw("decode u8 error, decoding is finish") |
---|
8 | | - | else { |
---|
9 | | - | let d = take(drop(b, c), 1) |
---|
10 | | - | let e = toInt((base58'1111111' + d), 0) |
---|
11 | | - | [toInt((base58'1111111' + d), 0), (c + 1)] |
---|
| 4 | + | func a () = { |
---|
| 5 | + | let b = addressFromString("3N54eKW5ZucDaRaGVUfzX8xRXv6Ve8M71tM") |
---|
| 6 | + | if ($isInstanceOf(b, "Address")) |
---|
| 7 | + | then { |
---|
| 8 | + | let c = b |
---|
| 9 | + | c |
---|
13 | | - | |
---|
14 | | - | |
---|
15 | | - | func f (b,c) = if ((2 > size(b))) |
---|
16 | | - | then throw("decode u16 error, data must be at least 2 bytes") |
---|
17 | | - | else if ((c > size(b))) |
---|
18 | | - | then throw("decode u16 error, decoding is finish") |
---|
19 | | - | else { |
---|
20 | | - | let d = drop(b, c) |
---|
21 | | - | let e = take(d, 2) |
---|
22 | | - | [toInt((base58'111111' + e), 0), (c + 2)] |
---|
23 | | - | } |
---|
24 | | - | |
---|
25 | | - | |
---|
26 | | - | func g (b,c) = if ((4 > size(b))) |
---|
27 | | - | then throw("decode u32 error, data must be at least 4 bytes") |
---|
28 | | - | else if ((c > size(b))) |
---|
29 | | - | then throw("decode u32 error, decoding is finish") |
---|
30 | | - | else { |
---|
31 | | - | let d = drop(b, c) |
---|
32 | | - | let e = take(d, 4) |
---|
33 | | - | [toInt((base58'1111' + e), 0), (c + 4)] |
---|
34 | | - | } |
---|
35 | | - | |
---|
36 | | - | |
---|
37 | | - | func h (b,c) = if ((8 > size(b))) |
---|
38 | | - | then throw("decode u32 error, data must be at least 8 bytes") |
---|
39 | | - | else if ((c > size(b))) |
---|
40 | | - | then throw("decode u32 error, decoding is finish") |
---|
41 | | - | else { |
---|
42 | | - | let d = drop(b, c) |
---|
43 | | - | let e = take(d, 8) |
---|
44 | | - | [toInt(e, 0), (c + 8)] |
---|
45 | | - | } |
---|
46 | | - | |
---|
47 | | - | |
---|
48 | | - | func i (b,c) = { |
---|
49 | | - | let j = a(b, c) |
---|
50 | | - | [DataEntry("bool", (j[0] != 0)), DataEntry("int", j[1])] |
---|
| 11 | + | else throw("fail to get bridge address") |
---|
54 | | - | func k (b,c) = if ((32 > size(b))) |
---|
55 | | - | then throw("decode bytes32 error, data must be at least 32 bytes") |
---|
56 | | - | else [DataEntry("byte_vector", take(drop(b, c), 32)), DataEntry("int", (c + 32))] |
---|
57 | | - | |
---|
58 | | - | |
---|
59 | | - | func l (b,c) = if ((64 > size(b))) |
---|
60 | | - | then throw("decode bytes64 error, data must be at least 64 bytes") |
---|
61 | | - | else [DataEntry("byte_vector", take(drop(b, c), 64)), DataEntry("int", (c + 64))] |
---|
62 | | - | |
---|
63 | | - | |
---|
64 | | - | func m (b,c) = if ((65 > size(b))) |
---|
65 | | - | then throw("decode bytes65 error, data must be at least 65 bytes") |
---|
66 | | - | else [DataEntry("byte_vector", take(drop(b, c), 65)), DataEntry("int", (c + 65))] |
---|
67 | | - | |
---|
68 | | - | |
---|
69 | | - | func n (b,c) = { |
---|
70 | | - | let j = g(b, c) |
---|
71 | | - | let o = j[0] |
---|
72 | | - | let p = j[1] |
---|
73 | | - | [DataEntry("byte_vector", take(drop(b, p), o)), DataEntry("int", (p + o))] |
---|
74 | | - | } |
---|
75 | | - | |
---|
76 | | - | |
---|
77 | | - | func q (b,c) = { |
---|
78 | | - | let j = g(b, c) |
---|
79 | | - | let o = j[0] |
---|
80 | | - | let p = j[1] |
---|
81 | | - | [DataEntry("string", toUtf8String(take(drop(b, p), o))), DataEntry("int", (p + o))] |
---|
82 | | - | } |
---|
83 | | - | |
---|
84 | | - | |
---|
85 | | - | func r (s) = { |
---|
86 | | - | let t = s[0].value |
---|
87 | | - | if ($isInstanceOf(t, "Boolean")) |
---|
88 | | - | then { |
---|
89 | | - | let u = t |
---|
90 | | - | u |
---|
91 | | - | } |
---|
92 | | - | else throw("not a Boolean") |
---|
93 | | - | } |
---|
94 | | - | |
---|
95 | | - | |
---|
96 | | - | func v (s) = { |
---|
97 | | - | let t = s[0].value |
---|
98 | | - | if ($isInstanceOf(t, "ByteVector")) |
---|
99 | | - | then { |
---|
100 | | - | let w = t |
---|
101 | | - | w |
---|
102 | | - | } |
---|
103 | | - | else throw("not a ByteVector") |
---|
104 | | - | } |
---|
105 | | - | |
---|
106 | | - | |
---|
107 | | - | func x (s) = { |
---|
108 | | - | let t = s[0].value |
---|
109 | | - | if ($isInstanceOf(t, "String")) |
---|
110 | | - | then { |
---|
111 | | - | let y = t |
---|
112 | | - | y |
---|
113 | | - | } |
---|
114 | | - | else throw("not a String") |
---|
115 | | - | } |
---|
116 | | - | |
---|
117 | | - | |
---|
118 | | - | func z (s) = { |
---|
119 | | - | let t = s[1].value |
---|
120 | | - | if ($isInstanceOf(t, "Int")) |
---|
121 | | - | then { |
---|
122 | | - | let A = t |
---|
123 | | - | A |
---|
124 | | - | } |
---|
125 | | - | else throw("not a Int") |
---|
126 | | - | } |
---|
127 | | - | |
---|
128 | | - | |
---|
129 | | - | func B (C) = { |
---|
130 | | - | let t = getInteger(this, (C + "/latest_update")) |
---|
131 | | - | if ($isInstanceOf(t, "Int")) |
---|
132 | | - | then { |
---|
133 | | - | let A = t |
---|
134 | | - | A |
---|
135 | | - | } |
---|
136 | | - | else 0 |
---|
137 | | - | } |
---|
138 | | - | |
---|
139 | | - | |
---|
140 | | - | @Callable(D) |
---|
141 | | - | func relayAndVerify (b) = if ((D.caller != this)) |
---|
142 | | - | then throw("Unauthorized caller") |
---|
| 15 | + | @Callable(d) |
---|
| 16 | + | func readFromBridge (e) = if (if (if ((e != "BTC")) |
---|
| 17 | + | then (e != "WAVES") |
---|
| 18 | + | else false) |
---|
| 19 | + | then (e != "ETH") |
---|
| 20 | + | else false) |
---|
| 21 | + | then throw("Invalid symbol") |
---|
144 | | - | let E = q(b, 0) |
---|
145 | | - | let F = h(b, z(E)) |
---|
146 | | - | let G = n(b, F[1]) |
---|
147 | | - | let H = h(b, z(G)) |
---|
148 | | - | let I = h(b, H[1]) |
---|
149 | | - | let J = q(b, I[1]) |
---|
150 | | - | let K = h(b, z(J)) |
---|
151 | | - | let L = h(b, K[1]) |
---|
152 | | - | let M = h(b, L[1]) |
---|
153 | | - | let N = h(b, M[1]) |
---|
154 | | - | let O = a(b, N[1]) |
---|
155 | | - | let P = n(b, O[1]) |
---|
156 | | - | let Q = v(G) |
---|
157 | | - | let R = q(Q, 0) |
---|
158 | | - | let S = h(Q, z(R)) |
---|
159 | | - | let C = x(R) |
---|
160 | | - | let T = S[0] |
---|
161 | | - | if ((F[0] != 1)) |
---|
162 | | - | then throw("Invalid oracle script") |
---|
163 | | - | else if (if (if ((C != "BTC")) |
---|
164 | | - | then (C != "WAVES") |
---|
165 | | - | else false) |
---|
166 | | - | then (C != "ETH") |
---|
167 | | - | else false) |
---|
168 | | - | then throw("Invalid symbol") |
---|
169 | | - | else if ((T != 1000000)) |
---|
170 | | - | then throw("Invalid multiplier") |
---|
171 | | - | else if ((B(C) >= N[0])) |
---|
172 | | - | then throw("Not newer than the latest") |
---|
173 | | - | else if ((O[0] != 1)) |
---|
174 | | - | then throw("Invalid resolve status") |
---|
175 | | - | else { |
---|
176 | | - | let U = v(P) |
---|
177 | | - | let V = h(U, 0) |
---|
178 | | - | WriteSet([DataEntry((C + "/latest_update_time"), N[0]), DataEntry((C + "/value"), V[0]), DataEntry((C + "/latest_block"), height)]) |
---|
179 | | - | } |
---|
| 23 | + | let f = getIntegerValue(a(), (e + "/value")) |
---|
| 24 | + | WriteSet([DataEntry((e + "/price"), f)]) |
---|