forked from OpenZeppelin/openzeppelin-contracts
-
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.
add simple catch-all implementation for the metadata URI interface
- Loading branch information
Showing
2 changed files
with
49 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
pragma solidity ^0.5.9; | ||
|
||
import "./ERC1155.sol"; | ||
import "./IERC1155MetadataURI.sol"; | ||
import "../../introspection/ERC165.sol"; | ||
|
||
contract ERC1155MetadataURI_CatchAll is ERC165, ERC1155, IERC1155MetadataURI { | ||
// Catch-all URI with placeholders, e.g. https://example.com/{locale}/{id}.json | ||
string private _uri; | ||
|
||
/* | ||
* bytes4(keccak256('uri(uint256)')) == 0x0e89341c | ||
*/ | ||
bytes4 private constant _INTERFACE_ID_ERC1155_METADATA_URI = 0x0e89341c; | ||
|
||
/** | ||
* @dev Constructor function | ||
*/ | ||
constructor (string memory uri) public { | ||
_uri = uri; | ||
emit URI(_uri, 0); | ||
|
||
// register the supported interfaces to conform to ERC1155 via ERC165 | ||
_registerInterface(_INTERFACE_ID_ERC1155_METADATA_URI); | ||
} | ||
|
||
/** | ||
* @notice A distinct Uniform Resource Identifier (URI) for a given token. | ||
* @dev URIs are defined in RFC 3986. | ||
* The URI MUST point to a JSON file that conforms to the "ERC-1155 Metadata URI JSON Schema". | ||
* param id uint256 ID of the token to query (ignored in this particular implementation, | ||
* as an {id} parameter in the string is expected) | ||
* @return URI string | ||
*/ | ||
function uri(uint256 /*id*/) external view returns (string memory) { | ||
return _uri; | ||
} | ||
} |
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,11 @@ | ||
pragma solidity ^0.5.0; | ||
|
||
import "./IERC1155.sol"; | ||
|
||
/** | ||
* @title ERC-1155 Multi Token Standard basic interface, optional metadata URI extension | ||
* @dev See https://eips.ethereum.org/EIPS/eip-1155 | ||
*/ | ||
contract IERC1155MetadataURI is IERC1155 { | ||
function uri(uint256 id) external view returns (string memory); | ||
} |