Continue Contribution contract and JS wrapper
This commit is contained in:
@@ -1,34 +1,49 @@
|
||||
pragma solidity ^0.4.18;
|
||||
pragma solidity ^0.4.19;
|
||||
|
||||
import "zeppelin-solidity/contracts/token/ERC721/ERC721Token.sol";
|
||||
import './upgradeable/Upgradeable.sol';
|
||||
|
||||
// ToDo: only load interfaces
|
||||
import './Token.sol';
|
||||
import './Contributors.sol';
|
||||
|
||||
contract Contribution is Upgradeable, ERC721Token {
|
||||
|
||||
struct Contribution {
|
||||
struct ContributionData {
|
||||
address contributor;
|
||||
uint amount;
|
||||
bool issued;
|
||||
uint proposalId;
|
||||
string url;
|
||||
uint256 claimAfterBlock;
|
||||
bool claimed;
|
||||
bytes32 hashDigest;
|
||||
uint8 hashFunction;
|
||||
uint8 hashSize;
|
||||
string tokenMetadataURL;
|
||||
uint claimAfterBlock;
|
||||
bool exists;
|
||||
}
|
||||
string internal name_;
|
||||
string internal symbol_;
|
||||
|
||||
mapping(uint256 => string) contributionURIs;
|
||||
|
||||
mapping(uint256 => address) contributionOwner;
|
||||
mapping(address => uint256[]) ownedContributions;
|
||||
|
||||
mapping(uint256 => Contribution) public contributions;
|
||||
mapping(uint256 => ContributionData) public contributions;
|
||||
uint256 public contributionsCount;
|
||||
|
||||
event ContributionAdded(uint256 id, address indexed contributor, uint256 amount);
|
||||
event ContributionClaimed(uint256 id, address indexed contributor, uint256 amount);
|
||||
|
||||
modifier coreOnly() {
|
||||
require(contributorsContract().addressIsCore(msg.sender));
|
||||
_;
|
||||
}
|
||||
modifier contributorOnly() {
|
||||
require(contributorsContract().addressExists(msg.sender));
|
||||
_;
|
||||
}
|
||||
|
||||
function contributorsContract() view public returns (Contributors) {
|
||||
return Contributors(registry.getProxyFor('Contributors'));
|
||||
}
|
||||
|
||||
function tokenContract() view public returns (Token) {
|
||||
return Token(registry.getProxyFor('Token'));
|
||||
@@ -42,11 +57,6 @@ contract Contribution is Upgradeable, ERC721Token {
|
||||
return symbol_;
|
||||
}
|
||||
|
||||
function contributionURI(uint256 contributionId) public view returns (string) {
|
||||
require(exists(contributionId));
|
||||
return contributions[contributionId].url;
|
||||
}
|
||||
|
||||
function ownerOf(uint256 contributionId) public view returns (address) {
|
||||
require(exists(contributionId));
|
||||
return contributions[contributionId].contributor;
|
||||
@@ -56,14 +66,36 @@ contract Contribution is Upgradeable, ERC721Token {
|
||||
return ownedContributions[contributor].length;
|
||||
}
|
||||
|
||||
function add(uint256 amount, uint256 proposalId, address contributor, uint256 blocksToWait, string url) public {
|
||||
function tokenOfOwnerByIndex(address contributor, uint index) public view returns (uint) {
|
||||
return ownedContributions[contributor][index];
|
||||
}
|
||||
|
||||
function tokenMetadata(uint contributionId) public view returns (string) {
|
||||
return contributions[contributionId].tokenMetadataURL;
|
||||
}
|
||||
|
||||
function getContribution(uint contributionId) public view returns (uint256 id, address contributor, uint256 amount, bool claimed, bytes32 hashDigest, uint8 hashFunction, uint8 hashSize, uint claimAfterBlock, bool exists) {
|
||||
id = contributionId;
|
||||
ContributionData storage c = contributions[id];
|
||||
return (
|
||||
id,
|
||||
c.contributor,
|
||||
c.amount,
|
||||
c.claimed,
|
||||
c.hashDigest,
|
||||
c.hashFunction,
|
||||
c.hashSize,
|
||||
c.claimAfterBlock,
|
||||
c.exists
|
||||
);
|
||||
}
|
||||
|
||||
function add(uint256 amount, address contributor, uint256 blocksToWait) public coreOnly {
|
||||
uint contributionId = contributionsCount + 1;
|
||||
var c = contributions[contributionId];
|
||||
ContributionData storage c = contributions[contributionId];
|
||||
c.exists = true;
|
||||
c.amount = amount;
|
||||
c.issued = false;
|
||||
c.proposalId = proposalId;
|
||||
c.url = url;
|
||||
c.claimed = false;
|
||||
c.contributor = contributor;
|
||||
c.claimAfterBlock = block.number + blocksToWait;
|
||||
|
||||
@@ -71,17 +103,19 @@ contract Contribution is Upgradeable, ERC721Token {
|
||||
|
||||
contributionOwner[contributionId] = contributor;
|
||||
ownedContributions[contributor].push(contributionId);
|
||||
|
||||
|
||||
ContributionAdded(contributionId, contributor, amount);
|
||||
}
|
||||
|
||||
function claim(uint256 contributionId) public {
|
||||
var c = contributions[contributionId];
|
||||
ContributionData storage c = contributions[contributionId];
|
||||
require(c.exists);
|
||||
require(!c.issued);
|
||||
require(!c.claimed);
|
||||
require(block.number > c.claimAfterBlock);
|
||||
c.claimed = true;
|
||||
tokenContract().mintFor(c.contributor, c.amount, contributionId);
|
||||
c.issued = true;
|
||||
|
||||
ContributionClaimed(contributionId, c.contributor, c.amount);
|
||||
}
|
||||
|
||||
function exists(uint256 contributionId) view public returns (bool) {
|
||||
|
||||
@@ -121,12 +121,11 @@ contract Operator is Upgradeable {
|
||||
}
|
||||
|
||||
function executeProposal(uint proposalId) private {
|
||||
|
||||
var p = proposals[proposalId];
|
||||
require(!p.executed);
|
||||
require(p.votesCount >= p.votesNeeded);
|
||||
address recipientAddress = contributorsContract().getContributorAddressById(p.contributorId);
|
||||
contributionContract().add(p.amount, proposalId, recipientAddress, 0, '');
|
||||
contributionContract().add(p.amount, recipientAddress, 0);
|
||||
p.executed = true;
|
||||
ProposalExecuted(proposalId, p.contributorId, p.amount);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user