Solidity Error : Construction of struct that contains a nested mapping

Viewed 316

I'm using solidity solc^0.8.0 to build a smart contract, and I've got the following problem:

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

The first line gives me two errors :

Types in storage containing (nested) mappings cannot be assigned to.

Struct containing a (nested) mapping cannot be constructed.

What is the correct pattern to make these two errors vanish?

1 Answers

After doing some research, I think we should change the following code from :

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

to the following :

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