Skip to content

Commit

Permalink
feat: grant
Browse files Browse the repository at this point in the history
  • Loading branch information
thashimoto1998 committed May 1, 2024
1 parent a7c5d27 commit 6010c31
Show file tree
Hide file tree
Showing 11 changed files with 229 additions and 2 deletions.
26 changes: 26 additions & 0 deletions contracts/access-condition/ERC1155/VWBLERC1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ contract VWBLERC1155 is Ownable, ERC1155Enumerable, ERC1155Burnable, AbstractVWB
using SafeMath for uint256;
using Strings for uint256;

// tokenId => grantee => bool
mapping (uint256 => mapping (address => bool)) public hasViewRight;

Check failure on line 20 in contracts/access-condition/ERC1155/VWBLERC1155.sol

View workflow job for this annotation

GitHub Actions / test-contract

Replace ·(uint256·=>·mapping· with (uint256·=>·mapping

event ViewRightGranted(uint256 tokenId, address grantee);

constructor(
string memory _baseURI,
address _gatewayProxy,
Expand Down Expand Up @@ -119,4 +124,25 @@ contract VWBLERC1155 is Ownable, ERC1155Enumerable, ERC1155Burnable, AbstractVWB
IVWBLGateway(getGatewayAddress()).payFee{value: fee}(tokenIdToTokenInfo[ids[i]].documentId, to);
}
}

/**
* @notice Grant view permission to grantee from nft owner
* @param tokenId The identifier of NFT
* @param grantee The Address who grantee of view permission right

Check failure on line 131 in contracts/access-condition/ERC1155/VWBLERC1155.sol

View workflow job for this annotation

GitHub Actions / test-contract

Delete ·
*/
function grantViewPermission(uint256 tokenId, address grantee) public returns (uint256) {
require(balanceOf(msg.sender, tokenId) > 0, "msg sender is not nft owner");
hasViewRight[tokenId][grantee] = true;
emit ViewRightGranted(tokenId, grantee);
return tokenId;
}

/**
* @notice Check view permission to user
* @param tokenId The Identifier of NFT
* @param user The address of verification target
*/
function checkViewPermission(uint256 tokenId, address user) public view returns (bool) {
return hasViewRight[tokenId][user];
}
}
27 changes: 27 additions & 0 deletions contracts/access-condition/ERC1155/VWBLERC1155ERC2981.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ contract VWBLERC1155ERC2981 is Ownable, ERC1155Enumerable, ERC1155Burnable, Abst
using SafeMath for uint256;
using Strings for uint256;

// tokenId => grantee => bool
mapping (uint256 => mapping (address => bool)) public hasViewRight;

Check failure on line 21 in contracts/access-condition/ERC1155/VWBLERC1155ERC2981.sol

View workflow job for this annotation

GitHub Actions / test-contract

Replace ·(uint256·=>·mapping· with (uint256·=>·mapping

event ViewRightGranted(uint256 tokenId, address grantee);

Check failure on line 23 in contracts/access-condition/ERC1155/VWBLERC1155ERC2981.sol

View workflow job for this annotation

GitHub Actions / test-contract

Delete ⏎


constructor(
string memory _baseURI,
address _gatewayProxy,
Expand Down Expand Up @@ -146,4 +152,25 @@ contract VWBLERC1155ERC2981 is Ownable, ERC1155Enumerable, ERC1155Burnable, Abst
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC1155, ERC2981) returns (bool) {
return super.supportsInterface(interfaceId);
}

/**
* @notice Grant view permission to grantee from nft owner
* @param tokenId The identifier of NFT
* @param grantee The Address who grantee of view permission right

Check failure on line 159 in contracts/access-condition/ERC1155/VWBLERC1155ERC2981.sol

View workflow job for this annotation

GitHub Actions / test-contract

Delete ·
*/
function grantViewPermission(uint256 tokenId, address grantee) public returns (uint256) {
require(balanceOf(msg.sender, tokenId) > 0, "msg sender is not nft owner");
hasViewRight[tokenId][grantee] = true;
emit ViewRightGranted(tokenId, grantee);
return tokenId;
}

/**
* @notice Check view permission to user
* @param tokenId The Identifier of NFT
* @param user The address of verification target
*/
function checkViewPermission(uint256 tokenId, address user) public view returns (bool) {
return hasViewRight[tokenId][user];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ contract VWBLERC1155ERC2981ForMetadata is Ownable, ERC1155Enumerable, ERC1155Bur

mapping(uint256 => string) private _tokenURIs;

// tokenId => grantee => bool
mapping (uint256 => mapping (address => bool)) public hasViewRight;

Check failure on line 23 in contracts/access-condition/ERC1155/extensions/VWBLERC1155ERC2981ForMetadata.sol

View workflow job for this annotation

GitHub Actions / test-contract

Replace ·(uint256·=>·mapping· with (uint256·=>·mapping

event ViewRightGranted(uint256 tokenId, address grantee);

Check failure on line 25 in contracts/access-condition/ERC1155/extensions/VWBLERC1155ERC2981ForMetadata.sol

View workflow job for this annotation

GitHub Actions / test-contract

Delete ⏎


constructor(
address _gatewayProxy,
address _accessCheckerContract,
Expand Down Expand Up @@ -154,4 +160,25 @@ contract VWBLERC1155ERC2981ForMetadata is Ownable, ERC1155Enumerable, ERC1155Bur
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC1155, ERC2981) returns (bool) {
return super.supportsInterface(interfaceId);
}

/**
* @notice Grant view permission to grantee from nft owner
* @param tokenId The identifier of NFT
* @param grantee The Address who grantee of view permission right

Check failure on line 167 in contracts/access-condition/ERC1155/extensions/VWBLERC1155ERC2981ForMetadata.sol

View workflow job for this annotation

GitHub Actions / test-contract

Delete ·
*/
function grantViewPermission(uint256 tokenId, address grantee) public returns (uint256) {
require(balanceOf(msg.sender, tokenId) > 0, "msg sender is not nft owner");
hasViewRight[tokenId][grantee] = true;
emit ViewRightGranted(tokenId, grantee);
return tokenId;
}

/**
* @notice Check view permission to user
* @param tokenId The Identifier of NFT
* @param user The address of verification target
*/
function checkViewPermission(uint256 tokenId, address user) public view returns (bool) {
return hasViewRight[tokenId][user];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import "./interfaces/IERC6150ParentTransferable.sol";
abstract contract ERC6150ParentTransferable is ERC6150, IERC6150ParentTransferable {
function transferParent(uint256 newParentId, uint256 tokenId) public virtual override {
require(
_isApprovedOrOwner(_msgSender(), tokenId),
_isApprovedOrOwner(msg.sender, tokenId),
"ERC6150ParentTransferable: caller is not token owner nor approved"
);
if (newParentId != 0) {
Expand Down
26 changes: 26 additions & 0 deletions contracts/access-condition/ERC6150/VWBLERC6150.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ contract VWBLERC6150 is Ownable, ERC6150ParentTransferable, AbstractVWBLToken {
using SafeMath for uint256;
using Strings for uint256;

// tokenId => grantee => bool
mapping (uint256 => mapping (address => bool)) public hasViewRight;

Check failure on line 19 in contracts/access-condition/ERC6150/VWBLERC6150.sol

View workflow job for this annotation

GitHub Actions / test-contract

Replace ·(uint256·=>·mapping· with (uint256·=>·mapping

event ViewRightGranted(uint256 tokenId, address grantee);

constructor(
string memory _baseURI,
address _gatewayProxy,
Expand Down Expand Up @@ -57,4 +62,25 @@ contract VWBLERC6150 is Ownable, ERC6150ParentTransferable, AbstractVWBLToken {
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC6150) returns (bool) {
return super.supportsInterface(interfaceId);
}

/**
* @notice Grant view permission to grantee from nft owner
* @param tokenId The identifier of NFT
* @param grantee The Address who grantee of view permission right

Check failure on line 69 in contracts/access-condition/ERC6150/VWBLERC6150.sol

View workflow job for this annotation

GitHub Actions / test-contract

Delete ·
*/
function grantViewPermission(uint256 tokenId, address grantee) public returns (uint256) {
require(msg.sender == ownerOf(tokenId), "msg sender is not nft owner");
hasViewRight[tokenId][grantee] = true;
emit ViewRightGranted(tokenId, grantee);
return tokenId;
}

/**
* @notice Check view permission to user
* @param tokenId The Identifier of NFT
* @param user The address of verification target
*/
function checkViewPermission(uint256 tokenId, address user) public view returns (bool) {
return hasViewRight[tokenId][user];
}
}
26 changes: 26 additions & 0 deletions contracts/access-condition/ERC6150/VWBLERC6150ERC2981.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ contract VWBLERC6150ERC2981 is Ownable, ERC6150ParentTransferable, AbstractVWBLT
using SafeMath for uint256;
using Strings for uint256;

// tokenId => grantee => bool
mapping (uint256 => mapping (address => bool)) public hasViewRight;

event ViewRightGranted(uint256 tokenId, address grantee);

constructor(
string memory _baseURI,
address _gatewayProxy,
Expand Down Expand Up @@ -70,4 +75,25 @@ contract VWBLERC6150ERC2981 is Ownable, ERC6150ParentTransferable, AbstractVWBLT
{
return super.supportsInterface(interfaceId);
}

/**
* @notice Grant view permission to grantee from nft owner
* @param tokenId The identifier of NFT
* @param grantee The Address who grantee of view permission right
*/
function grantViewPermission(uint256 tokenId, address grantee) public returns (uint256) {
require(msg.sender == ownerOf(tokenId), "msg sender is not nft owner");
hasViewRight[tokenId][grantee] = true;
emit ViewRightGranted(tokenId, grantee);
return tokenId;
}

/**
* @notice Check view permission to user
* @param tokenId The Identifier of NFT
* @param user The address of verification target
*/
function checkViewPermission(uint256 tokenId, address user) public view returns (bool) {
return hasViewRight[tokenId][user];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ contract AccessControlCheckerByNFT is AbstractControlChecker, Ownable {
* @param documentId The Identifier of digital content and decryption key
*/
function checkAccessControl(address user, bytes32 documentId) external view returns (bool) {
return false;
Token memory token = documentIdToToken[documentId];
try IVWBL(token.contractAddress).checkViewPermission(token.tokenId, user) returns (bool result) {
} catch {
return false;
}
}

/**
Expand Down
26 changes: 26 additions & 0 deletions contracts/access-condition/ERC721/VWBLERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import "../AbstractVWBLToken.sol";
* @dev NFT which is added Viewable features that only NFT Owner can view digital content
*/
contract VWBLERC721 is Ownable, AbstractVWBLToken, ERC721Enumerable {
// tokenId => grantee => bool
mapping (uint256 => mapping (address => bool)) public hasViewRight;

event ViewRightGranted(uint256 tokenId, address grantee);

constructor(
string memory _baseURI,
address _gatewayProxy,
Expand Down Expand Up @@ -47,4 +52,25 @@ contract VWBLERC721 is Ownable, AbstractVWBLToken, ERC721Enumerable {

return tokenId;
}

/**
* @notice Grant view permission to grantee from nft owner
* @param tokenId The identifier of NFT
* @param grantee The Address who grantee of view permission right
*/
function grantViewPermission(uint256 tokenId, address grantee) public returns (uint256) {
require(msg.sender == ownerOf(tokenId), "msg sender is not nft owner");
hasViewRight[tokenId][grantee] = true;
emit ViewRightGranted(tokenId, grantee);
return tokenId;
}

/**
* @notice Check view permission to user
* @param tokenId The Identifier of NFT
* @param user The address of verification target
*/
function checkViewPermission(uint256 tokenId, address user) public view returns (bool) {
return hasViewRight[tokenId][user];
}
}
26 changes: 26 additions & 0 deletions contracts/access-condition/ERC721/VWBLERC721ERC2981.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ import "../AbstractVWBLToken.sol";
* @dev NFT which is added Viewable features that only NFT Owner can view digital content
*/
contract VWBLERC721ERC2981 is Ownable, AbstractVWBLToken, ERC721Enumerable, ERC2981 {
// tokenId => grantee => bool
mapping (uint256 => mapping (address => bool)) public hasViewRight;

event ViewRightGranted(uint256 tokenId, address grantee);

constructor(
string memory _baseURI,
address _gatewayProxy,
Expand Down Expand Up @@ -68,4 +73,25 @@ contract VWBLERC721ERC2981 is Ownable, AbstractVWBLToken, ERC721Enumerable, ERC2
{
return super.supportsInterface(interfaceId);
}

/**
* @notice Grant view permission to grantee from nft owner
* @param tokenId The identifier of NFT
* @param grantee The Address who grantee of view permission right
*/
function grantViewPermission(uint256 tokenId, address grantee) public returns (uint256) {
require(msg.sender == ownerOf(tokenId), "msg sender is not nft owner");
hasViewRight[tokenId][grantee] = true;
emit ViewRightGranted(tokenId, grantee);
return tokenId;
}

/**
* @notice Check view permission to user
* @param tokenId The Identifier of NFT
* @param user The address of verification target
*/
function checkViewPermission(uint256 tokenId, address user) public view returns (bool) {
return hasViewRight[tokenId][user];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import "../../AbstractVWBLToken.sol";
*/
contract VWBLERC721ERC2981ForMetadata is Ownable, AbstractVWBLToken, ERC721Enumerable, ERC2981 {
mapping(uint256 => string) private _tokenURIs;
// tokenId => grantee => bool
mapping (uint256 => mapping (address => bool)) public hasViewRight;

event ViewRightGranted(uint256 tokenId, address grantee);

constructor(
address _gatewayProxy,
Expand Down Expand Up @@ -71,4 +75,25 @@ contract VWBLERC721ERC2981ForMetadata is Ownable, AbstractVWBLToken, ERC721Enume
{
return super.supportsInterface(interfaceId);
}

/**
* @notice Grant view permission to grantee from nft owner
* @param tokenId The identifier of NFT
* @param grantee The Address who grantee of view permission right
*/
function grantViewPermission(uint256 tokenId, address grantee) public returns (uint256) {
require(msg.sender == ownerOf(tokenId), "msg sender is not nft owner");
hasViewRight[tokenId][grantee] = true;
emit ViewRightGranted(tokenId, grantee);
return tokenId;
}

/**
* @notice Check view permission to user
* @param tokenId The Identifier of NFT
* @param user The address of verification target
*/
function checkViewPermission(uint256 tokenId, address user) public view returns (bool) {
return hasViewRight[tokenId][user];
}
}
14 changes: 14 additions & 0 deletions contracts/access-condition/IVWBL.sol
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,18 @@ interface IVWBL {
* @param minter The minter of NFT
*/
function getTokenByMinter(address minter) external view returns (uint256[] memory);

/**
* @notice Grant view permission to grantee from nft owner
* @param tokenId The identifier of NFT
* @param grantee The Address who grantee of view permission right
*/
function grantViewPermission(uint256 tokenId, address grantee) external returns (uint256);

/**
* @notice Check view permission to user
* @param tokenId The Identifier of NFT
* @param user The address of verification target
*/
function checkViewPermission(uint256 tokenId, address user) external view returns (bool);
}

0 comments on commit 6010c31

Please sign in to comment.