AddressManager.sol 2.14 KB
Newer Older
1
// SPDX-License-Identifier: MIT
2
pragma solidity 0.8.15;
3 4 5 6

import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";

/**
7
 * @custom:legacy
8
 * @title AddressManager
9 10 11 12
 * @notice AddressManager is a legacy contract that was used in the old version of the Optimism
 *         system to manage a registry of string names to addresses. We now use a more standard
 *         proxy system instead, but this contract is still necessary for backwards compatibility
 *         with several older contracts.
13
 */
14
contract AddressManager is Ownable {
15 16 17 18 19
    /**
     * @notice Mapping of the hashes of string names to addresses.
     */
    mapping(bytes32 => address) private addresses;

20 21 22 23 24 25 26
    /**
     * @notice Emitted when an address is modified in the registry.
     *
     * @param name       String name being set in the registry.
     * @param newAddress Address set for the given name.
     * @param oldAddress Address that was previously set for the given name.
     */
27
    event AddressSet(string indexed name, address newAddress, address oldAddress);
28 29

    /**
30 31 32
     * @notice Changes the address associated with a particular name.
     *
     * @param _name    String name to associate an address with.
33 34 35 36 37 38 39 40 41 42 43
     * @param _address Address to associate with the name.
     */
    function setAddress(string memory _name, address _address) external onlyOwner {
        bytes32 nameHash = _getNameHash(_name);
        address oldAddress = addresses[nameHash];
        addresses[nameHash] = _address;

        emit AddressSet(_name, _address, oldAddress);
    }

    /**
44 45
     * @notice Retrieves the address associated with a given name.
     *
46
     * @param _name Name to retrieve an address for.
47
     *
48 49 50 51 52 53 54
     * @return Address associated with the given name.
     */
    function getAddress(string memory _name) external view returns (address) {
        return addresses[_getNameHash(_name)];
    }

    /**
55 56
     * @notice Computes the hash of a name.
     *
57
     * @param _name Name to compute a hash for.
58
     *
59 60 61 62 63 64
     * @return Hash of the given name.
     */
    function _getNameHash(string memory _name) internal pure returns (bytes32) {
        return keccak256(abi.encodePacked(_name));
    }
}