Skip to content

Commit

Permalink
ON-476: Adds approval internal function
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Lima committed Sep 19, 2023
1 parent 75e41b2 commit 9b5437c
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions contracts/ERC7432/ERC7432.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ contract ERC7432 is IERC7432 {

modifier onlyApproved(address _tokenAddress, uint256 _tokenId, address _grantor) {
require(
isRoleApprovedForAll(_tokenAddress, _grantor, msg.sender) ||
getApprovedRole(_tokenAddress, _tokenId, _grantor, msg.sender),
_isRoleApproved(_tokenAddress, _tokenId, _grantor, msg.sender),
"ERC7432: sender must be approved"
);
_;
Expand Down Expand Up @@ -83,8 +82,8 @@ contract ERC7432 is IERC7432 {
address _revoker,
address _grantee
) external override {
bool _isRevokerApproved = isRoleApprovedForAll(_tokenAddress, _revoker, msg.sender) || getApprovedRole(_tokenAddress, _tokenId, _revoker, msg.sender);
bool _isGranteeApproved = isRoleApprovedForAll(_tokenAddress, _grantee, msg.sender) || getApprovedRole(_tokenAddress, _tokenId, _grantee, msg.sender);
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.
Expand Down Expand Up @@ -188,4 +187,13 @@ contract ERC7432 is IERC7432 {
) public view override returns (bool) {
return tokenIdApprovals[_grantor][_tokenAddress][_tokenId][_operator];
}

function _isRoleApproved(
address _tokenAddress,
uint256 _tokenId,
address _grantor,
address _operator
) internal view returns (bool) {
return isRoleApprovedForAll(_tokenAddress, _grantor, _operator) || getApprovedRole(_tokenAddress, _tokenId, _grantor, _operator);
}
}

0 comments on commit 9b5437c

Please # to comment.