ShowFactory.sol 912 B

1234567891011121314151617181920212223242526272829303132333435
  1. pragma solidity ^0.4.23;
  2. import "./Ownable.sol";
  3. contract ShowFactory is Ownable {
  4. event NewShow(uint id, string name, bytes music);
  5. struct Show {
  6. string name;
  7. bytes dance;
  8. bytes music;
  9. }
  10. Show[] public shows;
  11. mapping (uint=>address) public showToOwner;
  12. mapping (address=>uint) public ownerShowCount;
  13. modifier onlyOwnerOf(uint id) {
  14. require(msg.sender == showToOwner[id]);
  15. _;
  16. }
  17. function _createShow(string name, bytes dance, bytes music) internal {
  18. uint id = shows.push(Show(name, dance, music)) - 1;
  19. showToOwner[id] = msg.sender;
  20. ownerShowCount[msg.sender]++;
  21. emit NewShow(id, name, music);
  22. }
  23. function createFirstShow(string name, bytes dance, bytes music) public {
  24. require(ownerShowCount[msg.sender] == 0); // The 1st show is free
  25. _createShow(name, dance, music);
  26. }
  27. }