Skip to content

Commit

Permalink
refactor: events remove encoding (#129)
Browse files Browse the repository at this point in the history
  • Loading branch information
pegahcarter authored Oct 22, 2024
1 parent 5ebccad commit 51f68c9
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 27 deletions.
13 changes: 12 additions & 1 deletion contracts/tasks/TaskFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,18 @@ contract TaskFactory is ITaskFactory, Initializable, PeriodUtils, AccessUtils {

ITaskManager(taskManager()).addContribution(contributionId, contribution);

emit CreateContribution(contributionId, msg.sender, encodedContribution);
emit CreateContribution({
contributionId: contributionId,
sender: msg.sender,
hub: hub(),
taskId: contribution.taskId,
descriptionId: contribution.descriptionId,
role: contribution.role,
startDate: contribution.startDate,
endDate: contribution.endDate,
points: contribution.points,
quantity: contribution.quantity
});

return contributionId;
}
Expand Down
42 changes: 27 additions & 15 deletions contracts/tasks/TaskManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,14 @@ contract TaskManager is ITaskManager, Initializable, PeriodUtils, AccessUtils {
contributionStatuses[contributionId] = contributionStatus;
pointsActive += contribution.points * contribution.quantity;

emit AddContribution(contributionId, encodeContributionStatus(contributionStatus));
emit AddContribution({
contributionId: contributionId,
sender: msg.sender,
hub: hub(),
status: Status.Open,
points: contribution.points,
quantityRemaining: contribution.quantity
});
}

/// @inheritdoc ITaskManager
Expand Down Expand Up @@ -119,7 +126,14 @@ contract TaskManager is ITaskManager, Initializable, PeriodUtils, AccessUtils {
periodPointsRemoved += sumPointsRemoved;
contributionStatus.status = Status.Inactive;

emit RemoveContribution(contributionId, encodeContributionStatus(contributionStatus));
emit RemoveContribution({
contributionId: contributionId,
sender: msg.sender,
hub: hub(),
status: Status.Inactive,
points: contributionStatus.points,
quantityRemaining: contributionStatus.quantityRemaining
});
}

/// @inheritdoc ITaskManager
Expand Down Expand Up @@ -147,7 +161,7 @@ contract TaskManager is ITaskManager, Initializable, PeriodUtils, AccessUtils {

ContributionStatus storage contributionStatus = contributionStatuses[contributionId];
if (uint8(contributionStatus.status) != uint8(Status.Open)) revert ContributionNotOpen();
emit CommitContribution(contributionId, msg.sender, who, data);
emit CommitContribution({contributionId: contributionId, sender: msg.sender, hub: hub(), who: who, data: data});
}

/// @inheritdoc ITaskManager
Expand Down Expand Up @@ -197,8 +211,16 @@ contract TaskManager is ITaskManager, Initializable, PeriodUtils, AccessUtils {
if (contributionStatus.quantityRemaining == 0) {
contributionStatus.status = Status.Complete;
}

emit GiveContribution(contributionId, who, currentPeriodId_, encodeContributionStatus(contributionStatus));
emit GiveContribution({
contributionId: contributionId,
sender: msg.sender,
hub: hub(),
periodId: currentPeriodId_,
who: who,
status: contributionStatus.status,
points: contributionStatus.points,
quantityRemaining: contributionStatus.quantityRemaining
});
}

/// @inheritdoc ITaskManager
Expand Down Expand Up @@ -292,14 +314,4 @@ contract TaskManager is ITaskManager, Initializable, PeriodUtils, AccessUtils {
function getGivenContributions(uint32 periodId) external view returns (bytes32[] memory) {
return contributionsGivenInPeriod[periodId];
}

/// @inheritdoc ITaskManager
function encodeContributionStatus(ContributionStatus memory contributionStatus) public pure returns (bytes memory) {
return
abi.encodePacked(
contributionStatus.status,
contributionStatus.points,
contributionStatus.quantityRemaining
);
}
}
13 changes: 12 additions & 1 deletion contracts/tasks/interfaces/ITaskFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,18 @@ interface ITaskFactory {
error InvalidContributionPeriod();
error DescriptionAlreadyRegistered();

event CreateContribution(bytes32 indexed contributionId, address indexed sender, bytes encodedContribution);
event CreateContribution(
bytes32 indexed contributionId,
address indexed sender,
address indexed hub,
bytes32 taskId,
bytes32 descriptionId,
uint256 role,
uint32 startDate,
uint32 endDate,
uint32 points,
uint128 quantity
);
event RegisterDescription(bytes32 indexed descriptionId);

/// @notice register descriptions of contributions to be used in `createContribution(s)`
Expand Down
39 changes: 29 additions & 10 deletions contracts/tasks/interfaces/ITaskManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,38 @@ interface ITaskManager {

event AddContributionManager(address who);
event RemoveContributionManager(address who);
event AddContribution(bytes32 indexed contributionId, bytes encodedContributionStatus);
event RemoveContribution(bytes32 indexed contributionId, bytes encodedContributionStatus);
event CommitContribution(bytes32 indexed contributionId, address indexed sender, address indexed who, bytes data);
event AddContribution(
bytes32 indexed contributionId,
address indexed sender,
address indexed hub,
Status status,
uint32 points,
uint128 quantityRemaining
);
event RemoveContribution(
bytes32 indexed contributionId,
address indexed sender,
address indexed hub,
Status status,
uint32 points,
uint128 quantityRemaining
);
event CommitContribution(
bytes32 indexed contributionId,
address indexed sender,
address indexed hub,
address who,
bytes data
);
event GiveContribution(
bytes32 indexed contributionId,
address indexed who,
address indexed sender,
address indexed hub,
uint32 periodId,
bytes encodedContributionStatus
address who,
Status status,
uint32 points,
uint128 quantityRemaining
);

/// @notice Set the initial contribution manager from the hub registry
Expand Down Expand Up @@ -127,9 +151,4 @@ interface ITaskManager {

/// @notice return the contributionId's given for the whole hub for a provided periodId
function getGivenContributions(uint32 periodId) external view returns (bytes32[] memory);

/// @notice Encode a ContributionStatus to its' corresponding bytes array
function encodeContributionStatus(
ContributionStatus memory contributionStatus
) external pure returns (bytes memory);
}

0 comments on commit 51f68c9

Please sign in to comment.