Decoding a mapping in Solidity: Type library IterableMapping is not implicitly convertible to expected type struct IterableMapping.Map storage pointer

Context

I am storing the content of the following mapping into a file:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>pragma solidity >=0.8.25 <0.9.0;
import "test/TestConstants.sol";
library IterableMapping {
// Iterable mapping from string[] to uint;
struct Map {
string[] keys;
mapping(string => uint256) values;
mapping(string => uint256) indexOf;
mapping(string => bool) inserted;
}
function get(Map storage map, string memory key) public view returns (uint256) {
return map.values[key];
}
function getKeys(Map storage map) public view returns (string[] memory) {
return map.keys;
}
function getValues(Map storage map) public view returns (uint256[] memory) {
uint256[] memory listOfValues = new uint256[](_MAX_NR_OF_TEST_LOG_VALUES_PER_LOG_FILE);
for (uint256 i = 0; i < map.keys.length - 1; i++) {
listOfValues[i] = map.values[map.keys[i]];
}
return listOfValues;
}
function getKeyAtIndex(Map storage map, uint256 index) public view returns (string memory) {
return map.keys[index];
}
function size(Map storage map) public view returns (uint256) {
return map.keys.length;
}
function set(Map storage map, string memory key, uint256 val) public {
if (map.inserted[key]) {
map.values[key] = val;
} else {
map.inserted[key] = true;
map.values[key] = val;
map.indexOf[key] = map.keys.length;
map.keys.push(key);
}
}
function remove(Map storage map, string memory key) public {
if (!map.inserted[key]) {
return;
}
delete map.inserted[key];
delete map.values[key];
uint256 index = map.indexOf[key];
string memory lastKey = map.keys[map.keys.length - 1];
map.indexOf[lastKey] = index;
delete map.indexOf[key];
map.keys[index] = lastKey;
map.keys.pop();
}
}
</code>
<code>pragma solidity >=0.8.25 <0.9.0; import "test/TestConstants.sol"; library IterableMapping { // Iterable mapping from string[] to uint; struct Map { string[] keys; mapping(string => uint256) values; mapping(string => uint256) indexOf; mapping(string => bool) inserted; } function get(Map storage map, string memory key) public view returns (uint256) { return map.values[key]; } function getKeys(Map storage map) public view returns (string[] memory) { return map.keys; } function getValues(Map storage map) public view returns (uint256[] memory) { uint256[] memory listOfValues = new uint256[](_MAX_NR_OF_TEST_LOG_VALUES_PER_LOG_FILE); for (uint256 i = 0; i < map.keys.length - 1; i++) { listOfValues[i] = map.values[map.keys[i]]; } return listOfValues; } function getKeyAtIndex(Map storage map, uint256 index) public view returns (string memory) { return map.keys[index]; } function size(Map storage map) public view returns (uint256) { return map.keys.length; } function set(Map storage map, string memory key, uint256 val) public { if (map.inserted[key]) { map.values[key] = val; } else { map.inserted[key] = true; map.values[key] = val; map.indexOf[key] = map.keys.length; map.keys.push(key); } } function remove(Map storage map, string memory key) public { if (!map.inserted[key]) { return; } delete map.inserted[key]; delete map.values[key]; uint256 index = map.indexOf[key]; string memory lastKey = map.keys[map.keys.length - 1]; map.indexOf[lastKey] = index; delete map.indexOf[key]; map.keys[index] = lastKey; map.keys.pop(); } } </code>
pragma solidity >=0.8.25 <0.9.0;
import "test/TestConstants.sol";

library IterableMapping {
  // Iterable mapping from string[] to uint;
  struct Map {
    string[] keys;
    mapping(string => uint256) values;
    mapping(string => uint256) indexOf;
    mapping(string => bool) inserted;
  }

  function get(Map storage map, string memory key) public view returns (uint256) {
    return map.values[key];
  }

  function getKeys(Map storage map) public view returns (string[] memory) {
    return map.keys;
  }

  function getValues(Map storage map) public view returns (uint256[] memory) {
    uint256[] memory listOfValues = new uint256[](_MAX_NR_OF_TEST_LOG_VALUES_PER_LOG_FILE);
    for (uint256 i = 0; i < map.keys.length - 1; i++) {
      listOfValues[i] = map.values[map.keys[i]];
    }
    return listOfValues;
  }

  function getKeyAtIndex(Map storage map, uint256 index) public view returns (string memory) {
    return map.keys[index];
  }

  function size(Map storage map) public view returns (uint256) {
    return map.keys.length;
  }

  function set(Map storage map, string memory key, uint256 val) public {
    if (map.inserted[key]) {
      map.values[key] = val;
    } else {
      map.inserted[key] = true;
      map.values[key] = val;
      map.indexOf[key] = map.keys.length;
      map.keys.push(key);
    }
  }

  function remove(Map storage map, string memory key) public {
    if (!map.inserted[key]) {
      return;
    }

    delete map.inserted[key];
    delete map.values[key];

    uint256 index = map.indexOf[key];
    string memory lastKey = map.keys[map.keys.length - 1];

    map.indexOf[lastKey] = index;
    delete map.indexOf[key];

    map.keys[index] = lastKey;
    map.keys.pop();
  }
}

and when I try to read that mapping back from a file with:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>(string memory hitRateFilePath, bytes memory data) = _testFileLogging.updateLogFile(_map.getKeys(), _map.getValues());
// IterableMapping.Map something = abi.decode(data, (IterableMapping));
// IterableMapping.Map memory something = abi.decode(data, (IterableMapping));
// IterableMapping.Map storage something = abi.decode(data, (IterableMapping));
// IterableMapping.Map calldata something = abi.decode(data, (IterableMapping));
// IterableMapping something = abi.decode(data, (IterableMapping));
// IterableMapping memory something = abi.decode(data, (IterableMapping));
// IterableMapping storage something = abi.decode(data, (IterableMapping));
// IterableMapping calldata something = abi.decode(data, (IterableMapping));
</code>
<code>(string memory hitRateFilePath, bytes memory data) = _testFileLogging.updateLogFile(_map.getKeys(), _map.getValues()); // IterableMapping.Map something = abi.decode(data, (IterableMapping)); // IterableMapping.Map memory something = abi.decode(data, (IterableMapping)); // IterableMapping.Map storage something = abi.decode(data, (IterableMapping)); // IterableMapping.Map calldata something = abi.decode(data, (IterableMapping)); // IterableMapping something = abi.decode(data, (IterableMapping)); // IterableMapping memory something = abi.decode(data, (IterableMapping)); // IterableMapping storage something = abi.decode(data, (IterableMapping)); // IterableMapping calldata something = abi.decode(data, (IterableMapping)); </code>
(string memory hitRateFilePath, bytes memory data) = _testFileLogging.updateLogFile(_map.getKeys(), _map.getValues());
        // IterableMapping.Map something = abi.decode(data, (IterableMapping));
    // IterableMapping.Map memory something = abi.decode(data, (IterableMapping));
    // IterableMapping.Map storage something = abi.decode(data, (IterableMapping));
    // IterableMapping.Map calldata something = abi.decode(data, (IterableMapping));

    // IterableMapping  something = abi.decode(data, (IterableMapping));
    // IterableMapping memory something = abi.decode(data, (IterableMapping));
    // IterableMapping storage something = abi.decode(data, (IterableMapping));
    // IterableMapping calldata something = abi.decode(data, (IterableMapping));

I get the error:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Compiler run failed:
Error (9574): Type library IterableMapping is not implicitly convertible to expected type struct IterableMapping.Map storage pointer.
--> test/functional/DecentralisedInvestmentManager/triggerReturnAll/TestWithRandomNrOfInvestments.sol:108:5:
|
108 | IterableMapping.Map storage something = abi.decode(data, (IterableMapping));
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error:
Compilation failed
``
## Question
How can I decode the data that is written to file with:
```sol
function updateLogFile(
string[] memory keys,
uint256[] memory values) public returns (string memory hitRateFilePath, bytes memory data) {
// initialiseHitRates();
// Output hit rates to file if they do not exist yet.
string memory serialisedTextString = convertHitRatesToString(keys,values);
hitRateFilePath = createLogFileIfItDoesNotExist(_LOG_TIME_CREATOR, serialisedTextString);
// Read the latest hitRates from file.
data = readDataFromFile(hitRateFilePath);
return (hitRateFilePath, data);
}
</code>
<code>Compiler run failed: Error (9574): Type library IterableMapping is not implicitly convertible to expected type struct IterableMapping.Map storage pointer. --> test/functional/DecentralisedInvestmentManager/triggerReturnAll/TestWithRandomNrOfInvestments.sol:108:5: | 108 | IterableMapping.Map storage something = abi.decode(data, (IterableMapping)); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Error: Compilation failed `` ## Question How can I decode the data that is written to file with: ```sol function updateLogFile( string[] memory keys, uint256[] memory values) public returns (string memory hitRateFilePath, bytes memory data) { // initialiseHitRates(); // Output hit rates to file if they do not exist yet. string memory serialisedTextString = convertHitRatesToString(keys,values); hitRateFilePath = createLogFileIfItDoesNotExist(_LOG_TIME_CREATOR, serialisedTextString); // Read the latest hitRates from file. data = readDataFromFile(hitRateFilePath); return (hitRateFilePath, data); } </code>
Compiler run failed:
Error (9574): Type library IterableMapping is not implicitly convertible to expected type struct IterableMapping.Map storage pointer.
   --> test/functional/DecentralisedInvestmentManager/triggerReturnAll/TestWithRandomNrOfInvestments.sol:108:5:
    |
108 |     IterableMapping.Map storage something = abi.decode(data, (IterableMapping));
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Error: 
Compilation failed
``

## Question
How can I decode the data that is written to file with:
```sol
function updateLogFile(
    string[] memory keys,
    uint256[] memory values) public returns (string memory hitRateFilePath, bytes memory data) {
    // initialiseHitRates();
    // Output hit rates to file if they do not exist yet.
    string memory serialisedTextString = convertHitRatesToString(keys,values);
    hitRateFilePath = createLogFileIfItDoesNotExist(_LOG_TIME_CREATOR, serialisedTextString);
    // Read the latest hitRates from file.
    data = readDataFromFile(hitRateFilePath);
    return (hitRateFilePath, data);
  }

back into the mapping?

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật