Skip to content

Instantly share code, notes, and snippets.

function requestVotingRights(uint numTokens) external {
require(token.balanceOf(msg.sender) >= numTokens);
require(token.transferFrom(msg.sender, this, numTokens));
voteTokenBalance[msg.sender] += numTokens;
}
function withdrawVotingRights(uint numTokens) external {
uint availableTokens = voteTokenBalance[msg.sender] - getLockedTokens(msg.sender);
require(availableTokens >= numTokens);
require(token.transfer(msg.sender, numTokens));
voteTokenBalance[msg.sender] -= numTokens;
}
function commitVote(uint pollID, bytes32 secretHash, uint numTokens, uint prevPollID) external {
require(commitPeriodActive(pollID));
require(voteTokenBalance[msg.sender] >= numTokens); // prevent user from overspending
require(pollID != 0); // prevent user from committing to zero node placerholder
uint nextPollID = dllMap[msg.sender].getNext(prevPollID);
require(validPosition(prevPollID, nextPollID, msg.sender, numTokens));
dllMap[msg.sender].insert(prevPollID, pollID, nextPollID);
function revealVote(uint pollID, uint voteOption, uint salt) external {
// Make sure the reveal period is active
require(revealPeriodActive(pollID));
require(!hasBeenRevealed(msg.sender, pollID)); // prevent user from revealing multiple times
require(sha3(voteOption, salt) == getCommitHash(msg.sender, pollID)); // compare resultant hash from inputs to original commitHash
uint numTokens = getNumTokens(msg.sender, pollID);
if (voteOption == 1) // apply numTokens to appropriate poll choice
pollMap[pollID].votesFor += numTokens;
library DLL {
struct Node {
uint next;
uint prev;
}
struct Data {
mapping(uint => Node) dll;
}
library AttributeStore {
struct Data {
mapping(bytes32 => uint) store;
}
function getAttribute(Data storage self, bytes32 UUID, string attrName) returns (uint) {
bytes32 key = sha3(UUID, attrName);
return self.store[key];
}
function startPoll(uint _voteQuorum, uint _commitDuration, uint _revealDuration) public returns (uint pollID) {
pollNonce = pollNonce + 1;
pollMap[pollNonce] = Poll({
voteQuorum: _voteQuorum,
commitEndDate: block.timestamp + _commitDuration,
revealEndDate: block.timestamp + _commitDuration + _revealDuration,
votesFor: 0,
votesAgainst: 0
});
function Registry(
address _tokenAddr,
address _plcrAddr,
address _paramsAddr
) {
token = StandardToken(_tokenAddr);
voting = PLCRVoting(_plcrAddr);
parameterizer = Parameterizer(_paramsAddr);
}
function apply(string _domain, uint _amount) external {
require(!isWhitelisted(_domain));
require(!appWasMade(_domain));
require(_amount >= parameterizer.get("minDeposit"));
// Sets owner
Listing storage listing = listings[keccak256(_domain)];
listing.owner = msg.sender;
// Transfers tokens from user to Registry contract
struct Listing {
uint applicationExpiry; // Expiration date of apply stage
bool whitelisted; // Indicates registry status
address owner; // Owner of Listing
uint unstakedDeposit; // Number of unlocked tokens with potential risk if challenged
uint challengeID; // Identifier of canonical challenge
}