From 4c0e1dae2de73a442e26acd300f0ddc3dc06cfef Mon Sep 17 00:00:00 2001 From: Daniel Lima Date: Tue, 19 Sep 2023 15:28:11 -0300 Subject: [PATCH] ON-476: PR fixes --- contracts/ERC7432/ERC7432.sol | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/contracts/ERC7432/ERC7432.sol b/contracts/ERC7432/ERC7432.sol index aac5dcd..f3b8ee1 100644 --- a/contracts/ERC7432/ERC7432.sol +++ b/contracts/ERC7432/ERC7432.sol @@ -23,9 +23,9 @@ contract ERC7432 is IERC7432 { _; } - modifier onlyApproved(address _tokenAddress, uint256 _tokenId, address _grantor) { + modifier onlyApproved(address _tokenAddress, uint256 _tokenId, address _account) { require( - _isRoleApproved(_tokenAddress, _tokenId, _grantor, msg.sender), + _isRoleApproved(_tokenAddress, _tokenId, _account, msg.sender), "ERC7432: sender must be approved" ); _; @@ -82,15 +82,20 @@ contract ERC7432 is IERC7432 { address _revoker, address _grantee ) external override { - bool _isRevokerApproved = _isRoleApproved(_tokenAddress, _tokenId, _revoker, msg.sender); - bool _isGranteeApproved = _isRoleApproved(_tokenAddress, _tokenId, _grantee, msg.sender); - require(_isRevokerApproved || _isGranteeApproved, "ERC7432: sender must be approved"); - - address _caller = _isGranteeApproved ? _grantee : _revoker; // In case of operator being approved for both grantee and revoker, the grantee will be the caller. - + address _caller = _getApprovedCaller(_tokenAddress, _tokenId, _revoker, _grantee); _revokeRole(_role, _tokenAddress, _tokenId, _revoker, _grantee, _caller); } + function _getApprovedCaller(address _tokenAddress, uint256 _tokenId, address _revoker, address _grantee) internal view returns (address) { + if(_isRoleApproved(_tokenAddress, _tokenId, _grantee, msg.sender)){ + return _grantee; + } else if(_isRoleApproved(_tokenAddress, _tokenId, _revoker, msg.sender)){ + return _revoker; + } else { + revert("ERC7432: sender must be approved"); + } + } + function _revokeRole( bytes32 _role, address _tokenAddress,