Registry.sol (2039B)
1 pragma solidity >=0.8.0; 2 3 // Author: Louis Holbrook <dev@holbrook.no> 0826EDA1702D1E87C6E2875121D2E7BB88C2A746 4 // SPDX-License-Identifier: AGPL-3.0-or-later 5 // File-version: 4 6 // Description: Keyed smart contract registry 7 8 9 contract ContractRegistry { 10 mapping (bytes32 => address) entries; 11 12 // Implements ERC173 13 address public owner; 14 15 // Implements Registry 16 bytes32[] public identifier; 17 18 // Implements ERC173 19 event OwnershipTransferred(address indexed _previousOwner, address indexed _newOwner); 20 21 // Implements Registry 22 event AddressKey(bytes32 indexed _key, address _address); 23 24 constructor(bytes32[] memory _identifiers) { 25 owner = msg.sender; 26 for (uint i = 0; i < _identifiers.length; i++) { 27 identifier.push(_identifiers[i]); 28 } 29 } 30 31 // Assign address to identifier 32 function set(bytes32 _identifier, address _address) public returns (bool) { 33 require(msg.sender == owner); 34 require(entries[_identifier] == address(0)); 35 require(_address != address(0)); 36 37 bool found = false; 38 for (uint i = 0; i < identifier.length; i++) { 39 if (identifier[i] == _identifier) { 40 found = true; 41 } 42 } 43 require(found); 44 45 entries[_identifier] = _address; 46 47 emit AddressKey(_identifier, _address); 48 49 return true; 50 } 51 52 // Implements EIP 173 53 function transferOwnership(address _newOwner) public returns (bool) { 54 address _oldOwner; 55 56 require(msg.sender == owner, 'ERR_AXX'); 57 _oldOwner = owner; 58 owner = _newOwner; 59 emit OwnershipTransferred(_oldOwner, _newOwner); 60 return true; 61 } 62 63 // Implements Registry 64 function addressOf(bytes32 _identifier) public view returns (address) { 65 return entries[_identifier]; 66 } 67 68 // Implements Registry 69 function identifierCount() public view returns(uint256) { 70 return identifier.length; 71 } 72 73 // Implements ERC165 74 function supportsInterface(bytes4 _sum) public pure returns (bool) { 75 if (_sum == 0xeffbf671) { // Registry 76 return true; 77 } 78 if (_sum == 0x01ffc9a7) { // ERC165 79 return true; 80 } 81 if (_sum == 0x9493f8b2) { // ERC173 82 return true; 83 } 84 return false; 85 } 86 }