/ contracts / src / oraclize / oraclizeAPI_0.4.sol
oraclizeAPI_0.4.sol
  1  // <ORACLIZE_API>
  2  /*
  3  Copyright (c) 2015-2016 Oraclize SRL
  4  Copyright (c) 2016 Oraclize LTD
  5  
  6  
  7  
  8  Permission is hereby granted, free of charge, to any person obtaining a copy
  9  of this software and associated documentation files (the "Software"), to deal
 10  in the Software without restriction, including without limitation the rights
 11  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 12  copies of the Software, and to permit persons to whom the Software is
 13  furnished to do so, subject to the following conditions:
 14  
 15  
 16  
 17  The above copyright notice and this permission notice shall be included in
 18  all copies or substantial portions of the Software.
 19  
 20  
 21  
 22  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 23  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 24  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
 25  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 26  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 27  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 28  THE SOFTWARE.
 29  */
 30  
 31  pragma solidity ^0.4.0;//please import oraclizeAPI_pre0.4.sol when solidity < 0.4.0
 32  
 33  contract OraclizeI {
 34      address public cbAddress;
 35      function query(uint _timestamp, string _datasource, string _arg) payable returns (bytes32 _id);
 36      function query_withGasLimit(uint _timestamp, string _datasource, string _arg, uint _gaslimit) payable returns (bytes32 _id);
 37      function query2(uint _timestamp, string _datasource, string _arg1, string _arg2) payable returns (bytes32 _id);
 38      function query2_withGasLimit(uint _timestamp, string _datasource, string _arg1, string _arg2, uint _gaslimit) payable returns (bytes32 _id);
 39      function queryN(uint _timestamp, string _datasource, bytes _argN) payable returns (bytes32 _id);
 40      function queryN_withGasLimit(uint _timestamp, string _datasource, bytes _argN, uint _gaslimit) payable returns (bytes32 _id);
 41      function getPrice(string _datasource) returns (uint _dsprice);
 42      function getPrice(string _datasource, uint gaslimit) returns (uint _dsprice);
 43      function useCoupon(string _coupon);
 44      function setProofType(byte _proofType);
 45      function setConfig(bytes32 _config);
 46      function setCustomGasPrice(uint _gasPrice);
 47  }
 48  contract OraclizeAddrResolverI {
 49      function getAddress() returns (address _addr);
 50  }
 51  contract usingOraclize {
 52      uint constant day = 60*60*24;
 53      uint constant week = 60*60*24*7;
 54      uint constant month = 60*60*24*30;
 55      byte constant proofType_NONE = 0x00;
 56      byte constant proofType_TLSNotary = 0x10;
 57      byte constant proofStorage_IPFS = 0x01;
 58      uint8 constant networkID_auto = 0;
 59      uint8 constant networkID_mainnet = 1;
 60      uint8 constant networkID_testnet = 2;
 61      uint8 constant networkID_morden = 2;
 62      uint8 constant networkID_consensys = 161;
 63  
 64      OraclizeAddrResolverI OAR;
 65  
 66      OraclizeI oraclize;
 67      modifier oraclizeAPI {
 68          if((address(OAR)==0)||(getCodeSize(address(OAR))==0)) oraclize_setNetwork(networkID_auto);
 69          oraclize = OraclizeI(OAR.getAddress());
 70          _;
 71      }
 72      modifier coupon(string code){
 73          oraclize = OraclizeI(OAR.getAddress());
 74          oraclize.useCoupon(code);
 75          _;
 76      }
 77  
 78      function oraclize_setNetwork(uint8 networkID) internal returns(bool){
 79          if (getCodeSize(0x1d3B2638a7cC9f2CB3D298A3DA7a90B67E5506ed)>0){ //mainnet
 80              OAR = OraclizeAddrResolverI(0x1d3B2638a7cC9f2CB3D298A3DA7a90B67E5506ed);
 81              return true;
 82          }
 83          if (getCodeSize(0xc03A2615D5efaf5F49F60B7BB6583eaec212fdf1)>0){ //ropsten testnet
 84              OAR = OraclizeAddrResolverI(0xc03A2615D5efaf5F49F60B7BB6583eaec212fdf1);
 85              return true;
 86          }
 87          if (getCodeSize(0xB7A07BcF2Ba2f2703b24C0691b5278999C59AC7e)>0){ //kovan testnet
 88              OAR = OraclizeAddrResolverI(0xB7A07BcF2Ba2f2703b24C0691b5278999C59AC7e);
 89              return true;
 90          }
 91          if (getCodeSize(0x6f485C8BF6fc43eA212E93BBF8ce046C7f1cb475)>0){ //ethereum-bridge
 92              OAR = OraclizeAddrResolverI(0x6f485C8BF6fc43eA212E93BBF8ce046C7f1cb475);
 93              return true;
 94          }
 95          if (getCodeSize(0x20e12A1F859B3FeaE5Fb2A0A32C18F5a65555bBF)>0){ //ether.camp ide
 96              OAR = OraclizeAddrResolverI(0x20e12A1F859B3FeaE5Fb2A0A32C18F5a65555bBF);
 97              return true;
 98          }
 99          if (getCodeSize(0x51efaF4c8B3C9AfBD5aB9F4bbC82784Ab6ef8fAA)>0){ //browser-solidity
100              OAR = OraclizeAddrResolverI(0x51efaF4c8B3C9AfBD5aB9F4bbC82784Ab6ef8fAA);
101              return true;
102          }
103          return false;
104      }
105  
106      function __callback(bytes32 myid, string result) {
107          __callback(myid, result, new bytes(0));
108      }
109      function __callback(bytes32 myid, string result, bytes proof) {
110      }
111  
112      function oraclize_getPrice(string datasource) oraclizeAPI internal returns (uint){
113          return oraclize.getPrice(datasource);
114      }
115  
116      function oraclize_getPrice(string datasource, uint gaslimit) oraclizeAPI internal returns (uint){
117          return oraclize.getPrice(datasource, gaslimit);
118      }
119      
120      function oraclize_query(string datasource, string arg) oraclizeAPI internal returns (bytes32 id){
121          uint price = oraclize.getPrice(datasource);
122          if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price
123          return oraclize.query.value(price)(0, datasource, arg);
124      }
125      function oraclize_query(uint timestamp, string datasource, string arg) oraclizeAPI internal returns (bytes32 id){
126          uint price = oraclize.getPrice(datasource);
127          if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price
128          return oraclize.query.value(price)(timestamp, datasource, arg);
129      }
130      function oraclize_query(uint timestamp, string datasource, string arg, uint gaslimit) oraclizeAPI internal returns (bytes32 id){
131          uint price = oraclize.getPrice(datasource, gaslimit);
132          if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price
133          return oraclize.query_withGasLimit.value(price)(timestamp, datasource, arg, gaslimit);
134      }
135      function oraclize_query(string datasource, string arg, uint gaslimit) oraclizeAPI internal returns (bytes32 id){
136          uint price = oraclize.getPrice(datasource, gaslimit);
137          if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price
138          return oraclize.query_withGasLimit.value(price)(0, datasource, arg, gaslimit);
139      }
140      function oraclize_query(string datasource, string arg1, string arg2) oraclizeAPI internal returns (bytes32 id){
141          uint price = oraclize.getPrice(datasource);
142          if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price
143          return oraclize.query2.value(price)(0, datasource, arg1, arg2);
144      }
145      function oraclize_query(uint timestamp, string datasource, string arg1, string arg2) oraclizeAPI internal returns (bytes32 id){
146          uint price = oraclize.getPrice(datasource);
147          if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price
148          return oraclize.query2.value(price)(timestamp, datasource, arg1, arg2);
149      }
150      function oraclize_query(uint timestamp, string datasource, string arg1, string arg2, uint gaslimit) oraclizeAPI internal returns (bytes32 id){
151          uint price = oraclize.getPrice(datasource, gaslimit);
152          if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price
153          return oraclize.query2_withGasLimit.value(price)(timestamp, datasource, arg1, arg2, gaslimit);
154      }
155      function oraclize_query(string datasource, string arg1, string arg2, uint gaslimit) oraclizeAPI internal returns (bytes32 id){
156          uint price = oraclize.getPrice(datasource, gaslimit);
157          if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price
158          return oraclize.query2_withGasLimit.value(price)(0, datasource, arg1, arg2, gaslimit);
159      }
160      function oraclize_query(string datasource, string[] argN) oraclizeAPI internal returns (bytes32 id){
161          uint price = oraclize.getPrice(datasource);
162          if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price
163          bytes memory args = stra2cbor(argN);
164          return oraclize.queryN.value(price)(0, datasource, args);
165      }
166      function oraclize_query(uint timestamp, string datasource, string[] argN) oraclizeAPI internal returns (bytes32 id){
167          uint price = oraclize.getPrice(datasource);
168          if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price
169          bytes memory args = stra2cbor(argN);
170          return oraclize.queryN.value(price)(timestamp, datasource, args);
171      }
172      function oraclize_query(uint timestamp, string datasource, string[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){
173          uint price = oraclize.getPrice(datasource, gaslimit);
174          if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price
175          bytes memory args = stra2cbor(argN);
176          return oraclize.queryN_withGasLimit.value(price)(timestamp, datasource, args, gaslimit);
177      }
178      function oraclize_query(string datasource, string[] argN, uint gaslimit) oraclizeAPI internal returns (bytes32 id){
179          uint price = oraclize.getPrice(datasource, gaslimit);
180          if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price
181          bytes memory args = stra2cbor(argN);
182          return oraclize.queryN_withGasLimit.value(price)(0, datasource, args, gaslimit);
183      }
184      function oraclize_query(string datasource, string[1] args) oraclizeAPI internal returns (bytes32 id) {
185          string[] memory dynargs = new string[](1);
186          dynargs[0] = args[0];
187          return oraclize_query(datasource, dynargs);
188      }
189      function oraclize_query(uint timestamp, string datasource, string[1] args) oraclizeAPI internal returns (bytes32 id) {
190          string[] memory dynargs = new string[](1);
191          dynargs[0] = args[0];
192          return oraclize_query(timestamp, datasource, dynargs);
193      }
194      function oraclize_query(uint timestamp, string datasource, string[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) {
195          string[] memory dynargs = new string[](1);
196          dynargs[0] = args[0];
197          return oraclize_query(timestamp, datasource, dynargs, gaslimit);
198      }
199      function oraclize_query(string datasource, string[1] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) {
200          string[] memory dynargs = new string[](1);
201          dynargs[0] = args[0];       
202          return oraclize_query(datasource, dynargs, gaslimit);
203      }
204      
205      function oraclize_query(string datasource, string[2] args) oraclizeAPI internal returns (bytes32 id) {
206          string[] memory dynargs = new string[](2);
207          dynargs[0] = args[0];
208          dynargs[1] = args[1];
209          return oraclize_query(datasource, dynargs);
210      }
211      function oraclize_query(uint timestamp, string datasource, string[2] args) oraclizeAPI internal returns (bytes32 id) {
212          string[] memory dynargs = new string[](2);
213          dynargs[0] = args[0];
214          dynargs[1] = args[1];
215          return oraclize_query(timestamp, datasource, dynargs);
216      }
217      function oraclize_query(uint timestamp, string datasource, string[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) {
218          string[] memory dynargs = new string[](2);
219          dynargs[0] = args[0];
220          dynargs[1] = args[1];
221          return oraclize_query(timestamp, datasource, dynargs, gaslimit);
222      }
223      function oraclize_query(string datasource, string[2] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) {
224          string[] memory dynargs = new string[](2);
225          dynargs[0] = args[0];
226          dynargs[1] = args[1];
227          return oraclize_query(datasource, dynargs, gaslimit);
228      }
229      function oraclize_query(string datasource, string[3] args) oraclizeAPI internal returns (bytes32 id) {
230          string[] memory dynargs = new string[](3);
231          dynargs[0] = args[0];
232          dynargs[1] = args[1];
233          dynargs[2] = args[2];
234          return oraclize_query(datasource, dynargs);
235      }
236      function oraclize_query(uint timestamp, string datasource, string[3] args) oraclizeAPI internal returns (bytes32 id) {
237          string[] memory dynargs = new string[](3);
238          dynargs[0] = args[0];
239          dynargs[1] = args[1];
240          dynargs[2] = args[2];
241          return oraclize_query(timestamp, datasource, dynargs);
242      }
243      function oraclize_query(uint timestamp, string datasource, string[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) {
244          string[] memory dynargs = new string[](3);
245          dynargs[0] = args[0];
246          dynargs[1] = args[1];
247          dynargs[2] = args[2];
248          return oraclize_query(timestamp, datasource, dynargs, gaslimit);
249      }
250      function oraclize_query(string datasource, string[3] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) {
251          string[] memory dynargs = new string[](3);
252          dynargs[0] = args[0];
253          dynargs[1] = args[1];
254          dynargs[2] = args[2];
255          return oraclize_query(datasource, dynargs, gaslimit);
256      }
257      
258      function oraclize_query(string datasource, string[4] args) oraclizeAPI internal returns (bytes32 id) {
259          string[] memory dynargs = new string[](4);
260          dynargs[0] = args[0];
261          dynargs[1] = args[1];
262          dynargs[2] = args[2];
263          dynargs[3] = args[3];
264          return oraclize_query(datasource, dynargs);
265      }
266      function oraclize_query(uint timestamp, string datasource, string[4] args) oraclizeAPI internal returns (bytes32 id) {
267          string[] memory dynargs = new string[](4);
268          dynargs[0] = args[0];
269          dynargs[1] = args[1];
270          dynargs[2] = args[2];
271          dynargs[3] = args[3];
272          return oraclize_query(timestamp, datasource, dynargs);
273      }
274      function oraclize_query(uint timestamp, string datasource, string[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) {
275          string[] memory dynargs = new string[](4);
276          dynargs[0] = args[0];
277          dynargs[1] = args[1];
278          dynargs[2] = args[2];
279          dynargs[3] = args[3];
280          return oraclize_query(timestamp, datasource, dynargs, gaslimit);
281      }
282      function oraclize_query(string datasource, string[4] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) {
283          string[] memory dynargs = new string[](4);
284          dynargs[0] = args[0];
285          dynargs[1] = args[1];
286          dynargs[2] = args[2];
287          dynargs[3] = args[3];
288          return oraclize_query(datasource, dynargs, gaslimit);
289      }
290      function oraclize_query(string datasource, string[5] args) oraclizeAPI internal returns (bytes32 id) {
291          string[] memory dynargs = new string[](5);
292          dynargs[0] = args[0];
293          dynargs[1] = args[1];
294          dynargs[2] = args[2];
295          dynargs[3] = args[3];
296          dynargs[4] = args[4];
297          return oraclize_query(datasource, dynargs);
298      }
299      function oraclize_query(uint timestamp, string datasource, string[5] args) oraclizeAPI internal returns (bytes32 id) {
300          string[] memory dynargs = new string[](5);
301          dynargs[0] = args[0];
302          dynargs[1] = args[1];
303          dynargs[2] = args[2];
304          dynargs[3] = args[3];
305          dynargs[4] = args[4];
306          return oraclize_query(timestamp, datasource, dynargs);
307      }
308      function oraclize_query(uint timestamp, string datasource, string[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) {
309          string[] memory dynargs = new string[](5);
310          dynargs[0] = args[0];
311          dynargs[1] = args[1];
312          dynargs[2] = args[2];
313          dynargs[3] = args[3];
314          dynargs[4] = args[4];
315          return oraclize_query(timestamp, datasource, dynargs, gaslimit);
316      }
317      function oraclize_query(string datasource, string[5] args, uint gaslimit) oraclizeAPI internal returns (bytes32 id) {
318          string[] memory dynargs = new string[](5);
319          dynargs[0] = args[0];
320          dynargs[1] = args[1];
321          dynargs[2] = args[2];
322          dynargs[3] = args[3];
323          dynargs[4] = args[4];
324          return oraclize_query(datasource, dynargs, gaslimit);
325      }
326  
327      function oraclize_cbAddress() oraclizeAPI internal returns (address){
328          return oraclize.cbAddress();
329      }
330      function oraclize_setProof(byte proofP) oraclizeAPI internal {
331          return oraclize.setProofType(proofP);
332      }
333      function oraclize_setCustomGasPrice(uint gasPrice) oraclizeAPI internal {
334          return oraclize.setCustomGasPrice(gasPrice);
335      }
336      function oraclize_setConfig(bytes32 config) oraclizeAPI internal {
337          return oraclize.setConfig(config);
338      }
339  
340      function getCodeSize(address _addr) constant internal returns(uint _size) {
341          assembly {
342              _size := extcodesize(_addr)
343          }
344      }
345  
346      function parseAddr(string _a) internal returns (address){
347          bytes memory tmp = bytes(_a);
348          uint160 iaddr = 0;
349          uint160 b1;
350          uint160 b2;
351          for (uint i=2; i<2+2*20; i+=2){
352              iaddr *= 256;
353              b1 = uint160(tmp[i]);
354              b2 = uint160(tmp[i+1]);
355              if ((b1 >= 97)&&(b1 <= 102)) b1 -= 87;
356              else if ((b1 >= 48)&&(b1 <= 57)) b1 -= 48;
357              if ((b2 >= 97)&&(b2 <= 102)) b2 -= 87;
358              else if ((b2 >= 48)&&(b2 <= 57)) b2 -= 48;
359              iaddr += (b1*16+b2);
360          }
361          return address(iaddr);
362      }
363  
364      function strCompare(string _a, string _b) internal returns (int) {
365          bytes memory a = bytes(_a);
366          bytes memory b = bytes(_b);
367          uint minLength = a.length;
368          if (b.length < minLength) minLength = b.length;
369          for (uint i = 0; i < minLength; i ++)
370              if (a[i] < b[i])
371                  return -1;
372              else if (a[i] > b[i])
373                  return 1;
374          if (a.length < b.length)
375              return -1;
376          else if (a.length > b.length)
377              return 1;
378          else
379              return 0;
380      }
381  
382      function indexOf(string _haystack, string _needle) internal returns (int) {
383          bytes memory h = bytes(_haystack);
384          bytes memory n = bytes(_needle);
385          if(h.length < 1 || n.length < 1 || (n.length > h.length))
386              return -1;
387          else if(h.length > (2**128 -1))
388              return -1;
389          else
390          {
391              uint subindex = 0;
392              for (uint i = 0; i < h.length; i ++)
393              {
394                  if (h[i] == n[0])
395                  {
396                      subindex = 1;
397                      while(subindex < n.length && (i + subindex) < h.length && h[i + subindex] == n[subindex])
398                      {
399                          subindex++;
400                      }
401                      if(subindex == n.length)
402                          return int(i);
403                  }
404              }
405              return -1;
406          }
407      }
408  
409      function strConcat(string _a, string _b, string _c, string _d, string _e) internal returns (string) {
410          bytes memory _ba = bytes(_a);
411          bytes memory _bb = bytes(_b);
412          bytes memory _bc = bytes(_c);
413          bytes memory _bd = bytes(_d);
414          bytes memory _be = bytes(_e);
415          string memory abcde = new string(_ba.length + _bb.length + _bc.length + _bd.length + _be.length);
416          bytes memory babcde = bytes(abcde);
417          uint k = 0;
418          for (uint i = 0; i < _ba.length; i++) babcde[k++] = _ba[i];
419          for (i = 0; i < _bb.length; i++) babcde[k++] = _bb[i];
420          for (i = 0; i < _bc.length; i++) babcde[k++] = _bc[i];
421          for (i = 0; i < _bd.length; i++) babcde[k++] = _bd[i];
422          for (i = 0; i < _be.length; i++) babcde[k++] = _be[i];
423          return string(babcde);
424      }
425  
426      function strConcat(string _a, string _b, string _c, string _d) internal returns (string) {
427          return strConcat(_a, _b, _c, _d, "");
428      }
429  
430      function strConcat(string _a, string _b, string _c) internal returns (string) {
431          return strConcat(_a, _b, _c, "", "");
432      }
433  
434      function strConcat(string _a, string _b) internal returns (string) {
435          return strConcat(_a, _b, "", "", "");
436      }
437  
438      // parseInt
439      function parseInt(string _a) internal returns (uint) {
440          return parseInt(_a, 0);
441      }
442  
443      // parseInt(parseFloat*10^_b)
444      function parseInt(string _a, uint _b) internal returns (uint) {
445          bytes memory bresult = bytes(_a);
446          uint mint = 0;
447          bool decimals = false;
448          for (uint i=0; i<bresult.length; i++){
449              if ((bresult[i] >= 48)&&(bresult[i] <= 57)){
450                  if (decimals){
451                     if (_b == 0) break;
452                      else _b--;
453                  }
454                  mint *= 10;
455                  mint += uint(bresult[i]) - 48;
456              } else if (bresult[i] == 46) decimals = true;
457          }
458          if (_b > 0) mint *= 10**_b;
459          return mint;
460      }
461  
462      function uint2str(uint i) internal returns (string){
463          if (i == 0) return "0";
464          uint j = i;
465          uint len;
466          while (j != 0){
467              len++;
468              j /= 10;
469          }
470          bytes memory bstr = new bytes(len);
471          uint k = len - 1;
472          while (i != 0){
473              bstr[k--] = byte(48 + i % 10);
474              i /= 10;
475          }
476          return string(bstr);
477      }
478  
479      function stra2cbor(string[] arr) internal returns (bytes) {
480              uint arrlen = arr.length;
481  
482              // get correct cbor output length
483              uint outputlen = 0;
484              bytes[] memory elemArray = new bytes[](arrlen);
485              for (uint i = 0; i < arrlen; i++) {
486                  elemArray[i] = (bytes(arr[i]));
487                  outputlen += elemArray[i].length + (elemArray[i].length - 1)/23 + 3; //+3 accounts for paired identifier types
488              }
489              uint ctr = 0;
490              uint cborlen = arrlen + 0x80;
491              outputlen += byte(cborlen).length;
492              bytes memory res = new bytes(outputlen);
493  
494              while (byte(cborlen).length > ctr) {
495                  res[ctr] = byte(cborlen)[ctr];
496                  ctr++;
497              }
498              for (i = 0; i < arrlen; i++) {
499                  res[ctr] = 0x5F;
500                  ctr++;
501                  for (uint x = 0; x < elemArray[i].length; x++) {
502                      // if there's a bug with larger strings, this may be the culprit
503                      if (x % 23 == 0) {
504                          uint elemcborlen = elemArray[i].length - x >= 24 ? 23 : elemArray[i].length - x;
505                          elemcborlen += 0x40;
506                          uint lctr = ctr;
507                          while (byte(elemcborlen).length > ctr - lctr) {
508                              res[ctr] = byte(elemcborlen)[ctr - lctr];
509                              ctr++;
510                          }
511                      }
512                      res[ctr] = elemArray[i][x];
513                      ctr++;
514                  }
515                  res[ctr] = 0xFF;
516                  ctr++;
517              }
518              return res;
519          }
520  }
521  // </ORACLIZE_API>