Skip to content

Commit

Permalink
Improve event emissions in Registry
Browse files Browse the repository at this point in the history
Previously, frontend devs had to make several calls and checks to build
up the full context of challenges and exits.

* remove address from all events (duplicate of tx.from)
* remove deposit from _Challenge (duplicate of minDeposit)
* add appEndDate to _Application
* add _ListingWithdrawn and _TouchAndRemoved
  • Loading branch information
kangarang committed Mar 29, 2018
1 parent f5b42b2 commit cab98ed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions contracts/Registry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,18 @@ contract Registry {
// EVENTS
// ------

event _Application(bytes32 listingHash, uint deposit, string data);
event _Challenge(bytes32 listingHash, uint deposit, uint pollID, string data);
event _Application(bytes32 listingHash, uint deposit, uint appEndDate, string data);
event _Challenge(bytes32 listingHash, uint challengeID, string data);
event _Deposit(bytes32 listingHash, uint added, uint newTotal);
event _Withdrawal(bytes32 listingHash, uint withdrew, uint newTotal);
event _NewListingWhitelisted(bytes32 listingHash);
event _ApplicationWhitelisted(bytes32 listingHash);
event _ApplicationRemoved(bytes32 listingHash);
event _ListingRemoved(bytes32 listingHash);
event _ListingWithdrawn(bytes32 listingHash);
event _TouchAndRemoved(bytes32 listingHash);
event _ChallengeFailed(uint challengeID);
event _ChallengeSucceeded(uint challengeID);
event _RewardClaimed(address voter, uint challengeID, uint reward);
event _RewardClaimed(uint challengeID, uint reward);

using SafeMath for uint;

Expand Down Expand Up @@ -100,7 +102,7 @@ contract Registry {
// Transfers tokens from user to Registry contract
require(token.transferFrom(listing.owner, this, _amount));

_Application(_listingHash, _amount, _data);
_Application(_listingHash, _amount, listing.applicationExpiry, _data);

This comment has been minimized.

Copy link
@eccheung4

eccheung4 Mar 29, 2018

dunno if you want to rename applicationExpiry to appEndDate everywhere else in contract, but just pointing it out just in case for the general tcr

}

/**
Expand Down Expand Up @@ -153,6 +155,7 @@ contract Registry {

// Remove listingHash & return tokens
resetListing(_listingHash);
_ListingWithdrawn(_listingHash);
}

// -----------------------
Expand All @@ -178,6 +181,7 @@ contract Registry {
if (listing.unstakedDeposit < deposit) {
// Not enough tokens, listingHash auto-delisted
resetListing(_listingHash);
_TouchAndRemoved(_listingHash);
return 0;
}

Expand Down Expand Up @@ -205,7 +209,7 @@ contract Registry {
// Takes tokens from challenger
require(token.transferFrom(msg.sender, this, deposit));

_Challenge(_listingHash, deposit, pollID, _data);
_Challenge(_listingHash, pollID, _data);
return pollID;
}

Expand Down Expand Up @@ -252,7 +256,7 @@ contract Registry {

require(token.transfer(msg.sender, reward));

_RewardClaimed(msg.sender, _challengeID, reward);
_RewardClaimed(_challengeID, reward);
}

// --------
Expand Down Expand Up @@ -406,7 +410,7 @@ contract Registry {
@param _listingHash The listingHash of an application/listingHash to be whitelisted
*/
function whitelistApplication(bytes32 _listingHash) private {
if (!listings[_listingHash].whitelisted) { _NewListingWhitelisted(_listingHash); }
if (!listings[_listingHash].whitelisted) { _ApplicationWhitelisted(_listingHash); }
listings[_listingHash].whitelisted = true;
}

Expand Down
2 changes: 1 addition & 1 deletion test/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ const utils = {
challengeAndGetPollID: async (domain, actor) => {
const registry = await Registry.deployed();
const receipt = await utils.as(actor, registry.challenge, domain, '');
return receipt.logs[0].args.pollID;
return receipt.logs[0].args.challengeID;
},

commitVote: async (pollID, voteOption, tokensArg, salt, voter) => {
Expand Down

0 comments on commit cab98ed

Please sign in to comment.