From 67f568c4acc13e7aa1472a7fa1685d6f896a87a7 Mon Sep 17 00:00:00 2001 From: Juan Bautista Carpanelli Date: Thu, 7 Oct 2021 09:46:17 -0400 Subject: [PATCH] Add upgradeTo function --- contracts/contracts/levels/PuzzleWallet.sol | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/contracts/contracts/levels/PuzzleWallet.sol b/contracts/contracts/levels/PuzzleWallet.sol index 95118733c..0796ed623 100644 --- a/contracts/contracts/levels/PuzzleWallet.sol +++ b/contracts/contracts/levels/PuzzleWallet.sol @@ -13,16 +13,24 @@ contract PuzzleProxy is UpgradeableProxy { admin = _admin; } + modifier onlyAdmin { + require(msg.sender == admin, "Caller is not the admin"); + _; + } + // Anyone can propose a new admin, but the current admin must accept the change in the `changeAdmin` function function proposeNewAdmin(address _newAdmin) external { pendingAdmin = _newAdmin; } - function approveNewAdmin(address _expectedAdmin) external { - require(msg.sender == admin, "Caller is not the admin"); + function approveNewAdmin(address _expectedAdmin) external onlyAdmin { require(pendingAdmin == _expectedAdmin, "Expected new admin by the current admin is not the pending admin"); admin = pendingAdmin; } + + function upgradeTo(address _newImplementation) external onlyAdmin { + _upgradeTo(_newImplementation); + } } contract PuzzleWallet {