refactor get apps contract functions
This commit is contained in:
parent
d92ad83379
commit
e14cb0a77d
@ -60,23 +60,18 @@ contract Contribution is AragonApp {
|
|||||||
initialized();
|
initialized();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO refactor into a single function
|
function getContract(uint8 appId) public view returns (address) {
|
||||||
function getTokenContract() public view returns (address) {
|
|
||||||
IKernel k = IKernel(kernel());
|
IKernel k = IKernel(kernel());
|
||||||
return k.getApp(KERNEL_APP_ADDR_NAMESPACE, appIds[uint8(Apps.Token)]);
|
return k.getApp(KERNEL_APP_ADDR_NAMESPACE, appIds[appId]);
|
||||||
}
|
|
||||||
function getContributorContract() public view returns (address) {
|
|
||||||
IKernel k = IKernel(kernel());
|
|
||||||
return k.getApp(KERNEL_APP_ADDR_NAMESPACE, appIds[uint8(Apps.Contributor)]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getContributorIdByAddress(address contributorAccount) public view returns (uint32) {
|
function getContributorIdByAddress(address contributorAccount) public view returns (uint32) {
|
||||||
address contributor = getContributorContract();
|
address contributor = getContract(uint8(Apps.Contributor));
|
||||||
return ContributorInterface(contributor).getContributorIdByAddress(contributorAccount);
|
return ContributorInterface(contributor).getContributorIdByAddress(contributorAccount);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getContributorAddressById(uint32 contributorId) public view returns (address) {
|
function getContributorAddressById(uint32 contributorId) public view returns (address) {
|
||||||
address contributor = getContributorContract();
|
address contributor = getContract(uint8(Apps.Contributor));
|
||||||
return ContributorInterface(contributor).getContributorAddressById(contributorId);
|
return ContributorInterface(contributor).getContributorAddressById(contributorId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -198,14 +193,14 @@ contract Contribution is AragonApp {
|
|||||||
require(block.number >= c.confirmedAtBlock, 'NOT_CLAIMABLE');
|
require(block.number >= c.confirmedAtBlock, 'NOT_CLAIMABLE');
|
||||||
|
|
||||||
c.claimed = true;
|
c.claimed = true;
|
||||||
address token = getTokenContract();
|
address token = getContract(uint8(Apps.Token));
|
||||||
address contributorAccount = getContributorAddressById(c.contributorId);
|
address contributorAccount = getContributorAddressById(c.contributorId);
|
||||||
uint256 amount = uint256(c.amount);
|
uint256 amount = uint256(c.amount);
|
||||||
IToken(token).mintFor(contributorAccount, amount, contributionId);
|
IToken(token).mintFor(contributorAccount, amount, contributionId);
|
||||||
emit ContributionClaimed(contributionId, c.contributorId, c.amount);
|
emit ContributionClaimed(contributionId, c.contributorId, c.amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
function exists(uint32 contributionId) view public returns (bool) {
|
function exists(uint32 contributionId) public view returns (bool) {
|
||||||
return contributions[contributionId].exists;
|
return contributions[contributionId].exists;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -41,19 +41,12 @@ contract Contributor is AragonApp {
|
|||||||
initialized();
|
initialized();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getTokenContract() public view returns (address) {
|
function getContract(uint8 appId) public view returns (address) {
|
||||||
IKernel k = IKernel(kernel());
|
IKernel k = IKernel(kernel());
|
||||||
|
return k.getApp(KERNEL_APP_ADDR_NAMESPACE, appIds[appId]);
|
||||||
return k.getApp(KERNEL_APP_ADDR_NAMESPACE, appIds[uint8(Apps.Token)]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getContributionContract() public view returns (address) {
|
function coreContributorsCount() public view returns (uint32) {
|
||||||
IKernel k = IKernel(kernel());
|
|
||||||
|
|
||||||
return k.getApp(KERNEL_APP_ADDR_NAMESPACE, appIds[uint8(Apps.Contribution)]);
|
|
||||||
}
|
|
||||||
|
|
||||||
function coreContributorsCount() view public returns (uint32) {
|
|
||||||
uint32 count = 0;
|
uint32 count = 0;
|
||||||
for (uint32 i = 1; i <= contributorsCount; i++) {
|
for (uint32 i = 1; i <= contributorsCount; i++) {
|
||||||
if (isCoreTeam(i)) {
|
if (isCoreTeam(i)) {
|
||||||
@ -136,9 +129,9 @@ contract Contributor is AragonApp {
|
|||||||
hashFunction = c.hashFunction;
|
hashFunction = c.hashFunction;
|
||||||
hashSize = c.hashSize;
|
hashSize = c.hashSize;
|
||||||
isCore = isCoreTeam(id);
|
isCore = isCoreTeam(id);
|
||||||
address token = getTokenContract();
|
address token = getContract(uint8(Apps.Token));
|
||||||
balance = ITokenBalance(token).balanceOf(c.account);
|
balance = ITokenBalance(token).balanceOf(c.account);
|
||||||
address contribution = getContributionContract();
|
address contribution = getContract(uint8(Apps.Contribution));
|
||||||
totalKreditsEarned = IContributionBalance(contribution).totalKreditsEarnedByContributor(_id, true);
|
totalKreditsEarned = IContributionBalance(contribution).totalKreditsEarnedByContributor(_id, true);
|
||||||
contributionsCount = IContributionBalance(contribution).balanceOf(c.account);
|
contributionsCount = IContributionBalance(contribution).balanceOf(c.account);
|
||||||
exists = c.exists;
|
exists = c.exists;
|
||||||
|
@ -51,16 +51,13 @@ contract Proposal is AragonApp {
|
|||||||
initialized();
|
initialized();
|
||||||
}
|
}
|
||||||
|
|
||||||
function getContributorContract() public view returns (address) {
|
function getContract(uint8 appId) public view returns (address) {
|
||||||
return IKernel(kernel()).getApp(KERNEL_APP_ADDR_NAMESPACE, appIds[uint8(Apps.Contributor)]);
|
IKernel k = IKernel(kernel());
|
||||||
}
|
return k.getApp(KERNEL_APP_ADDR_NAMESPACE, appIds[appId]);
|
||||||
|
|
||||||
function getContributionContract() public view returns (address) {
|
|
||||||
return IKernel(kernel()).getApp(KERNEL_APP_ADDR_NAMESPACE, appIds[uint8(Apps.Contribution)]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function addProposal(uint32 contributorId, uint32 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(getContract(uint8(Apps.Contributor))).exists(contributorId), 'CONTRIBUTOR_NOT_FOUND');
|
||||||
|
|
||||||
uint32 proposalId = proposalsCount + 1;
|
uint32 proposalId = proposalsCount + 1;
|
||||||
uint16 _votesNeeded = 1; //contributorsContract().coreContributorsCount() / 100 * 75;
|
uint16 _votesNeeded = 1; //contributorsContract().coreContributorsCount() / 100 * 75;
|
||||||
@ -69,10 +66,10 @@ contract Proposal is AragonApp {
|
|||||||
p.creatorAccount = msg.sender;
|
p.creatorAccount = msg.sender;
|
||||||
p.contributorId = contributorId;
|
p.contributorId = contributorId;
|
||||||
p.amount = amount;
|
p.amount = amount;
|
||||||
p.hashDigest = hashDigest;
|
p.hashDigest = hashDigest;
|
||||||
p.hashFunction = hashFunction;
|
p.hashFunction = hashFunction;
|
||||||
p.hashSize = hashSize;
|
p.hashSize = hashSize;
|
||||||
p.votesCount = 0;
|
p.votesCount = 0;
|
||||||
p.votesNeeded = _votesNeeded;
|
p.votesNeeded = _votesNeeded;
|
||||||
p.exists = true;
|
p.exists = true;
|
||||||
|
|
||||||
@ -102,7 +99,7 @@ contract Proposal is AragonApp {
|
|||||||
function vote(uint32 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');
|
||||||
uint32 voterId = IContributor(getContributorContract()).getContributorIdByAddress(msg.sender);
|
uint32 voterId = IContributor(getContract(uint8(Apps.Contributor))).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;
|
||||||
@ -126,7 +123,7 @@ contract Proposal is AragonApp {
|
|||||||
require(p.votesCount >= p.votesNeeded, 'MISSING_VOTES');
|
require(p.votesCount >= p.votesNeeded, 'MISSING_VOTES');
|
||||||
|
|
||||||
p.executed = true;
|
p.executed = true;
|
||||||
IContribution(getContributionContract()).add(p.amount, p.contributorId, p.hashDigest, p.hashFunction, p.hashSize);
|
IContribution(getContract(uint8(Apps.Contribution))).add(p.amount, p.contributorId, p.hashDigest, p.hashFunction, p.hashSize);
|
||||||
emit ProposalExecuted(proposalId, p.contributorId, p.amount);
|
emit ProposalExecuted(proposalId, p.contributorId, p.amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user