Solidity Error : Construction of struct that contains a nested mapping
Solidity Error : Construction of struct that contains a nested mapping
我正在使用 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;
第一行给我两个错误:
Types in storage containing (nested) mappings cannot be assigned to.
Struct containing a (nested) mapping cannot be constructed.
使这两个错误消失的正确模式是什么?
经过一些研究,我认为我们应该更改以下代码:
oracleResponses[key] = ResponseInfo({requester: msg.sender, isOpen: true});
以下内容:
oracleResponses[key].requester = msg.sender;
oracleResponses[key].isOpen = true;
我正在使用 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;
第一行给我两个错误:
Types in storage containing (nested) mappings cannot be assigned to.
Struct containing a (nested) mapping cannot be constructed.
使这两个错误消失的正确模式是什么?
经过一些研究,我认为我们应该更改以下代码:
oracleResponses[key] = ResponseInfo({requester: msg.sender, isOpen: true});
以下内容:
oracleResponses[key].requester = msg.sender;
oracleResponses[key].isOpen = true;