Secondary.sol 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. address msgSender = _msgSender();
  19. _primary = msgSender;
  20. emit PrimaryTransferred(msgSender);
  21. }
  22. /**
  23. * @dev Reverts if called from any account other than the primary.
  24. */
  25. modifier onlyPrimary() {
  26. require(_msgSender() == _primary, "Secondary: caller is not the primary account");
  27. _;
  28. }
  29. /**
  30. * @return the address of the primary.
  31. */
  32. function primary() public view returns (address) {
  33. return _primary;
  34. }
  35. /**
  36. * @dev Transfers contract to a new primary.
  37. * @param recipient The address of new primary.
  38. */
  39. function transferPrimary(address recipient) public onlyPrimary {
  40. require(recipient != address(0), "Secondary: new primary is the zero address");
  41. _primary = recipient;
  42. emit PrimaryTransferred(recipient);
  43. }
  44. }