0

I am creating the following contract:

pragma solidity ^ 0.4.17;

contract TodoList {

    event NewTodo(uint todoId, string value);
    event DeleteTodo(uint todoId, string value);

    mapping(uint => address) public todoOwner;
    mapping(address => uint) ownerTodoCount;

    TodoItem[] public todoItems;

    struct TodoItem {
        string value;
        //TODO submit ether to a TodoItem
        bool active;
    }

    function createTodo(string _value) internal returns(uint) {
        uint id = todoItems.push(TodoItem(_value, true)) - 1;
        todoOwner[id] = msg.sender;
        ownerTodoCount[msg.sender]++;
        NewTodo(id, _value);
        return id;
    }

    function getAllTodos() constant returns(string[], bool[]) {
        uint length = todoItems.length;

        string[] memory values = new string[](length);
        bool[] memory actives = new bool[](length);

        for (uint i = 0; i < length; i++) {
            values[i] = todoItems[i].value;
            actives[i] = todoItems[i].active;
        }

        return (values, actives);
    }  
}

I would like to display all todos by a user. For this I created the getAllTodos function.

However, when doing truffle compile I get the following error:

UnimplementedFeatureError: Nested dynamic arrays not implemented here.

Any suggestions how to access all todos?

2

So dynamic nested arrays are something not perfectly handled by solidity as of now. Every time you access a function involving a nested array, it must be internal. Thus, I am guessing the error could be in function getAllTodos whose access scope isn't specified, thus defaulting to public.

I hope this works! (PS- I have heard that this could also fail because nested arrays isn't fully implemented yet, but well worth a try

  • Thx for your reply! Would you be so kind to add a sample code, how to do it better? I guess this might be highly relevant for future "answer" searchers. – Soli Feb 2 '18 at 5:26
  • So I think the code could work if you have the following function definition: function getAllTodos() internal returns(string[], bool[]) – Rahul Kothari Feb 2 '18 at 15:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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