在某些应用中,可能需要限制授权。受限授权可以防止用户未审计他们授权的合约时造成的损失。没有提供标准 API 来管理作用域,因为这是特定于实现的。某些实现可以选择提供固定数量的作用域,或将特定的一组作用域分配给某些类型。其他实现可能会向其用户开放作用域配置,并提供创建作用域和将 ID 分配给作用域的方法。
规范
pragmasolidity^0.5.2;/**
Note: The ERC-165 identifier for this interface is 0x30168307.
*/interfaceScopedApproval{/**
@dev MUST emit when approval changes for scope.
*/eventApprovalForScope(addressindexed_owner,addressindexed_operator,bytes32indexed_scope,bool_approved);/**
@dev MUST emit when the token IDs are added to the scope.
By default, IDs are in no scope.
The range is inclusive: _idStart, _idEnd, and all IDs in between have been added to the scope.
_idStart must be lower than or equal to _idEnd.
*/eventIdsAddedToScope(uint256indexed_idStart,uint256indexed_idEnd,bytes32indexed_scope);/**
@dev MUST emit when the token IDs are removed from the scope.
The range is inclusive: _idStart, _idEnd, and all IDs in between have been removed from the scope.
_idStart must be lower than or equal to _idEnd.
*/eventIdsRemovedFromScope(uint256indexed_idStart,uint256indexed_idEnd,bytes32indexed_scope);/** @dev MUST emit when a scope URI is set or changes.
URIs are defined in RFC 3986.
The URI MUST point a JSON file that conforms to the "Scope Metadata JSON Schema".
*/eventScopeURI(string_value,bytes32indexed_scope);/**
@notice Returns the number of scopes that contain _id.
@param _id The token ID
@return The number of scopes containing the ID
*/functionscopeCountForId(uint256_id)publicviewreturns(uint32);/**
@notice Returns a scope that contains _id.
@param _id The token ID
@param _scopeIndex The scope index to query (valid values are 0 to scopeCountForId(_id)-1)
@return The Nth scope containing the ID
*/functionscopeForId(uint256_id,uint32_scopeIndex)publicviewreturns(bytes32);/**
@notice Returns a URI that can be queried to get scope metadata. This URI should return a JSON document containing, at least the scope name and description. Although supplying a URI for every scope is recommended, returning an empty string "" is accepted for scopes without a URI.
@param _scope The queried scope
@return The URI describing this scope.
*/functionscopeUri(bytes32_scope)publicviewreturns(stringmemory);/**
@notice Enable or disable approval for a third party ("operator") to manage the caller's tokens in the specified scope.
@dev MUST emit the ApprovalForScope event on success.
@param _operator Address to add to the set of authorized operators
@param _scope Approval scope (can be identified by calling scopeForId)
@param _approved True if the operator is approved, false to revoke approval
*/functionsetApprovalForScope(address_operator,bytes32_scope,bool_approved)external;/**
@notice Queries the approval status of an operator for a given owner, within the specified scope.
@param _owner The owner of the Tokens
@param _operator Address of authorized operator
@param _scope Scope to test for approval (can be identified by calling scopeForId)
@return True if the operator is approved, false otherwise
*/functionisApprovedForScope(address_owner,address_operator,bytes32_scope)publicviewreturns(bool);}
作用域元数据 JSON 模式
此模式允许本地化。{id} 和 {locale} 应由客户端替换为适当的值。
{"title":"Scope Metadata","type":"object","required":["name"],"properties":{"name":{"type":"string","description":"Identifies the scope in a human-readable way.",},"description":{"type":"string","description":"Describes the scope to allow users to make informed approval decisions.",},"localization":{"type":"object","required":["uri","default","locales"],"properties":{"uri":{"type":"string","description":"The URI pattern to fetch localized data from. This URI should contain the substring `{locale}` which will be replaced with the appropriate locale value before sending the request."},"default":{"type":"string","description":"The locale of the default data within the base JSON"},"locales":{"type":"array","description":"The list of locales for which data is available. These locales should conform to those defined in the Unicode Common Locale Data Repository (http://cldr.unicode.org/)."}}}}}