diff --git a/contracts/lib/ethereans/bank/CollaborationBank.sol b/contracts/lib/ethereans/bank/CollaborationBank.sol index 91031cd..cad9581 100644 --- a/contracts/lib/ethereans/bank/CollaborationBank.sol +++ b/contracts/lib/ethereans/bank/CollaborationBank.sol @@ -17,13 +17,13 @@ import "../management/EpochLocker.sol"; import "../token/LockerToken.sol"; contract CollaborationBank is Bank, EpochLocker { - + LockerToken public token; //used for calculating balance and for checking if account withdrawn uint256 public currentPayEpoch; //stores the balance from the lock time uint256 public epochBalance; - //used for hecking if account withdrawn + //used for checking if account withdrawn mapping (address => uint) lastPaidOutEpoch; //events event Withdrawn(address tokenHolder, uint256 amountPaidOut); diff --git a/contracts/lib/ethereans/management/Owned.sol b/contracts/lib/ethereans/management/Owned.sol index 76683cc..141010d 100644 --- a/contracts/lib/ethereans/management/Owned.sol +++ b/contracts/lib/ethereans/management/Owned.sol @@ -3,7 +3,11 @@ pragma solidity ^0.4.8; contract Owned { address public owner= msg.sender; event NewOwner(address owner); - + + function Owned(){ + NewOwner(owner); + } + modifier only_owner { if (msg.sender != owner) throw; _; diff --git a/contracts/src/GitHubOracle.sol b/contracts/src/GitHubOracle.sol index f4a771f..83db21d 100644 --- a/contracts/src/GitHubOracle.sol +++ b/contracts/src/GitHubOracle.sol @@ -20,16 +20,15 @@ import "lib/JSONLib.sol"; import "lib/oraclize/oraclizeAPI_0.4.sol"; import "lib/ethereans/management/Owned.sol"; -import "./git-repository/GitRepositoryFactoryI.sol"; +import "./factory/GRFactory.sol"; +import "./factory/DBFactory.sol"; import "./storage/GitHubOracleStorageI.sol"; - contract GitHubOracle is Owned, usingOraclize { using StringLib for string; - GitRepositoryFactoryI public gitRepositoryFactoryI; GitHubOracleStorageI public db; enum OracleType { SET_REPOSITORY, SET_USER, CLAIM_COMMIT, UPDATE_ISSUE } @@ -53,9 +52,8 @@ contract GitHubOracle is Owned, usingOraclize { string commitid; } - function GitHubOracle(GitHubOracleStorageI _db, GitRepositoryFactoryI _gitRepositoryFactoryI){ // - gitRepositoryFactoryI = _gitRepositoryFactoryI; - db = _db; + function GitHubOracle(){ // + db = DBFactory.newStorage(); } //register or change a github user ethereum address 100000000000000000 @@ -79,7 +77,6 @@ contract GitHubOracle is Owned, usingOraclize { claimType[ocid] = OracleType.SET_REPOSITORY; } - function getRepository(uint projectId) constant returns (address){ return db.getRepositoryAddress(projectId); } @@ -105,14 +102,13 @@ contract GitHubOracle is Owned, usingOraclize { function bountyIssue(uint repositoryId, uint issueId) payable{ - + } //Internal Functions - - // + event OracleEvent(bytes32 myid, string result, bytes proof); //oraclize response callback @@ -148,7 +144,7 @@ contract GitHubOracle is Owned, usingOraclize { } event GitRepositoryRegistered(uint256 projectId, string full_name, uint256 watchers, uint256 subscribers); - function _setRepository(bytes32 myid, string result) //[83725290, "ethereans/github-token", 4, 2] + function _setRepository(bytes32 myid, string result) internal //[83725290, "ethereans/github-token", 4, 2] { uint256 projectId; string memory full_name; uint256 watchers; uint256 subscribers; uint256 ownerId; string memory name; //TODO @@ -161,7 +157,7 @@ contract GitHubOracle is Owned, usingOraclize { address repository = db.getRepositoryAddress(projectId); if(repository == 0x0){ GitRepositoryRegistered(projectId,full_name,watchers,subscribers); - repository = gitRepositoryFactoryI.newGitRepository(projectId,full_name); + repository = GRFactory.newGitRepository(projectId,full_name); db.addRepository(projectId,ownerId,name,full_name,repository); } GitRepositoryI(repository).setStats(subscribers,watchers); diff --git a/contracts/src/factory/DBFactory.sol b/contracts/src/factory/DBFactory.sol new file mode 100644 index 0000000..f9dd043 --- /dev/null +++ b/contracts/src/factory/DBFactory.sol @@ -0,0 +1,18 @@ +pragma solidity ^0.4.8; + +/** + * By Ricardo Guilherme Schmidt + * Released under GPLv3 License + */ + +import "../storage/GitHubOracleStorage.sol"; + + +library DBFactory { + + function newStorage() returns (GitHubOracleStorageI){ + GitHubOracleStorage db = new GitHubOracleStorage(); + return db; + } + +} \ No newline at end of file diff --git a/contracts/src/factory/GRFactory.sol b/contracts/src/factory/GRFactory.sol new file mode 100644 index 0000000..26e799c --- /dev/null +++ b/contracts/src/factory/GRFactory.sol @@ -0,0 +1,20 @@ +pragma solidity ^0.4.8; + +/** + * By Ricardo Guilherme Schmidt + * Released under GPLv3 License + */ + +import "../git-repository/GitRepository.sol"; +//import "./GitRepositoryFactoryI.sol"; + +library GRFactory { + + function newGitRepository(uint256 _uid, string _name) returns (GitRepositoryI){ + GitRepository repo = new GitRepository(_uid,_name); + return repo; + } + + + +} \ No newline at end of file diff --git a/contracts/src/git-repository/GitRepositoryFactory.sol b/contracts/src/git-repository/GitRepositoryFactory.sol deleted file mode 100644 index 1c20269..0000000 --- a/contracts/src/git-repository/GitRepositoryFactory.sol +++ /dev/null @@ -1,19 +0,0 @@ -pragma solidity ^0.4.8; - -/** - * By Ricardo Guilherme Schmidt - * Released under GPLv3 License - */ - -import "./GitRepository.sol"; -import "./GitRepositoryFactoryI.sol"; - -contract GitRepositoryFactory is GitRepositoryFactoryI { - - function newGitRepository(uint256 _uid, string _name) external returns (GitRepositoryI){ - GitRepository repo = new GitRepository(_uid,_name); - repo.setOwner(msg.sender); - return GitRepositoryI(repo); - } - -} \ No newline at end of file diff --git a/contracts/tests/index.test.js b/contracts/tests/index.test.js new file mode 100644 index 0000000..9dc9a79 --- /dev/null +++ b/contracts/tests/index.test.js @@ -0,0 +1,36 @@ +var assert = require('assert'); +var helper = require('ethereum-sandbox-helper'); +var Workbench = require('ethereum-sandbox-workbench'); + +var workbench = new Workbench({ + contractsDirectory: 'contracts', + solcVersion: '0.4.2', + defaults: { + from: '0xcd2a3d9f938e13cd947ec05abc7fe734df8dd826' + } +}); + +var contract; + +workbench.startTesting('contract', function(contracts) { + it('Deploy Contract', function() { + return contracts.Contract.new() + .then(function(result) { + if (result.address) contract = result; + else throw new Error('Contract is not deployed'); + return true; + }); + }); + + it('Prints string', function() { + var str = "hello, ethereum!"; + return contract.test(str) + .then(function(txHash) { + return workbench.waitForReceipt(txHash); + }) + .then(function (receipt) { + assert.equal(helper.hexToString(receipt.logs[0].data), str); + return true; + }); + }); +}); diff --git a/ethereum.json b/ethereum.json index 5501975..4735066 100644 --- a/ethereum.json +++ b/ethereum.json @@ -1,7 +1,7 @@ { "contracts": "contracts", - "deploy": ["GitHubOracleStorage", "GitRepositoryFactory", "GitHubOracle"], + "deploy": ["GitHubOracle"], "plugins": { "oraclize": { diff --git a/scenarios/DeployRegClaim.yaml b/scenarios/DeployRegClaim.yaml deleted file mode 100644 index 9b70d55..0000000 --- a/scenarios/DeployRegClaim.yaml +++ /dev/null @@ -1,143 +0,0 @@ -# -# Scenario3 -# -# Created on: 20/03/2017 02:44:46 -# - -# Create contract GitRepositoryFactory -- from: '0xdedb49385ad5b94a16f236a6890cf9e0b1e30392' - to: null - value: '0x0' - contract: - name: GitRepositoryFactory - dir: contracts/ - sources: - - lib/ethereans/bank/Bank.sol - - lib/ethereans/management/Owned.sol - - lib/ethereans/management/Secret.sol - - lib/ethereans/token/AbstractToken.sol - - lib/ethereans/token/CollaborationToken.sol - - lib/ethereans/token/JustifiedCollaborationToken.sol - - lib/ethereans/token/Token.sol - - lib/ethereans/token/WrappedEthToken.sol - - lib/ethereans/util/Bytes32Lib.sol - - lib/ethereans/util/IntLib.sol - - lib/JSONLib.sol - - lib/StringLib.sol - - lib/oraclize/oraclizeAPI_0.4.sol - - src/AbstractBounty.sol - - src/GitHubIssues.sol - - src/GitHubOracle.sol - - src/git-repository/GitRepository.sol - - src/git-repository/GitRepositoryFactory.sol - - src/git-repository/GitRepositoryFactoryI.sol - - src/git-repository/GitRepositoryI.sol - - src/git-repository/GitRepositoryStorage.sol - - src/git-repository/GitRepositoryToken.sol - - src/storage/GitHubOracleStorage.sol - - src/storage/GitHubOracleStorageI.sol - args: [] - -# Create contract GitHubOracleStorage -- from: '0xdedb49385ad5b94a16f236a6890cf9e0b1e30392' - to: null - value: '0x0' - contract: - name: GitHubOracleStorage - dir: contracts/ - sources: - - lib/ethereans/bank/Bank.sol - - lib/ethereans/management/Owned.sol - - lib/ethereans/management/Secret.sol - - lib/ethereans/token/AbstractToken.sol - - lib/ethereans/token/CollaborationToken.sol - - lib/ethereans/token/JustifiedCollaborationToken.sol - - lib/ethereans/token/Token.sol - - lib/ethereans/token/WrappedEthToken.sol - - lib/ethereans/util/Bytes32Lib.sol - - lib/ethereans/util/IntLib.sol - - lib/JSONLib.sol - - lib/StringLib.sol - - lib/oraclize/oraclizeAPI_0.4.sol - - src/AbstractBounty.sol - - src/GitHubIssues.sol - - src/GitHubOracle.sol - - src/git-repository/GitRepository.sol - - src/git-repository/GitRepositoryFactory.sol - - src/git-repository/GitRepositoryFactoryI.sol - - src/git-repository/GitRepositoryI.sol - - src/git-repository/GitRepositoryStorage.sol - - src/git-repository/GitRepositoryToken.sol - - src/storage/GitHubOracleStorage.sol - - src/storage/GitHubOracleStorageI.sol - args: [] - -# Create contract GitHubOracle -- from: '0xdedb49385ad5b94a16f236a6890cf9e0b1e30392' - to: null - value: '0x0' - contract: - name: GitHubOracle - dir: contracts/ - sources: - - lib/ethereans/bank/Bank.sol - - lib/ethereans/management/Owned.sol - - lib/ethereans/management/Secret.sol - - lib/ethereans/token/AbstractToken.sol - - lib/ethereans/token/CollaborationToken.sol - - lib/ethereans/token/JustifiedCollaborationToken.sol - - lib/ethereans/token/Token.sol - - lib/ethereans/token/WrappedEthToken.sol - - lib/ethereans/util/Bytes32Lib.sol - - lib/ethereans/util/IntLib.sol - - lib/JSONLib.sol - - lib/StringLib.sol - - lib/oraclize/oraclizeAPI_0.4.sol - - src/AbstractBounty.sol - - src/GitHubIssues.sol - - src/GitHubOracle.sol - - src/git-repository/GitRepository.sol - - src/git-repository/GitRepositoryFactory.sol - - src/git-repository/GitRepositoryFactoryI.sol - - src/git-repository/GitRepositoryI.sol - - src/git-repository/GitRepositoryStorage.sol - - src/git-repository/GitRepositoryToken.sol - - src/storage/GitHubOracleStorage.sol - - src/storage/GitHubOracleStorageI.sol - args: - - '0xdf315f7485c3a86eb692487588735f224482abe3' - - '0x17956ba5f4291844bc25aedb27e69bc11b5bda39' - -# Call method setOwner(address) -- from: '0xdedb49385ad5b94a16f236a6890cf9e0b1e30392' - to: '0xdf315f7485c3a86eb692487588735f224482abe3' - value: '0x0' - call: setOwner(address) - args: - - '0x06b179aabf198ced0f98c8ceca905a920a137ef4' - -# Call method addRepository(string) -- from: '0xdedb49385ad5b94a16f236a6890cf9e0b1e30392' - to: '0x06b179aabf198ced0f98c8ceca905a920a137ef4' - value: '0x16345785d8a0000' - call: addRepository(string) - args: - - ethereans/github-token - -# Call method register(string,string) -- from: '0xdedb49385ad5b94a16f236a6890cf9e0b1e30392' - to: '0x06b179aabf198ced0f98c8ceca905a920a137ef4' - value: '0x38D7EA4C68000' - call: 'register(string,string)' - args: - - 3esmit - - 31a58f2ddf2258697cce1b969e7c298b - -# Call method claimCommit(string,string) -- from: '0xdedb49385ad5b94a16f236a6890cf9e0b1e30392' - to: '0x06b179aabf198ced0f98c8ceca905a920a137ef4' - value: '0x2386f26fc10000' - call: 'claimCommit(string,string)' - args: - - ethereans/github-token - - 09ba429f22eec6cefcfa7a862f60b9d4cc1cfa14 \ No newline at end of file diff --git a/scenarios/RegisterClaim.yaml b/scenarios/RegisterClaim.yaml new file mode 100644 index 0000000..14f63d8 --- /dev/null +++ b/scenarios/RegisterClaim.yaml @@ -0,0 +1,31 @@ +# +# Scenario1 +# +# Created on: 26/03/2017 03:32:05 +# + +# Call method addRepository(string) +- from: '0xdedb49385ad5b94a16f236a6890cf9e0b1e30392' + to: '0xaefa01276783e1436e5b461c099edccb0448dcf6' + value: '0x16345785d8a0000' + call: addRepository(string) + args: + - status-im/github-oracle + +# Call method register(string,string) +- from: '0xdedb49385ad5b94a16f236a6890cf9e0b1e30392' + to: '0xaefa01276783e1436e5b461c099edccb0448dcf6' + value: '0x0' + call: 'register(string,string)' + args: + - 3esmit + - 31a58f2ddf2258697cce1b969e7c298b + +# Call method claimCommit(string,string) +- from: '0xdedb49385ad5b94a16f236a6890cf9e0b1e30392' + to: '0xaefa01276783e1436e5b461c099edccb0448dcf6' + value: '0x0' + call: 'claimCommit(string,string)' + args: + - status-im/github-oracle + - 3c461c5bfe3107923a13270f7037854f1ae8ca36