Solidity: UnimplementedFeatureError: Nested dynamic arrays not implemented here
Asked Answered
A

2

5

When I try to do this in Solidity, it gives me UnimplementedFeatureError: Nested dynamic arrays not implemented here.

I see this in code examples. Does Solidity not support this?

Edit - posted complete code below. So I figured out the problem is only in the last function. It doesn't like that I am returning a dynamic array. How could I implement the same functionality (I want to return a string array of data)?

pragma solidity ^0.4.6;

contract EmailIntegrity {

  // Map an array of EmailIntegrityStructs for each email address.
  // The first element will be used for the integrity record.
  // The rest will be used for audit records.

  enum ItemType { Integrity, Audit }
  
  struct EmailIntegrityStruct {
    ItemType itemType;
    uint timestamp;
    string data;
  }

  mapping(address => EmailIntegrityStruct[])  emailIntegrityStructs;

  function hasEmailIntegrityData(address emailAddress) public constant returns(bool isEmail) {
    return emailIntegrityStructs[emailAddress][0].timestamp == 0;
  }

  function insertIntegrityData(address emailAddress, uint timestamp, string data) public returns(bool success) {
    if (hasEmailIntegrityData(emailAddress)) {
        revert(); 
    }
    EmailIntegrityStruct memory integrityData;
    integrityData.itemType = ItemType.Integrity;
    integrityData.timestamp = timestamp;
    integrityData.data = data;
    emailIntegrityStructs[emailAddress].push(integrityData);
    return emailIntegrityStructs[emailAddress].length == 1;
  }

  function insertAuditData(address emailAddress, uint timestamp, string data) public returns(bool success) {
    if (!hasEmailIntegrityData(emailAddress)) {
        revert(); 
    }
    EmailIntegrityStruct memory auditData;
    auditData.itemType = ItemType.Audit;
    auditData.timestamp = timestamp;
    auditData.data = data;
    emailIntegrityStructs[emailAddress].push(auditData);
    return emailIntegrityStructs[emailAddress].length > 1;
  }
  
  function getIntegrityData(address emailAddress) public constant returns(string data) {
    if (!hasEmailIntegrityData(emailAddress)) {
        revert(); 
    }
    return emailIntegrityStructs[emailAddress][0].data; 
  } 

  function getAuditData(address emailAddress) public constant returns(string[] data) {
    if (!hasEmailIntegrityData(emailAddress)) {
        revert(); 
    }
    var length = emailIntegrityStructs[emailAddress].length;
    string[] memory auditData = new string[](length - 1);
    for (uint i = 1; i < length ; i++) {
           auditData[i] = emailIntegrityStructs[emailAddress][i].data;
    }
    return auditData; 
  }

}
Argentum answered 17/1, 2018 at 20:6 Comment(1)
check this ethereum.stackexchange.com/questions/37627/…Leflore
S
7

Solidity and Javascript allow nested arrays but we do not have the ability to pull a nested dynamic array from the solidity over to javascript world.

it is the limitation of the bridge between solidity and javascript. Since strings inside of solidity are represented as dynamic arrays, we cannot transfer array of strings.

UPDATE

Since then, solidity has evolved, you can return dynamic array including structs. A test contract:

// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.0;

contract Test {
    struct User{
        string name;
        string LastName;
    }
    User[] public store;

    function addToStorage() external returns (User[] memory ) {
        User memory newUser=User(
            "yilmads","bin"
        );
        store.push(newUser);
        return store;
    }
}
Subscription answered 3/4, 2020 at 2:50 Comment(1)
It seems that array of strings is also treated as nested arrays so cannot be passed through the bridge.Translate
C
2

This compiled fine for me.

I added a definition of MyStruct and upped the Solidity version to the current one (though it compiled fine with the old pragma too). Here's the code I compiled via Remix:

pragma solidity ^0.4.19;

contract MyContract{
    struct MyStruct {
        uint256 foo;
    }
    mapping(address => MyStruct[])  myStruct;
}

Could it be that you're using an older version of the Solidity compiler? (The ^0.4.6 made me think that perhaps you are.)

What's your MyStruct? Perhaps a more interesting structure there would fail. In general, please try to provide full code samples that reproduce the problem you're seeing.

Crippen answered 17/1, 2018 at 20:13 Comment(1)
I don't want you to waste your time answering this. I just read that you can return an array of other types from functions, but not an array of strings because strings are themselves arrays. I'm looking into how to solve this. Thanks for your help!Argentum

© 2022 - 2024 — McMap. All rights reserved.