changed abstract tokens to library link, oraclize to library link, introduced issues (not functional) and oraclize computation scripts

This commit is contained in:
Ricardo Guilherme Schmidt
2017-03-12 04:24:09 +00:00
parent 5263d57dec
commit 36edd65246
22 changed files with 250 additions and 815 deletions
+6 -4
View File
@@ -1,7 +1,7 @@
pragma solidity ^0.4.8;
/**
*
* DO NOT USE: under development
*/
contract AbstractBounty {
@@ -20,10 +20,12 @@ contract AbstractBounty {
modifier only_unlocked(uint num){
if(issues[num].unlock == 0 || issues[num].unlock > now) throw;
_;
}
modifier only_unclaimed(uint num){
if(issues[num].claimed) throw;
_;
}
function deposit(uint num)
@@ -39,15 +41,15 @@ contract AbstractBounty {
uint avaliable = deposits[msg.sender][num];
deposits[msg.sender][num] -= avaliable;
issues[num].balance -= avaliable;
msg.sender.send(avaliable);
if(!msg.sender.send(avaliable)) throw;
}
function open(uint num)
function lock(uint num)
only_unlocked(num)
internal {
issues[num].unlock=0;
}
function close(uint num)
function unlock(uint num)
only_unlocked(num)
internal {
issues[num].unlock=now+LOCKED_TIME;
-91
View File
@@ -1,91 +0,0 @@
pragma solidity ^0.4.8;
/**
* AbstractToken ECR20-compliant token contract
* Child should implement initial supply or minting and overwite base
* Based on BasicCoin by Parity Team (Ethcore), 2016.
* By Ricardo Guilherme Schmidt
* Released under the Apache Licence 2.
*/
import "Token.sol";
// AbstractToken, ECR20 tokens that all belong to the owner for sending around
contract AbstractToken is Token {
// the base, tokens denoted in micros
uint constant public base = 0;
// storage and mapping of all balances & allowances
mapping (address => Account) accounts;
// this is as basic as can be, only the associated balance & allowances
struct Account {
uint balance;
mapping (address => uint) allowanceOf;
}
// the balance should be available
modifier when_owns(address _owner, uint _amount) {
if (accounts[_owner].balance < _amount) throw;
_;
}
// an allowance should be available
modifier when_has_allowance(address _owner, address _spender, uint _amount) {
if (accounts[_owner].allowanceOf[_spender] < _amount) throw;
_;
}
// A helper to notify if overflow occurs
modifier safe_add(uint a, uint b) {
if (a + b < a && a + b < b) throw;
_;
}
// balance of a specific address
function balanceOf(address _who)
constant
returns (uint256) {
return accounts[_who].balance;
}
// transfer
function transfer(address _to, uint256 _value)
when_owns(msg.sender, _value)
safe_add(accounts[_to].balance, _value)
returns (bool) {
Transfer(msg.sender, _to, _value);
accounts[msg.sender].balance -= _value;
accounts[_to].balance += _value;
return true;
}
// transfer via allowance
function transferFrom(address _from, address _to, uint256 _value)
when_owns(_from, _value)
when_has_allowance(_from, msg.sender, _value)
safe_add(accounts[_to].balance, _value)
returns (bool) {
Transfer(_from, _to, _value);
accounts[_from].allowanceOf[msg.sender] -= _value;
accounts[_from].balance -= _value;
accounts[_to].balance += _value;
return true;
}
// approve allowances
function approve(address _spender, uint256 _value)
returns (bool) {
Approval(msg.sender, _spender, _value);
accounts[msg.sender].allowanceOf[_spender] += _value;
return true;
}
// available allowance
function allowance(address _owner, address _spender)
constant
returns (uint256) {
return accounts[_owner].allowanceOf[_spender];
}
}
-158
View File
@@ -1,158 +0,0 @@
pragma solidity ^0.4.0;
/**
* Abstract contract used for recieving donations or profits
* Withdraw is divided by total tokens each account owns
* Unlock period allows transfers
* Lock period allow withdraws
* Child contract that implement minting should use modifier not_locked in minting function
* Inspired by ProfitContainer and Lockable by vDice
*
* By Ricardo Guilherme Schmidt
* Released under GPLv3 License
*/
import "AbstractToken.sol";
contract CollaborationToken is AbstractToken {
//creation time, defined when contract is created
uint public creationTime = now;
//time constants, defines epoch size and periods
uint public constant UNLOCKED_TIME = 25 days;
uint public constant LOCKED_TIME = 5 days;
uint public constant EPOCH_LENGTH = UNLOCKED_TIME + LOCKED_TIME;
//current epoch constant formula, recalculated in any contract call
uint public constant CURRENT_EPOCH = (now - creationTime) / EPOCH_LENGTH + 1;
//next lock constant formula, recalculated in any contract call
uint public constant NEXT_LOCK = (creationTime + CURRENT_EPOCH * UNLOCKED_TIME) + (CURRENT_EPOCH - 1) * LOCKED_TIME;
//used for calculating balance and for checking if account withdrawn
uint public currentPayEpoch;
//stores the balance from the lock time
uint public epochBalance;
//stores lock state, used for events
bool public lock;
//used for hecking if account withdrawn
mapping (address => uint) lastPaidOutEpoch;
//events
event Withdrawn(address tokenHolder, uint amountPaidOut);
event Deposited(address donator,uint value);
event Locked();
event Unlocked();
//checks if not locked and call event on change
modifier not_locked {
if (NEXT_LOCK < now) {
if (lock) throw;
lock = true;
Locked();
return;
}
else {
if (lock) {
lock = false;
Unlocked();
}
}
_;
}
//checks if is locked and call event on change
modifier locked {
if (NEXT_LOCK < now) {
if (!lock){
lock = true;
Locked();
}
}
else {
if (!lock) throw;
lock = false;
Unlocked();
return;
}
_;
}
//update the balance and payout epoch
modifier update_epoch {
if(currentPayEpoch < CURRENT_EPOCH) {
currentPayEpoch = CURRENT_EPOCH;
epochBalance = this.balance;
}
_;
}
//checks if user already withdrawn
modifier not_paid {
if (lastPaidOutEpoch[msg.sender] == currentPayEpoch) throw;
_;
}
//check overflow in multiply
modifier safe_multiply(uint _a, uint _b) {
if (!(_b == 0 || ((_a * _b) / _b) == _a)) throw;
_;
}
//allow deposit and call event
function ()
payable {
Deposited(msg.sender, msg.value);
}
//withdraw if locked and not paid, updates epoch
function withdrawal()
external
locked
update_epoch
not_paid
safe_multiply(balanceOf(msg.sender), epochBalance) {
uint _currentEpoch = CURRENT_EPOCH;
uint _tokenBalance = balanceOf(msg.sender);
uint _totalSupply = totalSupply;
if (this.balance == 0 || _tokenBalance == 0) throw;
lastPaidOutEpoch[msg.sender] = currentPayEpoch;
uint amountToPayOut = (_tokenBalance * epochBalance) / _totalSupply;
if(!msg.sender.send(amountToPayOut)) {
throw;
}
Withdrawn(msg.sender, amountToPayOut);
}
//if this coin owns tokens of other lockablecoin, allow withdraw
function withdrawalFrom(CollaborationToken _otherCollaborationToken) {
_otherCollaborationToken.withdrawal();
}
//return expected payout in lock or estimated when not locked
function expectedPayout(address _tokenHolder)
external
constant
returns (uint payout) {
if (now < NEXT_LOCK) //unlocked, estimate
payout = (balanceOf(_tokenHolder) * this.balance) / totalSupply;
else
payout = (balanceOf(_tokenHolder) * epochBalance) / totalSupply;
}
//overwrite not allow transfer during lock
function transfer(address _to, uint256 _value)
not_locked
returns (bool ok) {
return super.transfer(_to,_value);
}
//overwrite not allow transfer during lock
function transferFrom(address _from, address _to, uint256 _value)
not_locked
returns (bool ok) {
return super.transferFrom(_from,_to,_value);
}
//overwrite not allow transfer during lock
function approve(address _spender, uint256 _value)
returns (bool ok) {
return super.approve(_spender,_value);
}
}
-58
View File
@@ -1,58 +0,0 @@
pragma solidity ^0.4.1;
/**
* Mintable coin with register of reason of minting
* Accept donations and can be withdrawn by token holders
*
* By Ricardo Guilherme Schmidt
* Released under GPLv3 License
*/
import "LockableCoin.sol";
contract EtherianKudos is LockableCoin {
event NewMinter(address minter, address newMinter);
event TokenMint(address minter, address beneficiary, string data);
event Verified(address minter, address newMinter);
mapping (uint => Receipt) public receipts;
mapping (address => bool) public minters;
// storage of minting reason
struct Receipt {
address minter;
address beneficiary;
string data;
}
// the balance should be available
modifier when_minter(address _minter) {
if (!minters[_minter]) throw;
_;
}
function EtherianKudos(address _minter) {
_add_minter(0x0,_minter);
}
function mint(address _beneficiary, string _data)
not_locked
when_minter(msg.sender) {
totalSupply++;
accounts[_beneficiary].balance++;
receipts[totalSupply].minter = msg.sender;
receipts[totalSupply].beneficiary = _beneficiary;
receipts[totalSupply].data = _data;
TokenMint(msg.sender, _beneficiary, _data);
}
function setMinter(address _newMinter)
when_minter(msg.sender) {
_add_minter(msg.sender, _newMinter);
}
function _add_minter(address _minter, address _newMinter)
internal {
minters[_newMinter] = true;
NewMinter(_minter,_newMinter);
}
}
-19
View File
@@ -1,19 +0,0 @@
pragma solidity ^0.4.8;
/**
*
*/
import "Bounty.sol";
contract GitHubIssue is AbstractBounty {
function __callback(bytes32 _ocid, string _result) {
}
function update(uint num){
}
}
+32
View File
@@ -0,0 +1,32 @@
pragma solidity ^0.4.8;
/**
* DO NOT USE: under development
*/
import "./GitHubOracle.sol";
import "./AbstractBounty.sol";
contract GitHubIssues is AbstractBounty {
//Address of the oracle, used for github login address lookup
GitHubOracle public oracle;
//stores repository name, used for claim calls
string private repository;
//stores repository name in sha3, used by GitHubOracle
bytes32 public sha3repository;
modifier only_oracle {
if (msg.sender != address(oracle)) throw;
_;
}
function GitHubIssues(string _repository, GitHubOracle _oracle) {
oracle = _oracle;
repository = _repository;
sha3repository = sha3(_repository);
}
function update(uint num){
}
}
@@ -1,8 +1,7 @@
pragma solidity ^0.4.8;
/**
* Contract that mint tokens by github commit stats
* This file contain two contracts: GitHubOracle and GitHubToken
* Contract that oracle github API
*
* GitHubOracle register users and create GitHubToken contracts
* Registration requires user create a gist with only their account address
@@ -15,88 +14,19 @@ pragma solidity ^0.4.8;
* By Ricardo Guilherme Schmidt
* Released under GPLv3 License
*/
import "lib/oraclizeAPI_0.4.sol";
import "Owned.sol";
import "CollaborationToken.sol";
contract GitHubToken is CollaborationToken, usingOraclize {
//stores repository name, used for claim calls
string private repository;
//stores repository name in sha3, used by GitHubOracle
bytes32 public sha3repository;
//permanent storage of recipts of all commits
mapping (bytes32 => CommitReciept) public commits;
//Address of the oracle, used for github login address lookup
GitHubOracle public oracle;
//claim event
event Claim(string claimer, string commitid, uint total);
//stores the total and user, and if claimed (used against double claiming)
struct CommitReciept {
uint256 total;
address user;
bool claimed;
}
//protect against double claiming
modifier not_claimed(string commitid) {
if(isClaimed(commitid)) throw;
_;
}
modifier only_oracle {
if (msg.sender != address(oracle)) throw;
_;
}
function GitHubToken(string _repository, GitHubOracle _oracle)
payable {
oracle = _oracle;
repository = _repository;
sha3repository = sha3(_repository);
}
//checks if a commit is already claimed
function isClaimed(string _commitid)
constant
returns (bool) {
return commits[sha3(_commitid)].claimed;
}
//oracle claim request
function _claim(string _commitid, string _login, uint _total)
only_oracle {
if(_total > 0 && !lock){
bytes32 shacommit = sha3(_commitid);
address user = oracle.getUserAddress(_login);
if(!commits[shacommit].claimed && user != 0x0){
commits[shacommit].claimed = true;
commits[shacommit].user = user;
commits[shacommit].total = _total;
accounts[user].balance += _total;
totalSupply += _total;
Claim(_login,_commitid,_total);
}
}
}
//claims a commitid
function claim(string _commitid)
payable
not_locked
not_claimed(_commitid) {
oracle.claimCommit(repository, _commitid);
}
}
import "lib/oraclize/ethereum-api/oraclizeAPI_0.4.sol";
import "./Owned.sol";
import "./GitHubToken.sol";
import "./GitHubIssues.sol";
contract GitHubOracle is Owned, usingOraclize {
//constant for oraclize commits callbacks
//constant for oraclize user callbacks
uint8 constant CLAIM_USER = 0;
//constant for oraclize commits callbacks
uint8 constant CLAIM_COMMIT = 1;
//constant for oraclize issues callbacks
uint8 constant UPDATE_ISSUE = 2;
//temporary storage enumerating oraclize calls
mapping (bytes32 => uint8) claimType;
//temporary storage for oraclize commit token claim calls
@@ -111,11 +41,12 @@ contract GitHubOracle is Owned, usingOraclize {
string private credentials = "";
//events
event UserSet(string githubLogin, address account);
event RepositoryAdd(string repository, address account);
event RepositoryAdd(string repository, address token, address issues);
//stores the address of githubtoken and registered is used for overwriting previous registered
struct Repository {
GitHubToken account;
GitHubToken token;
GitHubIssues issues;
bool registered;
}
@@ -153,7 +84,7 @@ contract GitHubOracle is Owned, usingOraclize {
delete userClaim[_ocid]; //should always be deleted
}else if(callback_type==CLAIM_COMMIT){
var (login,total) = extractCommit(_result);
repositories[commitClaim[_ocid].repository].account._claim(commitClaim[_ocid].commitid,login,total);
repositories[commitClaim[_ocid].repository].token._claim(commitClaim[_ocid].commitid,login,total);
delete commitClaim[_ocid]; //should always be deleted
}
delete claimType[_ocid]; //should always be deleted
@@ -181,31 +112,40 @@ contract GitHubOracle is Owned, usingOraclize {
commitClaim[ocid] = CommitClaim({repository: sha3(_repository), commitid: _commitid });
}
function updateIssueState(string _repository, uint _issueid){
throw; // * DO NOT USE: under development
//bytes32 ocid = oraclize_query("URL", strConcat(strConcat("json(https://api.github.com/repos/", _repository,"/issues/", parseInt(_issueid), credentials),").[closed_at]"));
}
//creates a new GitHubToken contract to _repository
function addRepository(string _repository)
returns (GitHubToken) {
bytes32 repo = sha3(_repository);
if(repositories[repo].registered) throw;
repositories[repo] = Repository({account: new GitHubToken(_repository, this), registered: true});
RepositoryAdd(_repository, repositories[repo].account);
return repositories[repo].account;
repositories[repo] = Repository({
token: new GitHubToken(_repository, this),
issues: new GitHubIssues(_repository,this),
registered: true
});
RepositoryAdd(_repository, repositories[repo].token, repositories[repo].issues);
return repositories[repo].token;
}
//register a contract deployed outside Oracle
function addRepository(string _repository, GitHubToken _addr)
function addRepository(string _repository, GitHubToken _addr, GitHubIssues _issues)
returns (GitHubToken) {
bytes32 repo = sha3(_repository);
if(repositories[repo].registered || _addr.sha3repository() != repo) throw;
repositories[repo] = Repository({account: _addr, registered: true});
RepositoryAdd(_repository, repositories[repo].account);
return repositories[repo].account;
repositories[repo] = Repository({token: _addr, issues: _issues, registered: true});
RepositoryAdd(_repository, repositories[repo].token, repositories[repo].issues);
return repositories[repo].token;
}
//return the contract address of the repository (or 0x0 if none registered)
function getRepository(string _repository)
function getRepositoryToken(string _repository)
constant
returns (GitHubToken) {
return repositories[sha3(_repository)].account;
return repositories[sha3(_repository)].token;
}
@@ -257,4 +197,4 @@ contract GitHubOracle is Owned, usingOraclize {
only_owner {
credentials = "";
}
}
}
+89
View File
@@ -0,0 +1,89 @@
pragma solidity ^0.4.8;
/**
* Contract that mint tokens by github commit stats
*
* GitHubOracle register users and create GitHubToken contracts
* Registration requires user create a gist with only their account address
* GitHubOracle will create one GitHubToken contract per repository
* GitHubToken mint tokens by commit only for registered users in GitHubOracle
* GitHubToken is a LockableCoin, that accept donatations and can be withdrawn by Token Holders
* The lookups are done by Oraclize that charge a small fee
* The contract itself will never charge any fee
*
* By Ricardo Guilherme Schmidt
* Released under GPLv3 License
*/
import "lib/ethereans/abstract-token/CollaborationToken.sol";
import "GitHubOracle.sol";
contract GitHubToken is CollaborationToken {
//stores repository name, used for claim calls
string private repository;
//stores repository name in sha3, used by GitHubOracle
bytes32 public sha3repository;
//permanent storage of recipts of all commits
mapping (bytes32 => CommitReciept) public commits;
//Address of the oracle, used for github login address lookup
GitHubOracle public oracle;
//claim event
event Claim(bytes32 shacommit);
//stores the total and user, and if claimed (used against double claiming)
struct CommitReciept {
uint256 total;
address user;
bool claimed;
}
//protect against double claiming
modifier not_claimed(string commitid) {
if(isClaimed(commitid)) throw;
_;
}
modifier only_oracle {
if (msg.sender != address(oracle)) throw;
_;
}
function GitHubToken(string _repository, GitHubOracle _oracle) {
oracle = _oracle;
repository = _repository;
sha3repository = sha3(_repository);
}
//checks if a commit is already claimed
function isClaimed(string _commitid)
constant
returns (bool) {
return commits[sha3(_commitid)].claimed;
}
//oracle claim request
function _claim(string _commitid, string _login, uint _total)
only_oracle {
if(_total > 0 && !lock){
bytes32 shacommit = sha3(_commitid);
address user = oracle.getUserAddress(_login);
if(!commits[shacommit].claimed && user != 0x0){
commits[shacommit].claimed = true;
commits[shacommit].user = user;
commits[shacommit].total = _total;
mint(user, _total);
Claim(shacommit);
}
}
}
//claims a commitid
function claim(string _commitid)
payable
not_locked
not_claimed(_commitid) {
oracle.claimCommit(repository, _commitid);
}
}
-1
View File
@@ -1 +0,0 @@
Moved to: https://github.com/ethereans/github-token/blob/master/contracts/CollaborationToken.sol
-14
View File
@@ -1,14 +0,0 @@
pragma solidity ^0.4.8;
// ECR20 standard token interface
contract Token {
uint public totalSupply;
function balanceOf(address who) constant returns (uint);
function allowance(address owner, address spender) constant returns (uint);
function transfer(address to, uint value) returns (bool ok);
function transferFrom(address from, address to, uint value) returns (bool ok);
function approve(address spender, uint value) returns (bool ok);
event Transfer(address indexed from, address indexed to, uint value);
event Approval(address indexed owner, address indexed spender, uint value);
}
+1
View File
@@ -0,0 +1 @@
../../../../abstract-token/contracts/
+1
View File
@@ -0,0 +1 @@
../../../../oraclize/ethereum-api
-311
View File
@@ -1,311 +0,0 @@
// <ORACLIZE_API>
/*
Copyright (c) 2015-2016 Oraclize SRL
Copyright (c) 2016 Oraclize LTD
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
pragma solidity ^0.4.0;//please import oraclizeAPI_pre0.4.sol when solidity < 0.4.0
contract OraclizeI {
address public cbAddress;
function query(uint _timestamp, string _datasource, string _arg) payable returns (bytes32 _id);
function query_withGasLimit(uint _timestamp, string _datasource, string _arg, uint _gaslimit) payable returns (bytes32 _id);
function query2(uint _timestamp, string _datasource, string _arg1, string _arg2) payable returns (bytes32 _id);
function query2_withGasLimit(uint _timestamp, string _datasource, string _arg1, string _arg2, uint _gaslimit) payable returns (bytes32 _id);
function getPrice(string _datasource) returns (uint _dsprice);
function getPrice(string _datasource, uint gaslimit) returns (uint _dsprice);
function useCoupon(string _coupon);
function setProofType(byte _proofType);
function setConfig(bytes32 _config);
function setCustomGasPrice(uint _gasPrice);
}
contract OraclizeAddrResolverI {
function getAddress() returns (address _addr);
}
contract usingOraclize {
uint constant day = 60*60*24;
uint constant week = 60*60*24*7;
uint constant month = 60*60*24*30;
byte constant proofType_NONE = 0x00;
byte constant proofType_TLSNotary = 0x10;
byte constant proofStorage_IPFS = 0x01;
uint8 constant networkID_auto = 0;
uint8 constant networkID_mainnet = 1;
uint8 constant networkID_testnet = 2;
uint8 constant networkID_morden = 2;
uint8 constant networkID_consensys = 161;
OraclizeAddrResolverI OAR;
OraclizeI oraclize;
modifier oraclizeAPI {
if((address(OAR)==0)||(getCodeSize(address(OAR))==0)) oraclize_setNetwork(networkID_auto);
oraclize = OraclizeI(OAR.getAddress());
_;
}
modifier coupon(string code){
oraclize = OraclizeI(OAR.getAddress());
oraclize.useCoupon(code);
_;
}
function oraclize_setNetwork(uint8 networkID) internal returns(bool){
if (getCodeSize(0x1d3B2638a7cC9f2CB3D298A3DA7a90B67E5506ed)>0){ //mainnet
OAR = OraclizeAddrResolverI(0x1d3B2638a7cC9f2CB3D298A3DA7a90B67E5506ed);
return true;
}
if (getCodeSize(0xc03A2615D5efaf5F49F60B7BB6583eaec212fdf1)>0){ //ropsten testnet
OAR = OraclizeAddrResolverI(0xc03A2615D5efaf5F49F60B7BB6583eaec212fdf1);
return true;
}
if (getCodeSize(0x6f485C8BF6fc43eA212E93BBF8ce046C7f1cb475)>0){ //ethereum-bridge
OAR = OraclizeAddrResolverI(0x6f485C8BF6fc43eA212E93BBF8ce046C7f1cb475);
return true;
}
if (getCodeSize(0x20e12A1F859B3FeaE5Fb2A0A32C18F5a65555bBF)>0){ //ether.camp ide
OAR = OraclizeAddrResolverI(0x20e12A1F859B3FeaE5Fb2A0A32C18F5a65555bBF);
return true;
}
if (getCodeSize(0x51efaF4c8B3C9AfBD5aB9F4bbC82784Ab6ef8fAA)>0){ //browser-solidity
OAR = OraclizeAddrResolverI(0x51efaF4c8B3C9AfBD5aB9F4bbC82784Ab6ef8fAA);
return true;
}
return false;
}
function __callback(bytes32 myid, string result) {
__callback(myid, result, new bytes(0));
}
function __callback(bytes32 myid, string result, bytes proof) {
}
function oraclize_getPrice(string datasource) oraclizeAPI internal returns (uint){
return oraclize.getPrice(datasource);
}
function oraclize_getPrice(string datasource, uint gaslimit) oraclizeAPI internal returns (uint){
return oraclize.getPrice(datasource, gaslimit);
}
function oraclize_query(string datasource, string arg) oraclizeAPI internal returns (bytes32 id){
uint price = oraclize.getPrice(datasource);
if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price
return oraclize.query.value(price)(0, datasource, arg);
}
function oraclize_query(uint timestamp, string datasource, string arg) oraclizeAPI internal returns (bytes32 id){
uint price = oraclize.getPrice(datasource);
if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price
return oraclize.query.value(price)(timestamp, datasource, arg);
}
function oraclize_query(uint timestamp, string datasource, string arg, uint gaslimit) oraclizeAPI internal returns (bytes32 id){
uint price = oraclize.getPrice(datasource, gaslimit);
if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price
return oraclize.query_withGasLimit.value(price)(timestamp, datasource, arg, gaslimit);
}
function oraclize_query(string datasource, string arg, uint gaslimit) oraclizeAPI internal returns (bytes32 id){
uint price = oraclize.getPrice(datasource, gaslimit);
if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price
return oraclize.query_withGasLimit.value(price)(0, datasource, arg, gaslimit);
}
function oraclize_query(string datasource, string arg1, string arg2) oraclizeAPI internal returns (bytes32 id){
uint price = oraclize.getPrice(datasource);
if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price
return oraclize.query2.value(price)(0, datasource, arg1, arg2);
}
function oraclize_query(uint timestamp, string datasource, string arg1, string arg2) oraclizeAPI internal returns (bytes32 id){
uint price = oraclize.getPrice(datasource);
if (price > 1 ether + tx.gasprice*200000) return 0; // unexpectedly high price
return oraclize.query2.value(price)(timestamp, datasource, arg1, arg2);
}
function oraclize_query(uint timestamp, string datasource, string arg1, string arg2, uint gaslimit) oraclizeAPI internal returns (bytes32 id){
uint price = oraclize.getPrice(datasource, gaslimit);
if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price
return oraclize.query2_withGasLimit.value(price)(timestamp, datasource, arg1, arg2, gaslimit);
}
function oraclize_query(string datasource, string arg1, string arg2, uint gaslimit) oraclizeAPI internal returns (bytes32 id){
uint price = oraclize.getPrice(datasource, gaslimit);
if (price > 1 ether + tx.gasprice*gaslimit) return 0; // unexpectedly high price
return oraclize.query2_withGasLimit.value(price)(0, datasource, arg1, arg2, gaslimit);
}
function oraclize_cbAddress() oraclizeAPI internal returns (address){
return oraclize.cbAddress();
}
function oraclize_setProof(byte proofP) oraclizeAPI internal {
return oraclize.setProofType(proofP);
}
function oraclize_setCustomGasPrice(uint gasPrice) oraclizeAPI internal {
return oraclize.setCustomGasPrice(gasPrice);
}
function oraclize_setConfig(bytes32 config) oraclizeAPI internal {
return oraclize.setConfig(config);
}
function getCodeSize(address _addr) constant internal returns(uint _size) {
assembly {
_size := extcodesize(_addr)
}
}
function parseAddr(string _a) internal returns (address){
bytes memory tmp = bytes(_a);
uint160 iaddr = 0;
uint160 b1;
uint160 b2;
for (uint i=2; i<2+2*20; i+=2){
iaddr *= 256;
b1 = uint160(tmp[i]);
b2 = uint160(tmp[i+1]);
if ((b1 >= 97)&&(b1 <= 102)) b1 -= 87;
else if ((b1 >= 48)&&(b1 <= 57)) b1 -= 48;
if ((b2 >= 97)&&(b2 <= 102)) b2 -= 87;
else if ((b2 >= 48)&&(b2 <= 57)) b2 -= 48;
iaddr += (b1*16+b2);
}
return address(iaddr);
}
function strCompare(string _a, string _b) internal returns (int) {
bytes memory a = bytes(_a);
bytes memory b = bytes(_b);
uint minLength = a.length;
if (b.length < minLength) minLength = b.length;
for (uint i = 0; i < minLength; i ++)
if (a[i] < b[i])
return -1;
else if (a[i] > b[i])
return 1;
if (a.length < b.length)
return -1;
else if (a.length > b.length)
return 1;
else
return 0;
}
function indexOf(string _haystack, string _needle) internal returns (int)
{
bytes memory h = bytes(_haystack);
bytes memory n = bytes(_needle);
if(h.length < 1 || n.length < 1 || (n.length > h.length))
return -1;
else if(h.length > (2**128 -1))
return -1;
else
{
uint subindex = 0;
for (uint i = 0; i < h.length; i ++)
{
if (h[i] == n[0])
{
subindex = 1;
while(subindex < n.length && (i + subindex) < h.length && h[i + subindex] == n[subindex])
{
subindex++;
}
if(subindex == n.length)
return int(i);
}
}
return -1;
}
}
function strConcat(string _a, string _b, string _c, string _d, string _e) internal returns (string){
bytes memory _ba = bytes(_a);
bytes memory _bb = bytes(_b);
bytes memory _bc = bytes(_c);
bytes memory _bd = bytes(_d);
bytes memory _be = bytes(_e);
string memory abcde = new string(_ba.length + _bb.length + _bc.length + _bd.length + _be.length);
bytes memory babcde = bytes(abcde);
uint k = 0;
for (uint i = 0; i < _ba.length; i++) babcde[k++] = _ba[i];
for (i = 0; i < _bb.length; i++) babcde[k++] = _bb[i];
for (i = 0; i < _bc.length; i++) babcde[k++] = _bc[i];
for (i = 0; i < _bd.length; i++) babcde[k++] = _bd[i];
for (i = 0; i < _be.length; i++) babcde[k++] = _be[i];
return string(babcde);
}
function strConcat(string _a, string _b, string _c, string _d) internal returns (string) {
return strConcat(_a, _b, _c, _d, "");
}
function strConcat(string _a, string _b, string _c) internal returns (string) {
return strConcat(_a, _b, _c, "", "");
}
function strConcat(string _a, string _b) internal returns (string) {
return strConcat(_a, _b, "", "", "");
}
// parseInt
function parseInt(string _a) internal returns (uint) {
return parseInt(_a, 0);
}
// parseInt(parseFloat*10^_b)
function parseInt(string _a, uint _b) internal returns (uint) {
bytes memory bresult = bytes(_a);
uint mint = 0;
bool decimals = false;
for (uint i=0; i<bresult.length; i++){
if ((bresult[i] >= 48)&&(bresult[i] <= 57)){
if (decimals){
if (_b == 0) break;
else _b--;
}
mint *= 10;
mint += uint(bresult[i]) - 48;
} else if (bresult[i] == 46) decimals = true;
}
if (_b > 0) mint *= 10**_b;
return mint;
}
function uint2str(uint i) internal returns (string){
if (i == 0) return "0";
uint j = i;
uint len;
while (j != 0){
len++;
j /= 10;
}
bytes memory bstr = new bytes(len);
uint k = len - 1;
while (i != 0){
bstr[k--] = byte(48 + i % 10);
i /= 10;
}
return string(bstr);
}
}
// </ORACLIZE_API>
+15
View File
@@ -0,0 +1,15 @@
# Not working due sandbox limitation
# Call method claim(string)
- from: '0x1081108d14493ead0d4071cc757688ed7b111c32'
to: '0x77a0e95b5d58cdb9b54f75e33b8764c87496abd1'
value: '0x16345785d8a0000'
call: claim(string)
args:
- e0a340e72784b1322929d6803773b31a2b6b5707
#transfer 101 eth
- from: '0x1081108d14493ead0d4071cc757688ed7b111c32'
to: '0x77a0e95b5d58cdb9b54f75e33b8764c87496abd1'
value: '0x579a814e10a740000'
data: null
+25
View File
@@ -0,0 +1,25 @@
#
# Create, register user, register repository and claim commits
#
# Created on: 01/03/2017 12:02:15
#
# Call method addRepository(string)
- from: '0x1081108d14493ead0d4071cc757688ed7b111c32'
to: '0x838ef69e5948e423db15757059d538b5bcaf659e'
value: '0x0'
call: addRepository(string)
args:
- ethereans/github-token
# Call method register(string,string)
- from: '0x1081108d14493ead0d4071cc757688ed7b111c32'
to: '0x838ef69e5948e423db15757059d538b5bcaf659e'
value: '0x16345785d8a0000'
call: 'register(string,string)'
args:
- 3esmit
- 31a58f2ddf2258697cce1b969e7c298b
-67
View File
@@ -1,67 +0,0 @@
#
# Create, register user, register repository and claim commits
#
# Created on: 01/03/2017 12:02:15
#
# Call method setAPICredentials(string,string)
- from: '0x1081108d14493ead0d4071cc757688ed7b111c32'
to: '0x838ef69e5948e423db15757059d538b5bcaf659e'
value: '0x0'
call: 'setAPICredentials(string,string)'
args:
- >-
BLX/GHYsFjUNDKfRXSmJAGDrwzO3p1XFpK2DG9nwRHJ0wHMTA7K4wMj+eoKWc6HpkXnxwn/mC8GPsz3bbPnM6luWa7qLHdT94bQX4g19icuzgfm/4BkY6oK/EUhoE8IU34frpF4=
- >-
BEMxXob2oNvdvo44KXhyBgou2xqr0Lits2wCy/OzrAIsfg5HO+GOEhdcEYrEByjhQosAJJX7uvuj7GVH65J8X7IFUFLrvWabWdTmPIEXwXoBGeU67z6SUtzOOgvAvFKixfl8pAWCDacJGZVQOoY+97tq140VAACEOA==
# Create contract GitHubToken
- from: '0x1081108d14493ead0d4071cc757688ed7b111c32'
to: null
value: '0x0'
contract:
name: GitHubToken
dir: contracts/
sources:
- AbtractToken.sol
- GithubToken.sol
- CollaborationToken.sol
- Token.sol
- lib/oraclizeAPI_0.4.sol
args:
- ethereans/github-token
- '0x838ef69e5948e423db15757059d538b5bcaf659e'
# Call method newRepository(string)
- from: '0x1081108d14493ead0d4071cc757688ed7b111c32'
to: '0x838ef69e5948e423db15757059d538b5bcaf659e'
value: '0x0'
call: addRepository(string,address)
args:
- ethereans/github-token
- '0x56ba765b4da244fea35dd74d406220cb2703e478'
# Call method register(string,string)
- from: '0x1081108d14493ead0d4071cc757688ed7b111c32'
to: '0x838ef69e5948e423db15757059d538b5bcaf659e'
value: '0x16345785d8a0000'
call: 'register(string,string)'
args:
- 3esmit
- 31a58f2ddf2258697cce1b969e7c298b
# Call method claim(string)
- from: '0x1081108d14493ead0d4071cc757688ed7b111c32'
to: '0xcb69fe2674a9533ac30acf7a0a2a736f93f67fe1'
value: '0x16345785d8a0000'
call: claim(string)
args:
- e0a340e72784b1322929d6803773b31a2b6b5707
#transfer 101 eth
- from: '0x1081108d14493ead0d4071cc757688ed7b111c32'
to: '0xcb69fe2674a9533ac30acf7a0a2a736f93f67fe1'
value: '0x579a814e10a740000'
data: null
+1 -1
View File
@@ -7,7 +7,7 @@
# Call method transfer(address,uint256)
- from: '0x1081108d14493ead0d4071cc757688ed7b111c32'
to: '0x56ba765b4da244fea35dd74d406220cb2703e478'
to: '0x77a0e95b5d58cdb9b54f75e33b8764c87496abd1'
value: '0x0'
call: 'transfer(address,uint256)'
args:
+5
View File
@@ -0,0 +1,5 @@
FROM ubuntu:14.04
RUN apt-get update && apt-get install -y python
ADD issue_status.py issue_status.py
MAINTAINER Ricardo “3esmit@gmail.com”
CMD python issue_status.py
+24
View File
@@ -0,0 +1,24 @@
import os, sys, json, urllib, datetime
print os.environ['ARG0']
if(len(sys.argv) < 3):
print "too few arguments"
sys.exit()
repo = sys.argv[1]
issue = sys.argv[2]
if(len(sys.argv) < 5):
auth = ""
else:
client_id = sys.argv[3]
client_secret = sys.argv[4]
auth = "?client_id="+client_id+"&client_secret="+client_secret
link_issue = "https://api.github.com/repos/" + repo + "/issues/" + issue + auth
issue = json.load(urllib.urlopen(link_issue))
if(issue['state'] == "closed"):
print datetime.datetime.strptime( json.dumps(issue['closed_at'])[1:-1], "%Y-%m-%dT%H:%M:%SZ" ).strftime('%s') +","+ json.dumps(issue['closed_by']['login'])
else:
print "open"
@@ -0,0 +1,20 @@
import sys
import json
import urllib
from collections import defaultdict
auth = "?client_id=&client_secret="
repo = sys.argv[1]
pr = sys.argv[2]
link_pulls_commits = "https://api.github.com/repos/" + repo + "/pulls/" + pr + "/commits" +auth
points = defaultdict(int)
commits = json.load(urllib.urlopen(link_pulls_commits))
for commit in commits:
if(commit['url']):
link_commit = json.dumps(commit['url'])[1:-1] +auth
_commit = json.load(urllib.urlopen(link_commit))
author = json.dumps(_commit['author']['login'])[1:-1]
points[author] += int(json.dumps(_commit['stats']['total']))
print points.items()