mirror of
git://holbrook.no/eth-contract-registry
synced 2024-12-22 20:27:32 +01:00
88 lines
2.2 KiB
Solidity
88 lines
2.2 KiB
Solidity
pragma solidity >0.6.11;
|
|
|
|
// Author: Louis Holbrook <dev@holbrook.no> 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
// File-version: 2
|
|
// Description: Top-level smart contract registry for the CIC network
|
|
|
|
|
|
contract CICRegistry {
|
|
// Implements ERC173
|
|
address public owner;
|
|
|
|
// Implements RegistryClient
|
|
bytes32[] public identifiers;
|
|
mapping (bytes32 => address) entries; // contractidentifier -> address
|
|
mapping (bytes32 => bytes32[]) entryBindings; // contractidentifier -> chainidentifier
|
|
|
|
// Implements ERC173
|
|
event OwnershipTransferred(address indexed _previousOwner, address indexed _newOwner);
|
|
|
|
constructor(bytes32[] memory _identifiers) {
|
|
owner = msg.sender;
|
|
for (uint i = 0; i < _identifiers.length; i++) {
|
|
identifiers.push(_identifiers[i]);
|
|
}
|
|
}
|
|
|
|
// Implements Registry
|
|
function set(bytes32 _identifier, address _address) public returns (bool) {
|
|
require(msg.sender == owner);
|
|
require(entries[_identifier] == address(0));
|
|
require(_address != address(0));
|
|
|
|
bool found = false;
|
|
for (uint i = 0; i < identifiers.length; i++) {
|
|
if (identifiers[i] == _identifier) {
|
|
found = true;
|
|
}
|
|
}
|
|
require(found);
|
|
|
|
entries[_identifier] = _address;
|
|
return true;
|
|
}
|
|
|
|
// Implements Registry
|
|
function bind(bytes32 _identifier, bytes32 _reference) public returns (bool) {
|
|
require(msg.sender == owner);
|
|
require(entries[_identifier] != address(0));
|
|
|
|
entryBindings[_identifier].push(_reference);
|
|
return true;
|
|
}
|
|
|
|
// Implements EIP 173
|
|
function transferOwnership(address _newOwner) public returns (bool) {
|
|
address _oldOwner;
|
|
|
|
require(msg.sender == owner);
|
|
_oldOwner = owner;
|
|
owner = _newOwner;
|
|
emit OwnershipTransferred(_oldOwner, _newOwner);
|
|
return true;
|
|
}
|
|
|
|
// Implements RegistryClient
|
|
function addressOf(bytes32 _identifier) public view returns (address) {
|
|
return entries[_identifier];
|
|
}
|
|
|
|
// Implements ERC165
|
|
function supportsInterface(bytes4 _sum) public pure returns (bool) {
|
|
if (_sum == 0xd719b0cc) { // Registry
|
|
return true;
|
|
}
|
|
if (_sum == 0x93c68796) { // RegistryClient
|
|
return true;
|
|
}
|
|
if (_sum == 0x01ffc9a7) { // ERC165
|
|
return true;
|
|
}
|
|
if (_sum == 0x9493f8b2) { // ERC173
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
}
|