diff --git a/apps/proposal/contracts/Proposal.sol b/apps/proposal/contracts/Proposal.sol index a0d808f..de89a51 100644 --- a/apps/proposal/contracts/Proposal.sol +++ b/apps/proposal/contracts/Proposal.sol @@ -4,13 +4,13 @@ import "@aragon/os/contracts/apps/AragonApp.sol"; import "@aragon/os/contracts/kernel/IKernel.sol"; interface IContributor { - function getContributorAddressById(uint256 contributorId) public view returns (address); - function getContributorIdByAddress(address contributorAccount) public view returns (uint256); - function exists(uint256 contributorId) public view returns (bool); + function getContributorAddressById(uint32 contributorId) public view returns (address); + function getContributorIdByAddress(address contributorAccount) public view returns (uint32); + function exists(uint32 contributorId) public view returns (bool); } interface IContribution { - function add(uint256 amount, address contributor, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize) public; + function add(uint32 amount, uint32 contributorId, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize) public; } contract Proposal is AragonApp { @@ -25,26 +25,26 @@ contract Proposal is AragonApp { struct Proposal { address creatorAccount; - uint contributorId; - uint votesCount; - uint votesNeeded; - uint256 amount; + uint32 contributorId; + uint16 votesCount; + uint16 votesNeeded; + uint32 amount; bool executed; bytes32 hashDigest; uint8 hashFunction; uint8 hashSize; - uint256[] voterIds; - mapping (uint256 => bool) votes; + uint32[] voterIds; + mapping (uint32 => bool) votes; bool exists; } - mapping(uint256 => Proposal) public proposals; - uint256 public proposalsCount; + mapping(uint32 => Proposal) public proposals; + uint32 public proposalsCount; - event ProposalCreated(uint256 id, address creatorAccount, uint256 contributorId, uint256 amount); + event ProposalCreated(uint32 id, address creatorAccount, uint32 contributorId, uint32 amount); - event ProposalVoted(uint256 id, uint256 voterId, uint256 totalVotes); - event ProposalExecuted(uint256 id, uint256 contributorId, uint256 amount); + event ProposalVoted(uint32 id, uint32 voterId, uint16 totalVotes); + event ProposalExecuted(uint32 id, uint32 contributorId, uint32 amount); function initialize(bytes32[4] _appIds) public onlyInit { appIds = _appIds; @@ -59,11 +59,11 @@ contract Proposal is AragonApp { return IKernel(kernel()).getApp(KERNEL_APP_ADDR_NAMESPACE, appIds[uint8(Apps.Contribution)]); } - function addProposal(uint contributorId, uint256 amount, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize) public isInitialized auth(ADD_PROPOSAL_ROLE) { + function addProposal(uint32 contributorId, uint32 amount, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize) public isInitialized auth(ADD_PROPOSAL_ROLE) { require(IContributor(getContributorContract()).exists(contributorId), 'CONTRIBUTOR_NOT_FOUND'); - uint256 proposalId = proposalsCount + 1; - uint256 _votesNeeded = 1; //contributorsContract().coreContributorsCount() / 100 * 75; + uint32 proposalId = proposalsCount + 1; + uint16 _votesNeeded = 1; //contributorsContract().coreContributorsCount() / 100 * 75; Proposal storage p = proposals[proposalId]; p.creatorAccount = msg.sender; @@ -75,23 +75,23 @@ contract Proposal is AragonApp { p.votesCount = 0; p.votesNeeded = _votesNeeded; p.exists = true; - + proposalsCount++; emit ProposalCreated(proposalId, msg.sender, p.contributorId, p.amount); } - function getProposal(uint proposalId) public view returns (uint256 id, address creatorAccount, uint256 contributorId, uint256 votesCount, uint256 votesNeeded, uint256 amount, bool executed, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize, uint256[] voterIds, bool exists) { + function getProposal(uint32 proposalId) public view returns (uint32 id, address creatorAccount, uint32 contributorId, uint16 votesCount, uint16 votesNeeded, uint32 amount, bool executed, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize, uint32[] voterIds, bool exists) { id = proposalId; Proposal storage p = proposals[id]; return ( id, p.creatorAccount, - p.contributorId, - p.votesCount, + p.contributorId, + p.votesCount, p.votesNeeded, p.amount, - p.executed, - p.hashDigest, + p.executed, + p.hashDigest, p.hashFunction, p.hashSize, p.voterIds, @@ -99,10 +99,10 @@ contract Proposal is AragonApp { ); } - function vote(uint256 proposalId) public isInitialized auth(VOTE_PROPOSAL_ROLE) { + function vote(uint32 proposalId) public isInitialized auth(VOTE_PROPOSAL_ROLE) { Proposal storage p = proposals[proposalId]; require(!p.executed, 'ALREADY_EXECUTED'); - uint256 voterId = IContributor(getContributorContract()).getContributorIdByAddress(msg.sender); + uint32 voterId = IContributor(getContributorContract()).getContributorIdByAddress(msg.sender); require(p.votes[voterId] != true, 'ALREADY_VOTED'); p.voterIds.push(voterId); p.votes[voterId] = true; @@ -114,20 +114,19 @@ contract Proposal is AragonApp { emit ProposalVoted(proposalId, voterId, p.votesCount); } - function batchVote(uint256[] _proposalIds) public isInitialized auth(VOTE_PROPOSAL_ROLE) { - for (uint256 i = 0; i < _proposalIds.length; i++) { + function batchVote(uint32[] _proposalIds) public isInitialized auth(VOTE_PROPOSAL_ROLE) { + for (uint32 i = 0; i < _proposalIds.length; i++) { vote(_proposalIds[i]); } } - function executeProposal(uint proposalId) private { + function executeProposal(uint32 proposalId) private { Proposal storage p = proposals[proposalId]; require(!p.executed, 'ALREADY_EXECUTED'); require(p.votesCount >= p.votesNeeded, 'MISSING_VOTES'); - + p.executed = true; - address contributorAccount = IContributor(getContributorContract()).getContributorAddressById(p.contributorId); - IContribution(getContributionContract()).add(p.amount, contributorAccount, p.hashDigest, p.hashFunction, p.hashSize); + IContribution(getContributionContract()).add(p.amount, p.contributorId, p.hashDigest, p.hashFunction, p.hashSize); emit ProposalExecuted(proposalId, p.contributorId, p.amount); } diff --git a/lib/contracts/proposal.js b/lib/contracts/proposal.js index cf7e363..896b72f 100644 --- a/lib/contracts/proposal.js +++ b/lib/contracts/proposal.js @@ -7,8 +7,7 @@ const Base = require('./base'); class Proposal extends Base { all() { return this.functions.proposalsCount() - .then((count) => { - count = count.toNumber(); + .then(count => { let proposals = []; for (let id = 1; id <= count; id++) { @@ -20,10 +19,8 @@ class Proposal extends Base { } getById(id) { - id = ethers.utils.bigNumberify(id); - return this.functions.getProposal(id) - .then((data) => { + .then(data => { return this.ipfs.catAndMerge(data, ContributionSerializer.deserialize); }); } diff --git a/scripts/list-proposals.js b/scripts/list-proposals.js index 701ce83..2bbbedf 100644 --- a/scripts/list-proposals.js +++ b/scripts/list-proposals.js @@ -14,7 +14,6 @@ module.exports = async function(callback) { console.log(`Using Proposal at: ${kredits.Proposal.contract.address}`); - const table = new Table({ head: ['ID', 'Contributor ID', 'Amount', 'Votes', 'Executed?', 'Description'] })