mirror of
https://github.com/status-im/github-oracle.git
synced 2026-08-27 09:51:10 +00:00
commit update first version
This commit is contained in:
+16
-6
@@ -34,8 +34,8 @@ contract DGit is Owned, DGitI {
|
||||
function register(string _github_user, string _gistid) payable{
|
||||
gitHubApi.register.value(msg.value)(msg.sender,_github_user,_gistid);
|
||||
}
|
||||
function claimCommit(string _repository, string _commitid) payable{
|
||||
gitHubApi.claimCommit.value(msg.value)(_repository,_commitid);
|
||||
function updateCommits(string _repository) payable{
|
||||
gitHubApi.updateCommits.value(msg.value)(_repository,db.getClaimedHead(_repository));
|
||||
}
|
||||
function addRepository(string _repository) payable{
|
||||
gitHubApi.addRepository.value(msg.value)(_repository);
|
||||
@@ -75,12 +75,22 @@ contract DGit is Owned, DGitI {
|
||||
GitRepositoryI(repository).setStats(subscribers,watchers);
|
||||
}
|
||||
|
||||
event NewClaim(string repository, bytes20 commitid, uint userId, uint total );
|
||||
function __claimCommit(string repository, bytes20 commitid, uint userId, uint total)
|
||||
event NewPoints(string repository, uint userId, uint total);
|
||||
function __newPoints(string repository, uint userId, uint total)
|
||||
only_gitapi {
|
||||
NewClaim(repository,commitid,userId,total);
|
||||
NewPoints(repository,userId,total);
|
||||
GitRepositoryI repoaddr = GitRepositoryI(db.getRepositoryAddress(repository));
|
||||
repoaddr.claim(commitid, db.getUserAddress(userId), total);
|
||||
if(!repoaddr.claim(db.getUserAddress(userId), total)){ //try to claim points
|
||||
db.setPending(repository, userId, total); //set as a pending points
|
||||
}
|
||||
}
|
||||
|
||||
//claims pending points
|
||||
function claimPending(uint repoId, uint userId){
|
||||
GitRepositoryI repoaddr = GitRepositoryI(db.getRepositoryAddress(repoId));
|
||||
uint total = db.claimPending(repoId,userId);
|
||||
if(!repoaddr.claim(db.getUserAddress(userId), total)) throw;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,8 +25,12 @@ contract DGitDBI {
|
||||
function getUserAddress(uint256 _id) constant returns(address);
|
||||
function getUserAddress(string _login) constant returns(address);
|
||||
function getClaimedHead(uint256 _repoid) constant returns (bytes20);
|
||||
function getClaimedHead(string _full_name) constant returns (bytes20);
|
||||
function getClaimedTail(uint256 _repoid) constant returns (bytes20);
|
||||
function setClaimed(uint256 _repoid, bytes20 _head, bytes20 _tail, uint points);
|
||||
function setPending(uint256 _repoid, uint256 _userid, uint256 _points);
|
||||
function setPending(string _full_name, uint256 _userid, uint256 _points);
|
||||
function claimPending(uint256 _repoid, uint256 _userid) returns (uint256 points);
|
||||
}
|
||||
|
||||
contract DGitDB is DGitDBI, Owned {
|
||||
@@ -44,6 +48,7 @@ contract DGitDB is DGitDBI, Owned {
|
||||
uint points;
|
||||
bytes20 head;
|
||||
bytes20 tail;
|
||||
mapping (uint256 => uint256) pending;
|
||||
}
|
||||
|
||||
|
||||
@@ -59,16 +64,29 @@ contract DGitDB is DGitDBI, Owned {
|
||||
repositories[_repoid].tail = _tail;
|
||||
repositories[_repoid].points += _points;
|
||||
}
|
||||
function setPending(uint256 _repoid, uint256 _userid, uint256 _points){
|
||||
repositories[_repoid].pending[_userid] += _points;
|
||||
}
|
||||
function setPending(string _full_name, uint256 _userid, uint256 _points){
|
||||
repositories[repositoryNames[_full_name]].pending[_userid] += _points;
|
||||
}
|
||||
function claimPending(uint256 _repoid, uint256 _userid) returns (uint256 points){
|
||||
points = repositories[_repoid].pending[_userid];
|
||||
delete repositories[_repoid].pending[_userid];
|
||||
}
|
||||
|
||||
function getClaimedHead(uint256 _repoid) constant returns (bytes20){
|
||||
return repositories[_repoid].head;
|
||||
}
|
||||
function getClaimedHead(string _full_name) constant returns (bytes20){
|
||||
return repositories[repositoryNames[_full_name]].head;
|
||||
}
|
||||
function getClaimedTail(uint256 _repoid) constant returns (bytes20){
|
||||
return repositories[_repoid].tail;
|
||||
}
|
||||
|
||||
function addRepository(uint256 _id, uint256 _owner, string _name, string _full_name, address _addr) only_owner {
|
||||
repositories[_id] = Repository({owner:_owner,name:_name,full_name:_full_name,addr:_addr,points:0});
|
||||
repositories[_id] = Repository({owner:_owner,name:_name,full_name:_full_name,addr:_addr,points:0,head:0,tail:0});
|
||||
repositoryNames[_full_name] = _id;
|
||||
}
|
||||
|
||||
@@ -101,7 +119,6 @@ contract DGitDB is DGitDBI, Owned {
|
||||
users[_userId].login = _name;
|
||||
}
|
||||
|
||||
|
||||
function getUserAddress(uint256 _id) constant returns(address){
|
||||
return users[_id].addr;
|
||||
}
|
||||
@@ -124,9 +141,7 @@ contract DGitDB is DGitDBI, Owned {
|
||||
}
|
||||
|
||||
library DBFactory {
|
||||
|
||||
function newStorage() returns (DGitDBI){
|
||||
return new DGitDB();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import "lib/ethereans/management/Owned.sol";
|
||||
|
||||
contract GitHubAPI{
|
||||
function register(address _sender, string _github_user, string _gistid) payable;
|
||||
function claimCommit(string _repository, string _commitid) payable;
|
||||
function updateCommits(string _repository, bytes20 _commitid) payable;
|
||||
function addRepository(string _repository) payable;
|
||||
function updateIssue(string _repository, string issue) payable;
|
||||
}
|
||||
@@ -16,7 +16,7 @@ contract GitHubAPI{
|
||||
contract DGitI {
|
||||
function __register(address addrLoaded, uint256 userId, string login);
|
||||
function __setRepository(uint256 projectId, string full_name, uint256 watchers, uint256 subscribers);
|
||||
function __claimCommit(string repository, bytes20 commitid, uint userid, uint total);
|
||||
function __newPoints(string repository, uint userId, uint total);
|
||||
}
|
||||
|
||||
contract GitHubAPIOraclize is GitHubAPI, Owned, usingOraclize{
|
||||
@@ -58,9 +58,8 @@ contract GitHubAPIOraclize is GitHubAPI, Owned, usingOraclize{
|
||||
|
||||
function updateCommits(string _repository, bytes20 _commitid)
|
||||
payable only_owner{
|
||||
string memory cred = StringLib.concat(" -c ${[decrypt] ", _client_id,"} -s ${[decrypt] ", _client_secret,"}");
|
||||
string memory commit_url = StringLib.concat("-S update-commits -r",_repository," -H ", toString(_commitid), cred);
|
||||
bytes32 ocid = oraclize_query("computation", ['']);
|
||||
bytes32 ocid = oraclize_query("computation", [script, commit_url]);
|
||||
claimType[ocid] = OracleType.CLAIM_COMMIT;
|
||||
commitClaim[ocid] = CommitClaim( { repository: _repository, commitid:_commitid});
|
||||
}
|
||||
@@ -143,7 +142,7 @@ contract GitHubAPIOraclize is GitHubAPI, Owned, usingOraclize{
|
||||
for(uint i; i < numAuthors; i++){
|
||||
(userId,pos) = JSONLib.getNextUInt(v,pos);
|
||||
(points,pos) = JSONLib.getNextUInt(v,pos);
|
||||
dGit._setCommiter(commitClaim[myid].repository,userId,points);
|
||||
dGit.__newPoints(commitClaim[myid].repository,userId,points);
|
||||
}
|
||||
delete commitClaim[myid];
|
||||
}
|
||||
|
||||
@@ -22,8 +22,7 @@ import "./GitRepositoryToken.sol";
|
||||
|
||||
|
||||
contract GitRepositoryI {
|
||||
function isClaimed(bytes20 _commitid) constant returns (bool);
|
||||
function claim(bytes20 _commitid, address _user, uint _total);
|
||||
function claim(address _user, uint _total) returns (bool) ;
|
||||
function setStats(uint256 _subscribers, uint256 _watchers);
|
||||
}
|
||||
|
||||
@@ -36,19 +35,10 @@ contract GitRepository is GitRepositoryI, Owned {
|
||||
|
||||
string public name;
|
||||
uint256 public uid;
|
||||
mapping (bytes20 => bool) public commits;
|
||||
|
||||
|
||||
uint256 public subscribers;
|
||||
uint256 public watchers;
|
||||
//claim event
|
||||
event Claim(bytes32 commit);
|
||||
|
||||
//protect against double claiming
|
||||
modifier not_claimed(bytes20 commitid) {
|
||||
if(isClaimed(commitid)) throw;
|
||||
_;
|
||||
}
|
||||
|
||||
function () payable {
|
||||
donationBank.deposit();
|
||||
donators[msg.sender] += msg.value;
|
||||
@@ -63,20 +53,15 @@ contract GitRepository is GitRepositoryI, Owned {
|
||||
bountyBank = new BountyBank();
|
||||
}
|
||||
|
||||
//checks if a commit is already claimed
|
||||
function isClaimed(bytes20 _commitid)
|
||||
constant
|
||||
returns (bool) {
|
||||
return commits[_commitid];
|
||||
}
|
||||
|
||||
//oracle claim request
|
||||
function claim(bytes20 _commitid, address _user, uint _total)
|
||||
only_owner {
|
||||
if(_total > 0 && !token.lock() && _user != 0x0 && !commits[_commitid]){
|
||||
Claim(_commitid);
|
||||
commits[_commitid] = true;
|
||||
function claim(address _user, uint _total)
|
||||
only_owner returns (bool) {
|
||||
if(!token.lock() && _user != 0x0){
|
||||
token.mint(_user, _total);
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user