Skip to content

Commit 4e61f7d

Browse files
committed
ERC1155: Add metadata related functions
1 parent 26d84aa commit 4e61f7d

File tree

1 file changed

+42
-8
lines changed

1 file changed

+42
-8
lines changed

erc1155/contracts/erc1155_Metadata.vy

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,30 +64,44 @@ ApprovalForAll: event({
6464
_approved: bool
6565
})
6666

67+
# @dev MUST emit when the URI is updated for a token ID.
68+
# URIs are defined in RFC 3986.
69+
# The URI MUST point to a JSON file that conforms to the "ERC-1155 Metadata URI JSON Schema".
70+
# event URI(string _value, uint256 indexed _id);
71+
URI: event({
72+
# https://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers
73+
_value: string[MAX_URI_SIZE],
74+
_id: indexed(uint256)
75+
})
6776

6877

69-
supportedInterfaces: map(bytes32, bool)
78+
# TODO: decide which batch size to use
79+
BATCH_SIZE: constant(uint256) = 5
80+
MAX_URI_SIZE: constant(uint256) = 1024
7081

7182
# https://eips.ethereum.org/EIPS/eip-165
72-
ERC165_INTERFACE_ID: constant(bytes32) = 0x0000000000000000000000000000000000000000000000000000000001ffc9a7
73-
ERC1155_INTERFACE_ID: constant(bytes32) = 0x00000000000000000000000000000000000000000000000000000000d9b67a26
83+
INTERFACE_ID_ERC165: constant(bytes32) = 0x0000000000000000000000000000000000000000000000000000000001ffc9a7
84+
INTERFACE_ID_ERC1155: constant(bytes32) = 0x00000000000000000000000000000000000000000000000000000000d9b67a26
85+
INTERFACE_ID_ERC1155_METADATA: constant(bytes32) = 0x000000000000000000000000000000000000000000000000000000000e89341c
86+
87+
supportedInterfaces: map(bytes32, bool)
7488

7589
tokensIdCount: uint256
7690

7791
_balanceOf: map(address, map(uint256, uint256))
7892

79-
operators: map(address, map(address, bool))
93+
_uri: map(uint256, string[MAX_URI_SIZE])
8094

81-
# TODO: decide which batch size to use
82-
BATCH_SIZE: constant(uint256) = 5
95+
operators: map(address, map(address, bool))
8396

8497

8598

8699
@public
87100
def __init__():
88101
self.tokensIdCount = 0
89-
self.supportedInterfaces[ERC165_INTERFACE_ID] = True
90-
self.supportedInterfaces[ERC1155_INTERFACE_ID] = True
102+
self.supportedInterfaces[INTERFACE_ID_ERC165] = True
103+
self.supportedInterfaces[INTERFACE_ID_ERC1155] = True
104+
self.supportedInterfaces[INTERFACE_ID_ERC1155_METADATA] = True
91105

92106

93107
@public
@@ -181,6 +195,26 @@ def balanceOf(
181195
return self._balanceOf[_owner][_id]
182196

183197

198+
# NOTE: This is not part of the standard
199+
# TODO: Right now everyone can set/change an uri
200+
# https://www.ietf.org/rfc/rfc3986.txt
201+
@public
202+
def setUri(_id: uint256, _newUri: string[MAX_URI_SIZE]):
203+
self._uri[_id] = _newUri
204+
log.URI(_newUri, _id)
205+
206+
207+
# @notice A distinct Uniform Resource Identifier (URI) for a given token.
208+
# @dev URIs are defined in RFC 3986. (https://www.ietf.org/rfc/rfc3986.txt)
209+
# The URI MUST point to a JSON file that conforms to the "ERC-1155 Metadata URI JSON Schema".
210+
# @return URI string
211+
# function uri(uint256 _id) external view returns (string memory);
212+
@public
213+
@constant
214+
def uri(_id: uint256) -> string[MAX_URI_SIZE]:
215+
return self._uri[_id]
216+
217+
184218
# @notice Get the balance of multiple account/token pairs
185219
# @param _owners The addresses of the token holders
186220
# @param _ids ID of the tokens

0 commit comments

Comments
 (0)