3

I have two structs

struct Vote {
  address from;
  uint256 rep;
  bool vote;
}

struct Pool { 
  address from;  
  string tokenSymbol;
  string name; 
  uint256 timeout;  
  string evidence;  
  Vote[] votes;
}

mapping(uint256 => Pool) validationPool;

How do I initialize an empty array of votes while creating a new Pool Struct?

    validationPool[proposalIndex] = Pool({
        from: msg.sender, tokenSymbol:_tokenSymbol,
        name:_name, 
        timeout: now + 180, 
        evidence:_evidence, 
        votes: new Vote[](0) });

I see the compilation error :

UnimplementedFeatureError: Copying of type struct DemoContract.Vote memory[] memory to storage not yet supported. What does it mean and how do I initialize an array of structs inside another struct?

1

I am still looking for the right way of doing it but found a work around. Here, there was no value associated with this proposalIndex in validationPool.

    Pool storage pool = validationPool[proposalIndex];
    pool.from = msg.sender;
    pool.name = _name;
    pool.timeout = now + 180;
    pool.evidence = _evidence;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.