mirror of
https://github.com/status-im/github-oracle.git
synced 2026-08-27 09:51:10 +00:00
cleanup
This commit is contained in:
@@ -15,9 +15,9 @@
|
||||
|
||||
import "lib/oraclize/oraclizeAPI_0.4.sol";
|
||||
import "lib/ethereans/management/Owned.sol";
|
||||
import "GitHubUserReg.sol";
|
||||
import "GitHubRepositoryReg.sol";
|
||||
import "GitHubPoints.sol";
|
||||
import "./GitHubUserReg.sol";
|
||||
import "./GitHubRepositoryReg.sol";
|
||||
import "./GitHubPoints.sol";
|
||||
|
||||
pragma solidity ^0.4.11;
|
||||
|
||||
@@ -28,7 +28,7 @@ contract GitHubOracle is Owned, DGitI {
|
||||
GitHubPoints public gitHubPoints;
|
||||
|
||||
mapping (uint256 => Repository) repositories;
|
||||
mapping (uint256 => mapping (uint256 => uint256)) pendingPoints;
|
||||
mapping (uint256 => mapping (uint256 => uint256)) pending;
|
||||
|
||||
struct Repository {
|
||||
bytes20 head;
|
||||
@@ -36,22 +36,19 @@ contract GitHubOracle is Owned, DGitI {
|
||||
}
|
||||
|
||||
function initialize() only_owner {
|
||||
userReg = QueryFactory.newUserReg();
|
||||
repositoryReg = QueryFactory.newRepositoryReg();
|
||||
gitHubPoints = QueryFactory.newPointsOracle();
|
||||
userReg = GitHubUserRegFactory.create();
|
||||
repositoryReg = GitHubRepositoryRegFactory.create();
|
||||
gitHubPoints = GitHubPointsFactory.create();
|
||||
}
|
||||
|
||||
function register(string _github_user, string _gistid) payable{
|
||||
userReg.register.value(msg.value)(msg.sender,_github_user,_gistid);
|
||||
function updateCommits(string _repository, string _token) payable{
|
||||
uint256 repoId = repositoryReg.getId(_repository);
|
||||
if(repoId == 0) throw;
|
||||
gitHubPoints.updateCommits.value(msg.value)(_repository, "master", repositories[repoId].head,_token);
|
||||
}
|
||||
function updateCommits(string _repository) payable{
|
||||
gitHubPoints.updateCommits.value(msg.value)(_repository,db.getClaimedHead(_repository));
|
||||
}
|
||||
function addRepository(string _repository) payable{
|
||||
repositoryReg.addRepository.value(msg.value)(_repository);
|
||||
}
|
||||
function updateIssue(string _repository, string issue) payable{
|
||||
gitHubPoints.updateIssue.value(msg.value)(_repository,issue);
|
||||
|
||||
function updateIssue(string _repository, string issue, string _token) payable{
|
||||
gitHubPoints.updateIssue.value(msg.value)(_repository,issue,_token);
|
||||
}
|
||||
function getRepository(uint projectId) constant returns (address){
|
||||
return repositoryReg.getAddr(projectId);
|
||||
@@ -60,34 +57,32 @@ contract GitHubOracle is Owned, DGitI {
|
||||
return repositoryReg.getAddr(full_name);
|
||||
}
|
||||
|
||||
modifier only_gitapi{
|
||||
if (msg.sender != address(gitHubApi)) throw;
|
||||
_;
|
||||
}
|
||||
|
||||
event NewPoints(uint repoId, uint userId, uint total, bool claimed);
|
||||
|
||||
function __newPoints(uint repoId, uint userId, uint total)
|
||||
only_gitapi {
|
||||
only_owner {
|
||||
GitRepositoryI repoaddr = GitRepositoryI(repositoryReg.getAddr(repoId));
|
||||
bool claimed = repoaddr.claim(db.getUserAddress(userId), total);
|
||||
bool claimed = repoaddr.claim(userReg.getAddr(userId), total);
|
||||
if(!claimed){ //try to claim points
|
||||
addPending(repoId, userId, total); //set as a pending points
|
||||
}
|
||||
NewPoints(repository,userId,total,claimed);
|
||||
NewPoints(repoId,userId,total,claimed);
|
||||
}
|
||||
|
||||
//claims pending points
|
||||
function claimPending(uint repoId, uint userId){
|
||||
GitRepositoryI repoaddr = GitRepositoryI(repositoryReg.getAddr(repoId));
|
||||
function claimPending(uint _repoId, uint _userId){
|
||||
GitRepositoryI repoaddr = GitRepositoryI(repositoryReg.getAddr(_repoId));
|
||||
uint total = pending[_userId][_repoId];
|
||||
delete pending[_userId][_repoId];
|
||||
if(repoaddr.claim(gitHubUserRegistry.getAddr(userId), total)) {
|
||||
NewPoints(repository,userId,total,true);
|
||||
if(repoaddr.claim(userReg.getAddr(_userId), total)) {
|
||||
NewPoints(_repoId,_userId,total,true);
|
||||
} else throw;
|
||||
}
|
||||
|
||||
function addPending(uint256 _repoid, uint256 _userid, uint256 _points) internal {
|
||||
function addPending(uint256 _repoId, uint256 _userId, uint256 _points) internal {
|
||||
pending[_userId][_repoId] += _points;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user