0

The contract intends to create a set of tasks dynamically, eg: tasks can be added(There is no need for deletion.) Some tasks will be related by a variable within the struct called smart contract Each of this task should be assigned to every user that calls update. Finally The smart contract will have a function to iterate through all the addresses that have called update.

So far I have managed to be able to create tasks on command, and I can edit variables. I how ever have not managed to set it up so that each user owns its own array. Currently when I call get task, I just get the latest one created so I messes up somewhere else too, though I cant seem to find where.

So I have to be missing something. Any pointers are appreciated.

/**
 * @title Ownable
 * @dev The Ownable contract has an owner address, and provides basic authorization control
 * functions, this simplifies the implementation of "user permissions".
 */
pragma solidity ^0.4.25;

contract Owned {

    address public owner;

    constructor() public {
        owner = msg.sender;
    }

  /// @notice modifies any function it gets attached to, only allows the owner of the smart contract to execute the function
  modifier onlyOwner(){
    require(msg.sender == owner);
    _;
  }
}

///The contract intends to create a set of tasks dynamically, eg: tasks can be added(There is no need for deletion.) 
///Some tasks will be related by a variable within the struct called smart contract
///Each of this task should be assigned to every user that calls update. 
///Finally The smart contract will have a function to iterate through all the addresses that have called update.

contract taskListContract is Owned {
    address public receiver;

    struct task {
        string iName;
        uint16 taskId;
        address smartContract;
        bool iValue;
    }

    uint taskCount;
    mapping(address => task) taskList;
    task[] taskArray;

    function addTask(string name, uint16 id, address code) external onlyOwner{
        receiver = msg.sender;
        task memory tasknew = task(name, id ,code, false);
        taskList[receiver] = tasknew;
        taskArray.push(tasknew);
        taskCount++;
    }


    function updateUserTask(bool _value) public{
        task storage individualUser =taskList[receiver];
        individualUser.iValue = _value;
    }

/**                 TODO 
 *  update all the users at the same time
 *  0xe3b819b9d1356bbbce0000ee1251d04d8bce60a1
 *
 *  function updateAllUserTasks() public{
 *      receiver = msg.sender;
 *      userTaskList(receiver)
 *
 *  }
 */

    function countItemList() public constant returns (uint count)  {     
        return taskCount;
    }

    function removeTask() external onlyOwner {
        delete taskList[msg.sender];
        taskCount--;
    }

    function getTask() public constant returns (string iName, bool iValue, uint count)  {   
        return (taskList[msg.sender].iName, taskList[msg.sender].iValue, taskCount);
    }
}

1 Answer 1

0

If you wish to have a task array per user, you'll have to change your mapping to

mapping(address => task[]) taskList;

In this case, you don't need the workaround with receiver.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.