Skip to content

Commit

Permalink
update grant struct
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Lima committed Aug 30, 2023
1 parent d9843be commit a0d580b
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions contracts/ImmutableVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ contract ImmutableVault is AccessControl {
struct Grant {
bytes32 role;
address grantee;
uint64 expirationDate;
bytes data;
}

Expand Down Expand Up @@ -110,40 +109,40 @@ contract ImmutableVault is AccessControl {
uint256 _nonce,
address _tokenAddress,
uint256 _tokenId,
uint64 _expirationDate,
Grant[] memory _grants
) external onlyRole(MARKETPLACE_ROLE) {
address _tokenOwner = ownerOf[_tokenAddress][_tokenId];
require(
nonceExpirationDate[_tokenOwner][_nonce] < block.timestamp,
"ImmutableVault: token has an active grant"
);
require(
deadlines[_tokenOwner][_tokenAddress][_tokenId] >= _expirationDate,
"ImmutableVault: token deadline is before the grant expiration date"
);

for (uint256 i = 0; i < _grants.length; i++) {
_grantRole(_nonce, _tokenOwner, _tokenAddress, _tokenId, _grants[i]);
_grantRole(_tokenAddress, _tokenId,_expirationDate, _grants[i]);
grants[_tokenOwner][_nonce].push(_grants[i]);
}

nonces[_tokenOwner] = _nonce;
nonceExpirationDate[_tokenOwner][_nonce] = _expirationDate;
}

function _grantRole(
uint256 _nonce,
address _tokenOwner,
address _tokenAddress,
uint256 _tokenId,
uint64 _expirationDate,
Grant memory _grant
) internal {
require(
deadlines[_tokenOwner][_tokenAddress][_tokenId] >= _grant.expirationDate,
"ImmutableVault: token deadline is before the grant expiration date"
);

if (_grant.expirationDate > nonceExpirationDate[_tokenOwner][_nonce]) {
nonceExpirationDate[_tokenOwner][_nonce] = _grant.expirationDate;
}

IRolesRegistry(rolesRegistry).grantRole(
_grant.role,
_tokenAddress,
_tokenId,
_grant.grantee,
_grant.expirationDate,
_expirationDate,
_grant.data
);
}
Expand Down

0 comments on commit a0d580b

Please sign in to comment.