Secondary.sol 1.2 KB

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