12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- pragma solidity ^0.5.0;
- import "../GSN/Context.sol";
- /**
- * @dev A Secondary contract can only be used by its primary account (the one that created it).
- */
- contract Secondary is Context {
- address private _primary;
- /**
- * @dev Emitted when the primary contract changes.
- */
- event PrimaryTransferred(
- address recipient
- );
- /**
- * @dev Sets the primary account to the one that is creating the Secondary contract.
- */
- constructor () internal {
- _primary = _msgSender();
- emit PrimaryTransferred(_primary);
- }
- /**
- * @dev Reverts if called from any account other than the primary.
- */
- modifier onlyPrimary() {
- require(_msgSender() == _primary, "Secondary: caller is not the primary account");
- _;
- }
- /**
- * @return the address of the primary.
- */
- function primary() public view returns (address) {
- return _primary;
- }
- /**
- * @dev Transfers contract to a new primary.
- * @param recipient The address of new primary.
- */
- function transferPrimary(address recipient) public onlyPrimary {
- require(recipient != address(0), "Secondary: new primary is the zero address");
- _primary = recipient;
- emit PrimaryTransferred(_primary);
- }
- }
|