Skip to content

Instantly share code, notes, and snippets.

@skmgoldin
Created November 12, 2017 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skmgoldin/e130f3b18162f58b5a17cf617c308b9f to your computer and use it in GitHub Desktop.
Save skmgoldin/e130f3b18162f58b5a17cf617c308b9f to your computer and use it in GitHub Desktop.
function resolveChallenge(string _domain) private {
bytes32 domainHash = keccak256(_domain);
Listing storage listing = listings[domainHash];
Challenge.Data storage challenge = challenges[listing.challengeID];
// Calculates the winner's reward,
// which is: (winner's full stake) + (dispensationPct * loser's stake)
uint winnerReward = challenge.challengeWinnerReward();
// Records whether the domain is a listing or an application
bool wasWhitelisted = isWhitelisted(_domain);
// Case: challenge failed
if (voting.isPassed(challenge.challengeID)) {
whitelistApplication(_domain);
// Unlock stake so that it can be retrieved by the applicant
listing.unstakedDeposit += winnerReward;
_ChallengeFailed(challenge.challengeID);
if (!wasWhitelisted) { _NewDomainWhitelisted(_domain); }
}
// Case: challenge succeeded
else {
resetListing(_domain);
// Transfer the reward to the challenger
require(token.transfer(challenge.challenger, winnerReward));
_ChallengeSucceeded(challenge.challengeID);
if (wasWhitelisted) { _ListingRemoved(_domain); }
else { _ApplicationRemoved(_domain); }
}
challenge.winningTokens =
challenge.voting.getTotalNumberOfTokensForWinningOption(challenge.challengeID);
challenge.resolved = true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment