GitHubAPIReg.sol
1 /** 2 * GitHubAPIReg.sol 3 * Abstract Logic for GitHubOracle Registries. 4 * Ricardo Guilherme Schmidt <3esmit@gmail.com> 5 */ 6 import "Owned.sol"; 7 import "oraclizeAPI_0.4.sol"; 8 import "strings.sol"; 9 10 pragma solidity ^0.4.11; 11 12 contract GitHubAPIReg is Owned, usingOraclize { 13 using strings for string; 14 using strings for strings.slice; 15 16 string cred = ""; 17 18 event OracleEvent(bytes32 myid, string result, bytes proof); 19 20 function GitHubAPIReg(){ 21 oraclize_setProof(proofType_TLSNotary | proofStorage_IPFS); 22 } 23 24 //owner management 25 function setAPICredentials(string _client_id, string _client_secret) only_owner { 26 strings.slice [] memory cm = new strings.slice[](5); 27 cm[0] = strings.toSlice("?client_id="); 28 cm[1] = _client_id.toSlice(); 29 cm[2] = strings.toSlice("&client_secret="); 30 cm[4] = _client_secret.toSlice(); 31 cred = strings.toSlice("").join(cm); 32 } 33 34 function clearAPICredentials() only_owner { 35 cred = ""; 36 } 37 38 function getNextString(bytes _str, uint8 _pos) internal constant returns (string, uint8) { 39 uint8 start = 0; 40 uint8 end = 0; 41 uint strl =_str.length; 42 for (;strl > _pos; _pos++) { 43 if (_str[_pos] == '"'){ //Found quotation mark 44 if(_str[_pos-1] != '\\'){ //is not escaped 45 end = start == 0 ? 0: _pos; 46 start = start == 0 ? (_pos+1) : start; 47 if(end > 0) break; 48 } 49 } 50 } 51 bytes memory str = new bytes(end-start); 52 for(_pos=0; _pos<str.length; _pos++){ 53 str[_pos] = _str[start+_pos]; 54 } 55 for(_pos=end+1; _pos<_str.length; _pos++) if (_str[_pos] == ','){ _pos++; break; } //end 56 57 return (string(str),_pos); 58 } 59 60 function getNextUInt(bytes _str, uint8 _pos) internal constant returns (uint, uint8) { 61 uint val = 0; 62 uint strl =_str.length; 63 for (; strl > _pos; _pos++) { 64 byte bp = _str[_pos]; 65 if (bp == ','){ //Find ends 66 _pos++; break; 67 }else if ((bp >= 48)&&(bp <= 57)){ //only ASCII numbers 68 val *= 10; 69 val += uint(bp) - 48; 70 } 71 } 72 return (val,_pos); 73 } 74 75 function getNextAddr(bytes _str, uint8 _pos) internal constant returns (address, uint8){ 76 uint160 iaddr = 0; 77 uint strl =_str.length; 78 for(;strl > _pos; _pos++){ 79 byte bp = _str[_pos]; 80 if (bp == '0'){ 81 if (_str[_pos+1] == 'x'){ 82 for (_pos=_pos+2; _pos<2+2*20; _pos+=2){ 83 iaddr *= 256; 84 iaddr += (uint160(hexVal(uint160(_str[_pos])))*16+uint160(hexVal(uint160(_str[_pos+1])))); 85 } 86 _pos++; 87 break; 88 } 89 }else if (bp == ','){ 90 _pos++; 91 break; 92 } 93 } 94 return (address(iaddr),_pos); 95 } 96 97 function hexVal(uint val) internal constant returns (uint){ 98 return val - (val < 58 ? 48 : (val < 97 ? 55 : 87)); 99 } 100 101 }