2017-11-22 23:14:38 +00:00
|
|
|
pragma solidity ^0.4.17;
|
2017-09-22 09:03:51 +00:00
|
|
|
|
2017-10-17 11:10:12 +00:00
|
|
|
import "./common/strings.sol";
|
2017-11-22 23:14:38 +00:00
|
|
|
import "./deploy/KillableModel.sol";
|
|
|
|
import "./JSONHelper.sol";
|
|
|
|
import "./oraclize/oraclizeAPI_0.4.sol";
|
|
|
|
import "./common/Controlled.sol";
|
2017-10-17 11:10:12 +00:00
|
|
|
import "./management/RegistryIndex.sol";
|
2017-09-22 09:03:51 +00:00
|
|
|
|
2017-11-22 23:14:38 +00:00
|
|
|
|
2017-07-28 06:02:48 +00:00
|
|
|
/**
|
|
|
|
* @title GitHubUserReg.sol
|
|
|
|
* Registers GitHub user login to an address
|
2017-09-22 09:03:51 +00:00
|
|
|
* @author Ricardo Guilherme Schmidt (Status Research & Development GmbH)]
|
2017-07-28 06:02:48 +00:00
|
|
|
*/
|
2017-11-22 23:14:38 +00:00
|
|
|
contract UserOracle is KillableModel, Controlled, RegistryIndex, JSONHelper, usingOraclize {
|
2017-05-19 19:06:53 +00:00
|
|
|
using strings for string;
|
|
|
|
using strings for strings.slice;
|
2017-11-22 23:14:38 +00:00
|
|
|
string private cred = "";
|
2017-10-17 11:10:12 +00:00
|
|
|
|
2017-11-22 23:14:38 +00:00
|
|
|
mapping (bytes32 => UserClaim) userClaim; //temporary db for oraclize user register queries
|
2017-05-11 06:38:15 +00:00
|
|
|
|
|
|
|
event RegisterUpdated(string name);
|
|
|
|
|
|
|
|
//stores temporary data for oraclize user register request
|
|
|
|
struct UserClaim {
|
|
|
|
address sender;
|
|
|
|
string login;
|
|
|
|
}
|
2017-10-17 11:10:12 +00:00
|
|
|
|
|
|
|
function register(string _githubUser, string _gistId, string _cred) public payable {
|
2017-11-22 23:14:38 +00:00
|
|
|
require(watchdog != 0x0);
|
2017-09-22 09:03:51 +00:00
|
|
|
if (bytes(_cred).length == 0) {
|
|
|
|
_cred = cred;
|
|
|
|
}
|
2017-10-17 11:10:12 +00:00
|
|
|
bytes32 ocid = oraclize_query("nested", _queryScript(_githubUser, _gistId, _cred));
|
|
|
|
userClaim[ocid] = UserClaim({sender: msg.sender, login: _githubUser});
|
2017-05-11 06:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//oraclize response callback
|
2017-09-22 09:03:51 +00:00
|
|
|
function __callback(bytes32 myid, string result, bytes proof) public {
|
2017-11-22 23:14:38 +00:00
|
|
|
//OracleEvent(myid, result, proof);
|
2017-09-22 09:03:51 +00:00
|
|
|
require(msg.sender == oraclize.cbAddress());
|
|
|
|
_register(myid, result);
|
2017-05-11 06:38:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function _register(bytes32 myid, string result) internal {
|
|
|
|
bytes memory v = bytes(result);
|
2017-11-22 23:14:38 +00:00
|
|
|
uint256 pos = 0;
|
2017-05-11 06:38:15 +00:00
|
|
|
address addrLoaded;
|
|
|
|
string memory login;
|
|
|
|
uint256 userId;
|
2017-09-22 09:03:51 +00:00
|
|
|
(addrLoaded, pos) = getNextAddr(v, pos);
|
|
|
|
(login, pos) = getNextString(v, pos);
|
|
|
|
(userId, pos) = getNextUInt(v, pos);
|
|
|
|
if (userClaim[myid].sender == addrLoaded && keccak256(userClaim[myid].login) == keccak256(login)) {
|
2017-05-11 06:38:15 +00:00
|
|
|
RegisterUpdated(login);
|
2017-10-17 11:10:12 +00:00
|
|
|
setRegistry(userId, addrLoaded, login);
|
2017-05-11 06:38:15 +00:00
|
|
|
}
|
2017-09-22 09:03:51 +00:00
|
|
|
delete userClaim[myid];
|
2017-05-11 06:38:15 +00:00
|
|
|
}
|
|
|
|
|
2017-10-17 11:10:12 +00:00
|
|
|
function _queryScript(string _githubUser, string _gistId, string _cred) internal returns (string) {
|
2017-09-22 09:03:51 +00:00
|
|
|
strings.slice[] memory cm = new strings.slice[](8);
|
|
|
|
cm[0] = strings.toSlice("[identity] ${[URL] https://gist.githubusercontent.com/");
|
2017-10-17 11:10:12 +00:00
|
|
|
cm[1] = _githubUser.toSlice();
|
2017-09-22 09:03:51 +00:00
|
|
|
cm[2] = strings.toSlice("/");
|
2017-10-17 11:10:12 +00:00
|
|
|
cm[3] = _gistId.toSlice();
|
2017-09-22 09:03:51 +00:00
|
|
|
cm[4] = strings.toSlice("/raw/register.txt}, ${[URL] json(https://api.github.com/gists/");
|
2017-10-17 11:10:12 +00:00
|
|
|
cm[5] = _gistId.toSlice();
|
2017-09-22 09:03:51 +00:00
|
|
|
cm[6] = _cred.toSlice();
|
|
|
|
cm[7] = strings.toSlice(").owner.[login,id]}");
|
|
|
|
return strings.toSlice("").join(cm);
|
2017-05-19 19:06:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|