2

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?

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
Yaa_seen
  • 21
  • 4

1 Answers1

1

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;
Yaa_seen
  • 21
  • 4
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 29 '21 at 19:25