|
| 1 | +// SPDX-License-Identifier: Apache-2.0 |
| 2 | +// Copyright 2017 Loopring Technology Limited. |
| 3 | +pragma solidity ^0.7.0; |
| 4 | +pragma experimental ABIEncoderV2; |
| 5 | + |
| 6 | +import "../../base/BaseWallet.sol"; |
| 7 | +import "../../stores/SecurityStore.sol"; |
| 8 | +import "../base/BaseModule.sol"; |
| 9 | + |
| 10 | + |
| 11 | +/// @title AddOfficialGuardianModule |
| 12 | +/// @dev This module adds the official guardian to a wallet and removes itself |
| 13 | +/// from the module list. |
| 14 | +/// |
| 15 | +/// @author Daniel Wang - <daniel@loopring.org> |
| 16 | +contract AddOfficialGuardianModule is BaseModule { |
| 17 | + ControllerImpl private controller_; |
| 18 | + address public officialGuardian; |
| 19 | + uint public officialGuardianGroup; |
| 20 | + |
| 21 | + constructor( |
| 22 | + ControllerImpl _controller, |
| 23 | + address _officialGuardian, |
| 24 | + uint _officialGuardianGroup |
| 25 | + ) |
| 26 | + { |
| 27 | + controller_ = _controller; |
| 28 | + officialGuardian = _officialGuardian; |
| 29 | + officialGuardianGroup = _officialGuardianGroup; |
| 30 | + } |
| 31 | + |
| 32 | + function controller() |
| 33 | + internal |
| 34 | + view |
| 35 | + override |
| 36 | + returns(ControllerImpl) |
| 37 | + { |
| 38 | + return ControllerImpl(controller_); |
| 39 | + } |
| 40 | + |
| 41 | + function bindableMethods() |
| 42 | + public |
| 43 | + pure |
| 44 | + override |
| 45 | + returns (bytes4[] memory methods) |
| 46 | + { |
| 47 | + } |
| 48 | + |
| 49 | + function activate() |
| 50 | + external |
| 51 | + override |
| 52 | + { |
| 53 | + address payable wallet = msg.sender; |
| 54 | + |
| 55 | + SecurityStore ss = controller().securityStore(); |
| 56 | + require( |
| 57 | + ss.numGuardiansWithPending(wallet) == 0, |
| 58 | + "NOT_THE_FIRST_GUARDIAN" |
| 59 | + ); |
| 60 | + |
| 61 | + ss.addGuardian( |
| 62 | + wallet, |
| 63 | + officialGuardian, |
| 64 | + officialGuardianGroup, |
| 65 | + block.timestamp |
| 66 | + ); |
| 67 | + |
| 68 | + BaseWallet(wallet).removeModule(address(this)); |
| 69 | + } |
| 70 | +} |
0 commit comments