Secondary.sol 1.3 KB

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