gpt4 book ai didi

arrays - Solidity:UnimplementedFeatureError:此处未实现嵌套动态数组

转载 作者:行者123 更新时间:2023-12-05 01:00:40 25 4
gpt4 key购买 nike

当我尝试在 Solidity 中执行此操作时,它给了我UnimplementedFeatureError:此处未实现嵌套动态数组。

我在代码示例中看到了这一点。 Solidity 不支持吗?

编辑 - 在下面发布完整代码。所以我发现问题只出在最后一个函数中。它不喜欢我返回一个动态数组。我怎样才能实现相同的功能(我想返回一个字符串数组)?

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;
}

}

最佳答案

Solidity 和 Javascript 允许嵌套数组,但我们无法将嵌套动态数组从 Solidity 拉到 javascript 世界。

这是solidity和javascript之间桥梁的限制。由于solidity内部的字符串被表示为动态数组,我们不能传输字符串数组。

关于arrays - Solidity:UnimplementedFeatureError:此处未实现嵌套动态数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48309171/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com