【问题标题】:Solidity Error : Construction of struct that contains a nested mappingSolidity 错误:构造包含嵌套映射的结构
【发布时间】:2021-12-27 17:54:00
【问题描述】:

我正在使用solidity solc^0.8.0构建智能合约,我遇到了以下问题:

// some lines of code 
oracleResponses[key] = ResponseInfo({ 
   requester: msg.sender, 
   isOpen: true}); // here the compiler complains about a the construction of a struct that contains a mapping

// some lines of code
struct ResponseInfo {
    address requester;                            
    bool isOpen;                                      
    mapping(uint8 => address[]) responses; // I think this what causes the problem                                                                                                                    
}    

 mapping(bytes32 => ResponseInfo) private oracleResponses;

第一行给了我两个错误:

无法分配包含(嵌套)映射的存储类型。

无法构造包含(嵌套)映射的结构。

使这两个错误消失的正确模式是什么?

【问题讨论】:

    标签: ethereum solidity smartcontracts truffle


    【解决方案1】:

    经过一番研究,我认为我们应该将以下代码更改为:

    oracleResponses[key] = ResponseInfo({requester: msg.sender, isOpen: true});
    

    到以下:

    oracleResponses[key].requester = msg.sender;
    oracleResponses[key].isOpen = true;
    

    【讨论】:

    • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 2020-12-29
    • 2020-11-20
    • 2021-10-13
    • 2021-01-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-28
    • 1970-01-01
    相关资源
    最近更新 更多