github.com/ethereum-optimism/optimism@v1.7.2/packages/contracts-bedrock/src/EAS/SchemaRegistry.sol (about)

     1  // SPDX-License-Identifier: MIT
     2  pragma solidity 0.8.19;
     3  
     4  import { ISemver } from "src/universal/ISemver.sol";
     5  import { ISchemaResolver } from "src/EAS/resolver/ISchemaResolver.sol";
     6  import { EMPTY_UID, MAX_GAP } from "src/EAS/Common.sol";
     7  import { ISchemaRegistry, SchemaRecord } from "src/EAS/ISchemaRegistry.sol";
     8  
     9  /// @custom:proxied
    10  /// @custom:predeploy 0x4200000000000000000000000000000000000020
    11  /// @title SchemaRegistry
    12  /// @notice The global attestation schemas for the Ethereum Attestation Service protocol.
    13  contract SchemaRegistry is ISchemaRegistry, ISemver {
    14      error AlreadyExists();
    15  
    16      // The global mapping between schema records and their IDs.
    17      mapping(bytes32 uid => SchemaRecord schemaRecord) private _registry;
    18  
    19      // Upgrade forward-compatibility storage gap
    20      uint256[MAX_GAP - 1] private __gap;
    21  
    22      /// @notice Semantic version.
    23      /// @custom:semver 1.3.0
    24      string public constant version = "1.3.0";
    25  
    26      /// @inheritdoc ISchemaRegistry
    27      function register(string calldata schema, ISchemaResolver resolver, bool revocable) external returns (bytes32) {
    28          SchemaRecord memory schemaRecord =
    29              SchemaRecord({ uid: EMPTY_UID, schema: schema, resolver: resolver, revocable: revocable });
    30  
    31          bytes32 uid = _getUID(schemaRecord);
    32          if (_registry[uid].uid != EMPTY_UID) {
    33              revert AlreadyExists();
    34          }
    35  
    36          schemaRecord.uid = uid;
    37          _registry[uid] = schemaRecord;
    38  
    39          emit Registered(uid, msg.sender, schemaRecord);
    40  
    41          return uid;
    42      }
    43  
    44      /// @inheritdoc ISchemaRegistry
    45      function getSchema(bytes32 uid) external view returns (SchemaRecord memory) {
    46          return _registry[uid];
    47      }
    48  
    49      /// @dev Calculates a UID for a given schema.
    50      /// @param schemaRecord The input schema.
    51      /// @return schema UID.
    52      function _getUID(SchemaRecord memory schemaRecord) private pure returns (bytes32) {
    53          return keccak256(abi.encodePacked(schemaRecord.schema, schemaRecord.resolver, schemaRecord.revocable));
    54      }
    55  }