From 7f300067034658898a4cadee056ebfc2543065ba Mon Sep 17 00:00:00 2001 From: bumi Date: Tue, 10 Apr 2018 16:25:17 +0200 Subject: [PATCH 01/11] More consistent contract parameter naming --- contracts/Operator.sol | 62 ++++++++++++++---------------------------- contracts/Token.sol | 9 +++--- 2 files changed, 25 insertions(+), 46 deletions(-) diff --git a/contracts/Operator.sol b/contracts/Operator.sol index 7b4fc6f..76fe3bd 100644 --- a/contracts/Operator.sol +++ b/contracts/Operator.sol @@ -24,9 +24,9 @@ contract Operator is Upgradeable { mapping(uint256 => Proposal) public proposals; uint256 public proposalsCount; - event ProposalCreated(uint256 id, address creator, uint recipient, uint256 amount); + event ProposalCreated(uint256 id, address creator, uint recipientId, uint256 amount); event ProposalVoted(uint256 id, address voter, uint256 totalVotes); - event ProposalExecuted(uint256 id, uint recipient, uint256 amount); + event ProposalExecuted(uint256 id, uint recipientId, uint256 amount); modifier coreOnly() { require(contributorsContract().addressIsCore(msg.sender)); @@ -55,45 +55,29 @@ contract Operator is Upgradeable { return contributorsContract().coreContributorsCount(); } - function addContributor(address _address, bytes32 _ipfsHash, uint8 _hashFunction, uint8 _hashSize, bool _isCore) public coreOnly { - contributorsContract().addContributor(_address, _ipfsHash, _hashFunction, _hashSize, _isCore); - } - - function updateContributorIpfsHash(uint _id, bytes32 _ipfsHash, uint8 _hashFunction, uint8 _hashSize) public coreOnly { - contributorsContract().updateContributorIpfsHash(_id, _ipfsHash, _hashFunction, _hashSize); - } - - function getContributor(uint _id) view public returns (address account, bytes32 ipfsHash, uint8 hashFunction, uint8 hashSize, bool isCore) { - bool exists; - - (account, ipfsHash, hashFunction, hashSize, isCore, exists) = contributorsContract().contributors(_id); - - require(exists); - } - - function addProposal(uint _recipient, uint256 _amount, bytes32 _ipfsHash, uint8 _hashFunction, uint8 _hashSize) public returns (uint256 proposalId) { - require(contributorsContract().exists(_recipient)); + function addProposal(uint recipientId, uint256 amount, bytes32 ipfsHash, uint8 hashFunction, uint8 hashSize) public returns { + require(contributorsContract().exists(recipientId)); proposalId = proposalsCount + 1; uint _votesNeeded = contributorsContract().coreContributorsCount() / 100 * 75; var p = proposals[proposalId]; p.creator = msg.sender; - p.recipientId = _recipient; - p.amount = _amount; - p.ipfsHash = _ipfsHash; - p.hashFunction = _hashFunction; - p.hashSize = _hashSize; + p.recipientId = recipientId; + p.amount = amount; + p.ipfsHash = ipfsHash; + p.hashFunction = hashFunction; + p.hashSize = hashSize; p.votesCount = 0; - p.votesNeeded = _votesNeeded; + p.votesNeeded = votesNeeded; p.exists = true; proposalsCount++; ProposalCreated(proposalId, msg.sender, p.recipientId, p.amount); } - function getProposal(uint _proposalId) public view returns (address creator, uint256 recipientId, uint256 votesCount, uint256 votesNeeded, uint256 amount, bool executed, bytes32 ipfsHash, uint8 hashFunction, uint8 hashSize, uint256[] voterIds, bool exists) { - Proposal storage p = proposals[_proposalId]; + function getProposal(uint id) public view returns (address creator, uint256 recipientId, uint256 votesCount, uint256 votesNeeded, uint256 amount, bool executed, bytes32 ipfsHash, uint8 hashFunction, uint8 hashSize, uint256[] voterIds, bool exists) { + Proposal storage p = proposals[id]; return ( p.creator, p.recipientId, @@ -109,25 +93,22 @@ contract Operator is Upgradeable { ); } - function vote(uint256 _proposalId) public coreOnly returns (uint _pId, bool _executed) { - var p = proposals[_proposalId]; + function vote(uint256 proposalId) public coreOnly { + var p = proposals[proposalId]; require(!p.executed); - uint256 contributorId = contributorsContract().getContributorIdByAddress(msg.sender); - require(p.votes[contributorId] != true); - p.voterIds.push(contributorId); - p.votes[contributorId] = true; + uint256 voterId = contributorsContract().getContributorIdByAddress(msg.sender); + require(p.votes[voterId] != true); + p.voterIds.push(voterId); + p.votes[voterId] = true; p.votesCount++; - _executed = false; - _pId = _proposalId; if (p.votesCount >= p.votesNeeded) { - executeProposal(_proposalId); - _executed = true; + executeProposal(proposalId); } - ProposalVoted(_pId, msg.sender, p.votesCount); + ProposalVoted(proposalId, msg.sender, p.votesCount); } - function executeProposal(uint proposalId) private returns (bool) { + function executeProposal(uint proposalId) private { var p = proposals[proposalId]; require(!p.executed); require(p.votesCount >= p.votesNeeded); @@ -135,7 +116,6 @@ contract Operator is Upgradeable { tokenContract().mintFor(recipientAddress, p.amount, proposalId); p.executed = true; ProposalExecuted(proposalId, p.recipientId, p.amount); - return true; } } diff --git a/contracts/Token.sol b/contracts/Token.sol index d892165..3ce085b 100644 --- a/contracts/Token.sol +++ b/contracts/Token.sol @@ -17,12 +17,11 @@ contract Token is Upgradeable, BasicToken { decimals = 18; } - function mintFor(address _recipient, uint256 _amount, uint _proposalId) onlyRegistryContractFor('Operator') public returns (bool success) { - totalSupply_ = totalSupply_.add(_amount); - balances[_recipient] = balances[_recipient].add(_amount); + function mintFor(address recipientAddress, uint256 amount, uint proposalId) onlyRegistryContractFor('Operator') public { + totalSupply_ = totalSupply_.add(amount); + balances[recipientAddress] = balances[recipientAddress].add(amount); - LogMint(_recipient, _amount, _proposalId); - return true; + LogMint(recipientAddress, amount, proposalId); } } -- 2.25.1 From 147904e2378d04a11d5790a10356df9b1986b107 Mon Sep 17 00:00:00 2001 From: bumi Date: Tue, 10 Apr 2018 16:40:11 +0200 Subject: [PATCH 02/11] maybe more consitent --- contracts/Operator.sol | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/contracts/Operator.sol b/contracts/Operator.sol index 76fe3bd..79d070f 100644 --- a/contracts/Operator.sol +++ b/contracts/Operator.sol @@ -76,7 +76,8 @@ contract Operator is Upgradeable { ProposalCreated(proposalId, msg.sender, p.recipientId, p.amount); } - function getProposal(uint id) public view returns (address creator, uint256 recipientId, uint256 votesCount, uint256 votesNeeded, uint256 amount, bool executed, bytes32 ipfsHash, uint8 hashFunction, uint8 hashSize, uint256[] voterIds, bool exists) { + function getProposal(uint proposalId) public view returns (uint256 id, address creator, uint256 recipientId, uint256 votesCount, uint256 votesNeeded, uint256 amount, bool executed, bytes32 ipfsHash, uint8 hashFunction, uint8 hashSize, uint256[] voterIds, bool exists) { + id = proposalId; Proposal storage p = proposals[id]; return ( p.creator, -- 2.25.1 From e116e7ebf3f52f78eefa416c7ab24a5d9f9cfe87 Mon Sep 17 00:00:00 2001 From: bumi Date: Tue, 10 Apr 2018 17:49:16 +0200 Subject: [PATCH 03/11] Use new naming convention to call address things accounts So here we use creatorAccount - similar to proposalId. Like this we will always have an *Account or *Id as identifier. --- contracts/Operator.sol | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/contracts/Operator.sol b/contracts/Operator.sol index 79d070f..dc3bf46 100644 --- a/contracts/Operator.sol +++ b/contracts/Operator.sol @@ -7,7 +7,7 @@ import './Contributors.sol'; contract Operator is Upgradeable { struct Proposal { - address creator; + address creatorAccount; uint recipientId; uint votesCount; uint votesNeeded; @@ -24,9 +24,9 @@ contract Operator is Upgradeable { mapping(uint256 => Proposal) public proposals; uint256 public proposalsCount; - event ProposalCreated(uint256 id, address creator, uint recipientId, uint256 amount); - event ProposalVoted(uint256 id, address voter, uint256 totalVotes); - event ProposalExecuted(uint256 id, uint recipientId, uint256 amount); + event ProposalCreated(uint256 id, address creatorAccount, uint256 recipientId, uint256 amount); + event ProposalVoted(uint256 id, uint256 contributorId, uint256 totalVotes); + event ProposalExecuted(uint256 id, uint256 recipientId, uint256 amount); modifier coreOnly() { require(contributorsContract().addressIsCore(msg.sender)); @@ -62,7 +62,7 @@ contract Operator is Upgradeable { uint _votesNeeded = contributorsContract().coreContributorsCount() / 100 * 75; var p = proposals[proposalId]; - p.creator = msg.sender; + p.creatorAccount = msg.sender; p.recipientId = recipientId; p.amount = amount; p.ipfsHash = ipfsHash; @@ -106,7 +106,7 @@ contract Operator is Upgradeable { if (p.votesCount >= p.votesNeeded) { executeProposal(proposalId); } - ProposalVoted(proposalId, msg.sender, p.votesCount); + ProposalVoted(proposalId, voterId, p.votesCount); } function executeProposal(uint proposalId) private { -- 2.25.1 From b85117835dd36c24bc20ab244afc4f8ff2033ab7 Mon Sep 17 00:00:00 2001 From: bumi Date: Tue, 10 Apr 2018 18:02:00 +0200 Subject: [PATCH 04/11] update contributor account vs. address --- contracts/Contributors.sol | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contracts/Contributors.sol b/contracts/Contributors.sol index d876979..939d02b 100644 --- a/contracts/Contributors.sol +++ b/contracts/Contributors.sol @@ -49,7 +49,7 @@ contract Contributors is Upgradeable { return count; } - function updateContributorAddress(uint id, address oldAccount, address newAccount) public onlyCoreOrOperator { + function updateContributorAccount(uint id, address oldAccount, address newAccount) public onlyCoreOrOperator { contributorIds[oldAccount] = 0; contributorIds[newAccount] = id; contributors[id].account = newAccount; -- 2.25.1 From 3a0350d581f5d0438ce023dcab0a62b2c21b3820 Mon Sep 17 00:00:00 2001 From: bumi Date: Tue, 10 Apr 2018 18:16:19 +0200 Subject: [PATCH 05/11] Fix --- contracts/Operator.sol | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/contracts/Operator.sol b/contracts/Operator.sol index dc3bf46..cff99e6 100644 --- a/contracts/Operator.sol +++ b/contracts/Operator.sol @@ -55,11 +55,11 @@ contract Operator is Upgradeable { return contributorsContract().coreContributorsCount(); } - function addProposal(uint recipientId, uint256 amount, bytes32 ipfsHash, uint8 hashFunction, uint8 hashSize) public returns { + function addProposal(uint recipientId, uint256 amount, bytes32 ipfsHash, uint8 hashFunction, uint8 hashSize) public { require(contributorsContract().exists(recipientId)); - proposalId = proposalsCount + 1; - uint _votesNeeded = contributorsContract().coreContributorsCount() / 100 * 75; + uint256 proposalId = proposalsCount + 1; + uint256 _votesNeeded = contributorsContract().coreContributorsCount() / 100 * 75; var p = proposals[proposalId]; p.creatorAccount = msg.sender; @@ -69,18 +69,19 @@ contract Operator is Upgradeable { p.hashFunction = hashFunction; p.hashSize = hashSize; p.votesCount = 0; - p.votesNeeded = votesNeeded; + p.votesNeeded = _votesNeeded; p.exists = true; proposalsCount++; ProposalCreated(proposalId, msg.sender, p.recipientId, p.amount); } - function getProposal(uint proposalId) public view returns (uint256 id, address creator, uint256 recipientId, uint256 votesCount, uint256 votesNeeded, uint256 amount, bool executed, bytes32 ipfsHash, uint8 hashFunction, uint8 hashSize, uint256[] voterIds, bool exists) { + function getProposal(uint proposalId) public view returns (uint256 id, address creatorAccount, uint256 recipientId, uint256 votesCount, uint256 votesNeeded, uint256 amount, bool executed, bytes32 ipfsHash, uint8 hashFunction, uint8 hashSize, uint256[] voterIds, bool exists) { id = proposalId; Proposal storage p = proposals[id]; return ( - p.creator, + id, + p.creatorAccount, p.recipientId, p.votesCount, p.votesNeeded, -- 2.25.1 From 4fd35a86c8aac68081bacf28646a65b8388ec9be Mon Sep 17 00:00:00 2001 From: bumi Date: Sun, 15 Apr 2018 19:35:30 +0200 Subject: [PATCH 06/11] update seeds --- config/seeds.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/config/seeds.js b/config/seeds.js index 90badf1..ae3403a 100644 --- a/config/seeds.js +++ b/config/seeds.js @@ -8,9 +8,9 @@ let contractCalls = { }, Operator: { addProposal: [ - [1, 23, '0x1e1a168d736fc825213144973a8fd5b3cc9f37ad821a8b3d9c3488034bbf69d8', 18, 32], // QmQNA1hhVyL1Vm6HiRxXe9xmc6LUMBDyiNMVgsjThtyevs" - [2, 42, '0x1e1a168d736fc825213144973a8fd5b3cc9f37ad821a8b3d9c3488034bbf69d8', 18, 32], // QmQNA1hhVyL1Vm6HiRxXe9xmc6LUMBDyiNMVgsjThtyevs" - [2, 100, '0x1e1a168d736fc825213144973a8fd5b3cc9f37ad821a8b3d9c3488034bbf69d8', 18, 32] // QmQNA1hhVyL1Vm6HiRxXe9xmc6LUMBDyiNMVgsjThtyevs" + [2, 23, '0x1e1a168d736fc825213144973a8fd5b3cc9f37ad821a8b3d9c3488034bbf69d8', 18, 32], // QmQNA1hhVyL1Vm6HiRxXe9xmc6LUMBDyiNMVgsjThtyevs" + [3, 42, '0x1e1a168d736fc825213144973a8fd5b3cc9f37ad821a8b3d9c3488034bbf69d8', 18, 32], // QmQNA1hhVyL1Vm6HiRxXe9xmc6LUMBDyiNMVgsjThtyevs" + [3, 100, '0x1e1a168d736fc825213144973a8fd5b3cc9f37ad821a8b3d9c3488034bbf69d8', 18, 32] // QmQNA1hhVyL1Vm6HiRxXe9xmc6LUMBDyiNMVgsjThtyevs" ], vote: [ [1] -- 2.25.1 From d7c8ee46bdf941ea18651401d135c0c9417b6c2f Mon Sep 17 00:00:00 2001 From: bumi Date: Sun, 15 Apr 2018 19:58:28 +0200 Subject: [PATCH 07/11] Rename recipientId to contributorId in Operator --- contracts/Operator.sol | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/contracts/Operator.sol b/contracts/Operator.sol index cff99e6..45541ba 100644 --- a/contracts/Operator.sol +++ b/contracts/Operator.sol @@ -8,7 +8,7 @@ contract Operator is Upgradeable { struct Proposal { address creatorAccount; - uint recipientId; + uint contributorId; uint votesCount; uint votesNeeded; uint256 amount; @@ -24,9 +24,9 @@ contract Operator is Upgradeable { mapping(uint256 => Proposal) public proposals; uint256 public proposalsCount; - event ProposalCreated(uint256 id, address creatorAccount, uint256 recipientId, uint256 amount); - event ProposalVoted(uint256 id, uint256 contributorId, uint256 totalVotes); - event ProposalExecuted(uint256 id, uint256 recipientId, uint256 amount); + event ProposalCreated(uint256 id, address creatorAccount, uint256 contributorId, uint256 amount); + event ProposalVoted(uint256 id, uint256 voterId, uint256 totalVotes); + event ProposalExecuted(uint256 id, uint256 contributorId, uint256 amount); modifier coreOnly() { require(contributorsContract().addressIsCore(msg.sender)); @@ -55,15 +55,15 @@ contract Operator is Upgradeable { return contributorsContract().coreContributorsCount(); } - function addProposal(uint recipientId, uint256 amount, bytes32 ipfsHash, uint8 hashFunction, uint8 hashSize) public { - require(contributorsContract().exists(recipientId)); + function addProposal(uint contributorId, uint256 amount, bytes32 ipfsHash, uint8 hashFunction, uint8 hashSize) public { + require(contributorsContract().exists(contributorId)); uint256 proposalId = proposalsCount + 1; uint256 _votesNeeded = contributorsContract().coreContributorsCount() / 100 * 75; var p = proposals[proposalId]; p.creatorAccount = msg.sender; - p.recipientId = recipientId; + p.contributorId = contributorId; p.amount = amount; p.ipfsHash = ipfsHash; p.hashFunction = hashFunction; @@ -73,16 +73,16 @@ contract Operator is Upgradeable { p.exists = true; proposalsCount++; - ProposalCreated(proposalId, msg.sender, p.recipientId, p.amount); + ProposalCreated(proposalId, msg.sender, p.contributorId, p.amount); } - function getProposal(uint proposalId) public view returns (uint256 id, address creatorAccount, uint256 recipientId, uint256 votesCount, uint256 votesNeeded, uint256 amount, bool executed, bytes32 ipfsHash, uint8 hashFunction, uint8 hashSize, uint256[] voterIds, bool exists) { + function getProposal(uint proposalId) public view returns (uint256 id, address creatorAccount, uint256 contributorId, uint256 votesCount, uint256 votesNeeded, uint256 amount, bool executed, bytes32 ipfsHash, uint8 hashFunction, uint8 hashSize, uint256[] voterIds, bool exists) { id = proposalId; Proposal storage p = proposals[id]; return ( id, p.creatorAccount, - p.recipientId, + p.contributorId, p.votesCount, p.votesNeeded, p.amount, @@ -114,10 +114,10 @@ contract Operator is Upgradeable { var p = proposals[proposalId]; require(!p.executed); require(p.votesCount >= p.votesNeeded); - address recipientAddress = contributorsContract().getContributorAddressById(p.recipientId); + address recipientAddress = contributorsContract().getContributorAddressById(p.contributorId); tokenContract().mintFor(recipientAddress, p.amount, proposalId); p.executed = true; - ProposalExecuted(proposalId, p.recipientId, p.amount); + ProposalExecuted(proposalId, p.contributorId, p.amount); } } -- 2.25.1 From 9e57567cd3250396f1364957deb9551be3fca7b9 Mon Sep 17 00:00:00 2001 From: bumi Date: Sun, 15 Apr 2018 20:21:49 +0200 Subject: [PATCH 08/11] rename recipent to contributor in token contract --- contracts/Token.sol | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/contracts/Token.sol b/contracts/Token.sol index 3ce085b..9d81a9f 100644 --- a/contracts/Token.sol +++ b/contracts/Token.sol @@ -17,11 +17,11 @@ contract Token is Upgradeable, BasicToken { decimals = 18; } - function mintFor(address recipientAddress, uint256 amount, uint proposalId) onlyRegistryContractFor('Operator') public { + function mintFor(address contributorAccount, uint256 amount, uint proposalId) onlyRegistryContractFor('Operator') public { totalSupply_ = totalSupply_.add(amount); - balances[recipientAddress] = balances[recipientAddress].add(amount); + balances[contributorAccount] = balances[contributorAccount].add(amount); - LogMint(recipientAddress, amount, proposalId); + LogMint(contributorAccount, amount, proposalId); } } -- 2.25.1 From 4b1cbbd0f7540b11ef638c53c86a27905ff47d05 Mon Sep 17 00:00:00 2001 From: bumi Date: Sun, 15 Apr 2018 21:03:12 +0200 Subject: [PATCH 09/11] Persist ganache DB and use fixed Mnemonic This persists the state of the ganache db and uses a fixed mnemonic code to create accounts. It now acts more like a local presistent database and no need to send funds to the accounts after restart. --- .gitignore | 3 ++- package.json | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 48912d2..697f31a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ build -node_modules \ No newline at end of file +node_modules +.ganache-db \ No newline at end of file diff --git a/package.json b/package.json index b97dd9c..f5c22e7 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "scripts": { "build-json": "truffle compile && node ./scripts/build-json.js", "bootstrap": "truffle migrate --reset && truffle exec scripts/seeds.js && npm run build-json", - "ganache": "ganache-cli -p 7545 -i 100", + "ganache": "ganache-cli -p 7545 -i 100 --db=./.ganache-db -m kredits", "dev": "truffle migrate && npm run build-json", "test": "echo \"Error: no test specified\" && exit 1" }, -- 2.25.1 From 64ce554c492c11b4ef200a7a995d63801e9d0e8b Mon Sep 17 00:00:00 2001 From: bumi Date: Mon, 16 Apr 2018 11:01:43 +0200 Subject: [PATCH 10/11] readme --- README.mdown | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/README.mdown b/README.mdown index 48517ef..95143bc 100644 --- a/README.mdown +++ b/README.mdown @@ -22,11 +22,18 @@ We use following solidity contract libraries: For local development it is recommended to use [ganache-cli](https://github.com/trufflesuite/ganache-cli) (or the [ganache GUI](http://truffleframework.com/ganache/) to run a local development chain. Using the ganache simulator no full Ethereum node is required. -We default to the port 7545 for development to not get in conflict with the default Ethereum RPC port. Have a look at `ganache-cli` for more configuration options. +We default to: + +* port 7545 for development to not get in conflict with the default Ethereum RPC port. +* network ID 100 to stay on the same network id +* store ganache data in .ganache-db to presist the chain data across restarts +* use a fixed Mnemonic code to get the same accounts across restarts + +Have a look at `ganache-cli` for more configuration options. Run your ganache simulator before using Kredits locally: - $ ganache-cli -p 7545 + $ npm run ganache (which is: ganache-cli -p 7545 -i 100 --db=./.ganache-db -m kredits) ### Truffle console -- 2.25.1 From f2fc9fd1610b17bd8e032f9a80970fe7d524c474 Mon Sep 17 00:00:00 2001 From: Sebastian Kippe Date: Tue, 17 Apr 2018 13:13:52 +0200 Subject: [PATCH 11/11] Add empty Ganache DB directory --- .ganache-db/.gitkeep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 .ganache-db/.gitkeep diff --git a/.ganache-db/.gitkeep b/.ganache-db/.gitkeep new file mode 100644 index 0000000..e69de29 -- 2.25.1