Solidity storing struct data in an address

1.5k Views Asked by At

In solidity I want to allow registering for classes on the blockchain. Just like eventbrite. A wallet should have access to an array of classes. I am not sure how to structure this data but this is what I tried.

pragma solidity ^0.4.2;

contract SimpleStorage {
  mapping(address => EventClass[]) class_event; 

  struct EventClass {
      uint start_time;
      string title;
      string first_name;
      string last_name;
  }

  function registerTicket(){
    class_event[msg.sender][0].first_name = "Alain";
  }
}

Here I have an array of structs mapped into addresses. However, this code is broken. What is wrong with my logic.

1

There are 1 best solutions below

0
On BEST ANSWER

Got it, it's more like this

pragma solidity ^0.4.2;

contract SimpleStorage {
  mapping(address => Pass[]) passes; 

  struct Pass {
      string first_name;
      string last_name;
  }

  function submitPass(){
      passes[msg.sender].push(Pass({
          first_name: "Alain",
          last_name: "Goldman"
      }));
  }

  function whatsInFirst() returns(string){
      return passes[msg.sender][1].first_name;
  }
}