-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddressManager.sol
64 lines (57 loc) · 2.14 KB
/
AddressManager.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// SPDX-License-Identifier: MIT
pragma solidity 0.8.15;
import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
/**
* @custom:legacy
* @title AddressManager
* @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.
*/
contract AddressManager is Ownable {
/**
* @notice Mapping of the hashes of string names to addresses.
*/
mapping(bytes32 => address) private addresses;
/**
* @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.
*/
event AddressSet(string indexed name, address newAddress, address oldAddress);
/**
* @notice Changes the address associated with a particular name.
*
* @param _name String name to associate an address with.
* @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);
}
/**
* @notice Retrieves the address associated with a given name.
*
* @param _name Name to retrieve an address for.
*
* @return Address associated with the given name.
*/
function getAddress(string memory _name) external view returns (address) {
return addresses[_getNameHash(_name)];
}
/**
* @notice Computes the hash of a name.
*
* @param _name Name to compute a hash for.
*
* @return Hash of the given name.
*/
function _getNameHash(string memory _name) internal pure returns (bytes32) {
return keccak256(abi.encodePacked(_name));
}
}