Secondary.sol 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. pragma solidity ^0.5.0;
  2. /**
  3. * @dev A Secondary contract can only be used by its primary account (the one that created it).
  4. */
  5. contract Secondary {
  6. address private _primary;
  7. /**
  8. * @dev Emitted when the primary contract changes.
  9. */
  10. event PrimaryTransferred(
  11. address recipient
  12. );
  13. /**
  14. * @dev Sets the primary account to the one that is creating the Secondary contract.
  15. */
  16. constructor () internal {
  17. _primary = msg.sender;
  18. emit PrimaryTransferred(_primary);
  19. }
  20. /**
  21. * @dev Reverts if called from any account other than the primary.
  22. */
  23. modifier onlyPrimary() {
  24. require(msg.sender == _primary, "Secondary: caller is not the primary account");
  25. _;
  26. }
  27. /**
  28. * @return the address of the primary.
  29. */
  30. function primary() public view returns (address) {
  31. return _primary;
  32. }
  33. /**
  34. * @dev Transfers contract to a new primary.
  35. * @param recipient The address of new primary.
  36. */
  37. function transferPrimary(address recipient) public onlyPrimary {
  38. require(recipient != address(0), "Secondary: new primary is the zero address");
  39. _primary = recipient;
  40. emit PrimaryTransferred(_primary);
  41. }
  42. }