-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #213 from nevermined-io/feature/nft_metadata
Adding support to NFTs metadata (ERC-721 & 1155)
- Loading branch information
Showing
11 changed files
with
360 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
pragma solidity ^0.8.0; | ||
// Copyright 2020 Keyko GmbH. | ||
// SPDX-License-Identifier: (Apache-2.0 AND CC-BY-4.0) | ||
// Code is Apache-2.0 and docs are CC-BY-4.0 | ||
|
||
import '@openzeppelin/contracts-upgradeable/interfaces/IERC2981Upgradeable.sol'; | ||
import '@openzeppelin/contracts-upgradeable/access/AccessControlUpgradeable.sol'; | ||
import '@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol'; | ||
import '@openzeppelin/contracts-upgradeable/token/ERC1155/ERC1155Upgradeable.sol'; | ||
|
||
/** | ||
* | ||
* @dev Implementation of the Royalties EIP-2981 base contract | ||
* See https://eips.ethereum.org/EIPS/eip-2981 | ||
*/ | ||
abstract contract NFTBase is IERC2981Upgradeable, OwnableUpgradeable, AccessControlUpgradeable { | ||
|
||
// Mapping from account to proxy approvals | ||
mapping (address => bool) internal _proxyApprovals; | ||
|
||
bytes32 public constant MINTER_ROLE = keccak256('MINTER_ROLE'); | ||
|
||
struct RoyaltyInfo { | ||
address receiver; | ||
uint256 royaltyAmount; | ||
} | ||
|
||
struct NFTMetadata { | ||
string nftURI; | ||
} | ||
|
||
// Mapping of Royalties per tokenId (DID) | ||
mapping(uint256 => RoyaltyInfo) internal _royalties; | ||
|
||
mapping(uint256 => NFTMetadata) internal _metadata; | ||
|
||
/** | ||
* Event for recording proxy approvals. | ||
*/ | ||
event ProxyApproval(address sender, address operator, bool approved); | ||
|
||
|
||
function setProxyApproval( | ||
address operator, | ||
bool approved | ||
) | ||
public | ||
onlyOwner | ||
virtual | ||
{ | ||
_proxyApprovals[operator] = approved; | ||
emit ProxyApproval(_msgSender(), operator, approved); | ||
} | ||
|
||
function _setNFTMetadata( | ||
uint256 tokenId, | ||
string memory tokenURI | ||
) | ||
internal | ||
{ | ||
_metadata[tokenId] = NFTMetadata(tokenURI); | ||
} | ||
|
||
function _setTokenRoyalty( | ||
uint256 tokenId, | ||
address receiver, | ||
uint256 royaltyAmount | ||
) | ||
internal | ||
{ | ||
require(royaltyAmount <= 100, 'ERC2981Royalties: Too high'); | ||
_royalties[tokenId] = RoyaltyInfo(receiver, royaltyAmount); | ||
} | ||
|
||
/** | ||
* @inheritdoc IERC2981Upgradeable | ||
*/ | ||
function royaltyInfo( | ||
uint256 tokenId, | ||
uint256 value | ||
) | ||
external | ||
view | ||
override | ||
returns (address receiver, uint256 royaltyAmount) | ||
{ | ||
RoyaltyInfo memory royalties = _royalties[tokenId]; | ||
receiver = royalties.receiver; | ||
royaltyAmount = (value * royalties.royaltyAmount) / 100; | ||
} | ||
|
||
} |
Oops, something went wrong.