Skip to content

Commit

Permalink
refactor: registerTask(s) return value (#119)
Browse files Browse the repository at this point in the history
  • Loading branch information
pegahcarter authored Oct 7, 2024
1 parent a9a4589 commit 5b4fa68
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
20 changes: 13 additions & 7 deletions contracts/tasks/TaskRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,32 @@ contract TaskRegistry is ITaskRegistry {
EnumerableSet.Bytes32Set private _taskIds;
mapping(bytes32 => Task) private _tasks;

// TODO: access control
// TODO: access control ?

function registerTasks(Task[] calldata tasks) external {
for (uint256 i = 0; i < tasks.length; i++) {
_registerTask(tasks[i]);
function registerTasks(Task[] calldata tasks) external returns (bytes32[] memory) {
uint256 length = tasks.length;
bytes32[] memory newTaskIds = new bytes32[](length);
for (uint256 i = 0; i < length; i++) {
newTaskIds[i] = _registerTask(tasks[i]);
}

return newTaskIds;
}

function registerTask(Task memory task) external {
_registerTask(task);
function registerTask(Task memory task) external returns (bytes32) {
return _registerTask(task);
}

function _registerTask(Task memory task) internal {
function _registerTask(Task memory task) internal returns (bytes32) {
bytes32 taskId = calcTaskId(task);

if (!_taskIds.add(taskId)) revert TaskAlreadyRegistered();

_tasks[taskId] = task;

emit RegisterTask(taskId, msg.sender, task.uri);

return taskId;
}

function getTaskById(bytes32 taskId) external view returns (Task memory) {
Expand Down
4 changes: 2 additions & 2 deletions contracts/tasks/interfaces/ITaskRegistry.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ interface ITaskRegistry {

event RegisterTask(bytes32 indexed taskId, address indexed who, string uri);

function registerTasks(Task[] calldata tasks) external;
function registerTask(Task memory task) external;
function registerTasks(Task[] calldata tasks) external returns (bytes32[] memory);
function registerTask(Task memory task) external returns (bytes32);

function getTaskById(bytes32 taskId) external view returns (Task memory);
function getTaskByIdEncoded(bytes32 taskId) external view returns (bytes memory);
Expand Down

0 comments on commit 5b4fa68

Please sign in to comment.