github.com/ethereum-optimism/optimism@v1.7.2/packages/contracts-bedrock/src/legacy/AddressManager.sol (about) 1 // SPDX-License-Identifier: MIT 2 pragma solidity 0.8.15; 3 4 import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol"; 5 6 /// @custom:legacy 7 /// @title AddressManager 8 /// @notice AddressManager is a legacy contract that was used in the old version of the Optimism 9 /// system to manage a registry of string names to addresses. We now use a more standard 10 /// proxy system instead, but this contract is still necessary for backwards compatibility 11 /// with several older contracts. 12 contract AddressManager is Ownable { 13 /// @notice Mapping of the hashes of string names to addresses. 14 mapping(bytes32 => address) private addresses; 15 16 /// @notice Emitted when an address is modified in the registry. 17 /// @param name String name being set in the registry. 18 /// @param newAddress Address set for the given name. 19 /// @param oldAddress Address that was previously set for the given name. 20 event AddressSet(string indexed name, address newAddress, address oldAddress); 21 22 /// @notice Changes the address associated with a particular name. 23 /// @param _name String name to associate an address with. 24 /// @param _address Address to associate with the name. 25 function setAddress(string memory _name, address _address) external onlyOwner { 26 bytes32 nameHash = _getNameHash(_name); 27 address oldAddress = addresses[nameHash]; 28 addresses[nameHash] = _address; 29 30 emit AddressSet(_name, _address, oldAddress); 31 } 32 33 /// @notice Retrieves the address associated with a given name. 34 /// @param _name Name to retrieve an address for. 35 /// @return Address associated with the given name. 36 function getAddress(string memory _name) external view returns (address) { 37 return addresses[_getNameHash(_name)]; 38 } 39 40 /// @notice Computes the hash of a name. 41 /// @param _name Name to compute a hash for. 42 /// @return Hash of the given name. 43 function _getNameHash(string memory _name) internal pure returns (bytes32) { 44 return keccak256(abi.encodePacked(_name)); 45 } 46 }