fixed branch string dynamic type and added start

This commit is contained in:
Ricardo Guilherme Schmidt 2017-05-20 04:51:42 -03:00
parent d9e8570ebb
commit b5538664d1
1 changed files with 65 additions and 39 deletions

View File

@ -29,64 +29,98 @@ contract GitHubOracle is Controlled, DGitI {
mapping (uint256 => Repository) repositories; mapping (uint256 => Repository) repositories;
mapping (uint256 => mapping (uint256 => uint256)) pending; mapping (uint256 => mapping (uint256 => uint256)) pending;
address public newContract;
modifier oraclized { modifier oraclized {
if(msg.sender != address(gitHubPoints)) throw; if(msg.sender != address(gitHubPoints)) throw;
_; _;
} }
modifier onlyUpgrading {
if(newContract == 0) throw;
_;
}
struct Repository { struct Repository {
string head; string head;
string tail; string tail;
mapping (string => string) pending; mapping (string => string) pending;
} }
function __init_regs() onlyController {
if(address(userReg) == 0x0){
userReg = GHUserReg.create();
}
if(address(repositoryReg) == 0x0){
repositoryReg = GHRepoReg.create();
}
}
function __set_points_script(string _arg) onlyController { function upgrade(uint[] _repoIds) onlyUpgrading {
if(address(gitHubPoints) == 0x0){ uint len = _repoIds.length;
gitHubPoints = GHPoints.create(_arg); for(uint i = 0; i < len; i++){
}else { Controlled(repositoryReg.getAddr(_repoIds[i])).changeController(newContract);
gitHubPoints.setScript(_arg);
} }
} }
function __changeController(address _newController) onlyController { function start(string _repository, string _branch, string _token) payable {
userReg.changeController(_newController); uint256 repoId = repositoryReg.getId(_repository);
repositoryReg.changeController(_newController); if(repoId == 0) throw;
gitHubPoints.changeController(_newController); if(repositoryReg.getBranch(repoId) != sha3(_branch)) throw;
gitHubPoints.start.value(msg.value)(_repository, _branch, _token);
}
function update(string _repository, string _branch, string _token) payable {
uint256 repoId = repositoryReg.getId(_repository);
if(repoId == 0) throw;
if(repositoryReg.getBranch(repoId) != sha3(_branch)) throw;
gitHubPoints.update.value(msg.value)(_repository, _branch, repositories[repoId].head, _token);
} }
function update(string _repository, string _token) payable { function resume(string _repository, string _branch, string _pendingTail, string _token) payable {
uint256 repoId = repositoryReg.getId(_repository); uint256 repoId = repositoryReg.getId(_repository);
if(repoId == 0) throw; if(repoId == 0) throw;
gitHubPoints.update.value(msg.value)(_repository, repositoryReg.getBranch(repoId), repositories[repoId].head, _token); if(repositoryReg.getBranch(repoId) != sha3(_branch)) throw;
} string claimedCommit = repositories[repoId].pending[_pendingTail];
function resume(string _repository, string _pendingTail, string _token) payable {
uint256 repoId = repositoryReg.getId(_repository);
if(repoId == 0) throw;
string claimedCommit = repositories[repoid].pending[_pendingTail];
if(bytes(claimedCommit).length == 0) throw; if(bytes(claimedCommit).length == 0) throw;
delete repositories[repoid].pending[_pendingTail]; delete repositories[repoId].pending[_pendingTail];
gitHubPoints.resume.value(msg.value)(_repository, repositoryReg.getBranch(repoId), _pendingTail, claimedCommit, _token); gitHubPoints.resume.value(msg.value)(_repository, _branch, _pendingTail, claimedCommit, _token);
} }
function longtail(string _repository, string _token) payable {
function longtail(string _repository, string _branch, string _token) payable {
uint256 repoId = repositoryReg.getId(_repository); uint256 repoId = repositoryReg.getId(_repository);
if(repoId == 0) throw; if(repoId == 0) throw;
gitHubPoints.longtail.value(msg.value)(_repository, repositoryReg.getBranch(repoId), repositories[repoId].tail, _token); if(repositoryReg.getBranch(repoId) != sha3(_branch)) throw;
gitHubPoints.longtail.value(msg.value)(_repository, _branch, repositories[repoId].tail, _token);
} }
function issue(string _repository, string _issue, string _token) payable { function issue(string _repository, string _issue, string _token) payable {
gitHubPoints.issue.value(msg.value)(_repository,_issue,_token); gitHubPoints.issue.value(msg.value)(_repository,_issue,_token);
} }
//claims pending points
function claimPending(uint _repoId, uint _userId){
GitRepositoryI repoaddr = GitRepositoryI(repositoryReg.getAddr(_repoId));
uint total = pending[_userId][_repoId];
delete pending[_userId][_repoId];
if(!repoaddr.claim(userReg.getAddr(_userId), total)) throw;
}
function __init_regs() onlyController {
if(address(userReg) == 0){
userReg = GHUserReg.create();
}
if(address(repositoryReg) == 0){
repositoryReg = GHRepoReg.create();
}
}
function __set_points_script(string _arg) onlyController {
if(address(gitHubPoints) == 0){
gitHubPoints = GHPoints.create(_arg);
} else {
gitHubPoints.setScript(_arg);
}
}
function __upgrade_contract(address _newContract) onlyController {
userReg.changeController(_newContract);
repositoryReg.changeController(_newContract);
gitHubPoints.changeController(_newContract);
newContract = _newContract;
if(_newContract != 0) _newContract.send(this.balance);
}
function __pendingScan(uint256 _projectId, string _lastCommit, string _pendingTail) oraclized { function __pendingScan(uint256 _projectId, string _lastCommit, string _pendingTail) oraclized {
repositories[_projectId].pending[_pendingTail] = _lastCommit; repositories[_projectId].pending[_pendingTail] = _lastCommit;
} }
@ -125,13 +159,5 @@ contract GitHubOracle is Controlled, DGitI {
} }
} }
} }
//claims pending points
function claimPending(uint _repoId, uint _userId){
GitRepositoryI repoaddr = GitRepositoryI(repositoryReg.getAddr(_repoId));
uint total = pending[_userId][_repoId];
delete pending[_userId][_repoId];
if(!repoaddr.claim(userReg.getAddr(_userId), total)) throw;
}
} }