8

How would I have the following data structure be saved in an Ethereum contract using solidity?

{
  address1 => [struct1, struct2, struct3, struct4, struct5],
  address2 => [struct1, struct2, struct3, struct4, struct5],
  address3 => [struct1, struct2, struct3, struct4, struct5],
  ...
}

The goal is for me to be able to easily access the array of structs associated to each user/address.

Pabi
  • 1,129
  • 4
  • 11
  • 18

1 Answers1

9

Here is an example :

pragma solidity ^0.4.2;
contract test {

  struct my_struct {
    int a;
  }

  mapping (address=>my_struct[]) Map;

  function fill_map(my_struct struct1,my_struct struct2) internal  {

    Map[msg.sender].push(struct1);
    Map[msg.sender].push(struct2);

  }
}
Badr Bellaj
  • 18,780
  • 4
  • 58
  • 75