Adjust proposals for format changes
This commit is contained in:
parent
181e6f3c23
commit
a049f2eedb
@ -4,13 +4,13 @@ import "@aragon/os/contracts/apps/AragonApp.sol";
|
|||||||
import "@aragon/os/contracts/kernel/IKernel.sol";
|
import "@aragon/os/contracts/kernel/IKernel.sol";
|
||||||
|
|
||||||
interface IContributor {
|
interface IContributor {
|
||||||
function getContributorAddressById(uint256 contributorId) public view returns (address);
|
function getContributorAddressById(uint32 contributorId) public view returns (address);
|
||||||
function getContributorIdByAddress(address contributorAccount) public view returns (uint256);
|
function getContributorIdByAddress(address contributorAccount) public view returns (uint32);
|
||||||
function exists(uint256 contributorId) public view returns (bool);
|
function exists(uint32 contributorId) public view returns (bool);
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IContribution {
|
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 {
|
contract Proposal is AragonApp {
|
||||||
@ -25,26 +25,26 @@ contract Proposal is AragonApp {
|
|||||||
|
|
||||||
struct Proposal {
|
struct Proposal {
|
||||||
address creatorAccount;
|
address creatorAccount;
|
||||||
uint contributorId;
|
uint32 contributorId;
|
||||||
uint votesCount;
|
uint16 votesCount;
|
||||||
uint votesNeeded;
|
uint16 votesNeeded;
|
||||||
uint256 amount;
|
uint32 amount;
|
||||||
bool executed;
|
bool executed;
|
||||||
bytes32 hashDigest;
|
bytes32 hashDigest;
|
||||||
uint8 hashFunction;
|
uint8 hashFunction;
|
||||||
uint8 hashSize;
|
uint8 hashSize;
|
||||||
uint256[] voterIds;
|
uint32[] voterIds;
|
||||||
mapping (uint256 => bool) votes;
|
mapping (uint32 => bool) votes;
|
||||||
bool exists;
|
bool exists;
|
||||||
}
|
}
|
||||||
|
|
||||||
mapping(uint256 => Proposal) public proposals;
|
mapping(uint32 => Proposal) public proposals;
|
||||||
uint256 public proposalsCount;
|
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 ProposalVoted(uint32 id, uint32 voterId, uint16 totalVotes);
|
||||||
event ProposalExecuted(uint256 id, uint256 contributorId, uint256 amount);
|
event ProposalExecuted(uint32 id, uint32 contributorId, uint32 amount);
|
||||||
|
|
||||||
function initialize(bytes32[4] _appIds) public onlyInit {
|
function initialize(bytes32[4] _appIds) public onlyInit {
|
||||||
appIds = _appIds;
|
appIds = _appIds;
|
||||||
@ -59,11 +59,11 @@ contract Proposal is AragonApp {
|
|||||||
return IKernel(kernel()).getApp(KERNEL_APP_ADDR_NAMESPACE, appIds[uint8(Apps.Contribution)]);
|
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');
|
require(IContributor(getContributorContract()).exists(contributorId), 'CONTRIBUTOR_NOT_FOUND');
|
||||||
|
|
||||||
uint256 proposalId = proposalsCount + 1;
|
uint32 proposalId = proposalsCount + 1;
|
||||||
uint256 _votesNeeded = 1; //contributorsContract().coreContributorsCount() / 100 * 75;
|
uint16 _votesNeeded = 1; //contributorsContract().coreContributorsCount() / 100 * 75;
|
||||||
|
|
||||||
Proposal storage p = proposals[proposalId];
|
Proposal storage p = proposals[proposalId];
|
||||||
p.creatorAccount = msg.sender;
|
p.creatorAccount = msg.sender;
|
||||||
@ -80,7 +80,7 @@ contract Proposal is AragonApp {
|
|||||||
emit ProposalCreated(proposalId, msg.sender, p.contributorId, p.amount);
|
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;
|
id = proposalId;
|
||||||
Proposal storage p = proposals[id];
|
Proposal storage p = proposals[id];
|
||||||
return (
|
return (
|
||||||
@ -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];
|
Proposal storage p = proposals[proposalId];
|
||||||
require(!p.executed, 'ALREADY_EXECUTED');
|
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');
|
require(p.votes[voterId] != true, 'ALREADY_VOTED');
|
||||||
p.voterIds.push(voterId);
|
p.voterIds.push(voterId);
|
||||||
p.votes[voterId] = true;
|
p.votes[voterId] = true;
|
||||||
@ -114,20 +114,19 @@ contract Proposal is AragonApp {
|
|||||||
emit ProposalVoted(proposalId, voterId, p.votesCount);
|
emit ProposalVoted(proposalId, voterId, p.votesCount);
|
||||||
}
|
}
|
||||||
|
|
||||||
function batchVote(uint256[] _proposalIds) public isInitialized auth(VOTE_PROPOSAL_ROLE) {
|
function batchVote(uint32[] _proposalIds) public isInitialized auth(VOTE_PROPOSAL_ROLE) {
|
||||||
for (uint256 i = 0; i < _proposalIds.length; i++) {
|
for (uint32 i = 0; i < _proposalIds.length; i++) {
|
||||||
vote(_proposalIds[i]);
|
vote(_proposalIds[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function executeProposal(uint proposalId) private {
|
function executeProposal(uint32 proposalId) private {
|
||||||
Proposal storage p = proposals[proposalId];
|
Proposal storage p = proposals[proposalId];
|
||||||
require(!p.executed, 'ALREADY_EXECUTED');
|
require(!p.executed, 'ALREADY_EXECUTED');
|
||||||
require(p.votesCount >= p.votesNeeded, 'MISSING_VOTES');
|
require(p.votesCount >= p.votesNeeded, 'MISSING_VOTES');
|
||||||
|
|
||||||
p.executed = true;
|
p.executed = true;
|
||||||
address contributorAccount = IContributor(getContributorContract()).getContributorAddressById(p.contributorId);
|
IContribution(getContributionContract()).add(p.amount, p.contributorId, p.hashDigest, p.hashFunction, p.hashSize);
|
||||||
IContribution(getContributionContract()).add(p.amount, contributorAccount, p.hashDigest, p.hashFunction, p.hashSize);
|
|
||||||
emit ProposalExecuted(proposalId, p.contributorId, p.amount);
|
emit ProposalExecuted(proposalId, p.contributorId, p.amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7,8 +7,7 @@ const Base = require('./base');
|
|||||||
class Proposal extends Base {
|
class Proposal extends Base {
|
||||||
all() {
|
all() {
|
||||||
return this.functions.proposalsCount()
|
return this.functions.proposalsCount()
|
||||||
.then((count) => {
|
.then(count => {
|
||||||
count = count.toNumber();
|
|
||||||
let proposals = [];
|
let proposals = [];
|
||||||
|
|
||||||
for (let id = 1; id <= count; id++) {
|
for (let id = 1; id <= count; id++) {
|
||||||
@ -20,10 +19,8 @@ class Proposal extends Base {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getById(id) {
|
getById(id) {
|
||||||
id = ethers.utils.bigNumberify(id);
|
|
||||||
|
|
||||||
return this.functions.getProposal(id)
|
return this.functions.getProposal(id)
|
||||||
.then((data) => {
|
.then(data => {
|
||||||
return this.ipfs.catAndMerge(data, ContributionSerializer.deserialize);
|
return this.ipfs.catAndMerge(data, ContributionSerializer.deserialize);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,6 @@ module.exports = async function(callback) {
|
|||||||
|
|
||||||
console.log(`Using Proposal at: ${kredits.Proposal.contract.address}`);
|
console.log(`Using Proposal at: ${kredits.Proposal.contract.address}`);
|
||||||
|
|
||||||
|
|
||||||
const table = new Table({
|
const table = new Table({
|
||||||
head: ['ID', 'Contributor ID', 'Amount', 'Votes', 'Executed?', 'Description']
|
head: ['ID', 'Contributor ID', 'Amount', 'Votes', 'Executed?', 'Description']
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user