2021-03-16 13:53:22 +01:00
|
|
|
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 {
|
2023-03-21 14:44:54 +01:00
|
|
|
// Implements ERC173
|
2021-03-16 13:53:22 +01:00
|
|
|
address public owner;
|
|
|
|
|
2023-03-21 14:44:54 +01:00
|
|
|
// Implements RegistryClient
|
2021-03-16 13:53:22 +01:00
|
|
|
bytes32[] public identifiers;
|
|
|
|
mapping (bytes32 => address) entries; // contractidentifier -> address
|
2021-11-14 05:23:44 +01:00
|
|
|
mapping (bytes32 => bytes32[]) entryBindings; // contractidentifier -> chainidentifier
|
2021-03-16 13:53:22 +01:00
|
|
|
|
2023-03-21 14:44:54 +01:00
|
|
|
// Implements ERC173
|
|
|
|
event OwnershipTransferred(address indexed _previousOwner, address indexed _newOwner);
|
|
|
|
|
2023-03-17 23:10:56 +01:00
|
|
|
constructor(bytes32[] memory _identifiers) {
|
2021-03-16 13:53:22 +01:00
|
|
|
owner = msg.sender;
|
|
|
|
for (uint i = 0; i < _identifiers.length; i++) {
|
|
|
|
identifiers.push(_identifiers[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-21 14:44:54 +01:00
|
|
|
// Implements Registry
|
2021-11-14 05:23:44 +01:00
|
|
|
function set(bytes32 _identifier, address _address) public returns (bool) {
|
2021-03-16 13:53:22 +01:00
|
|
|
require(msg.sender == owner);
|
|
|
|
require(entries[_identifier] == address(0));
|
2021-11-14 05:23:44 +01:00
|
|
|
require(_address != address(0));
|
|
|
|
|
2021-03-16 13:53:22 +01:00
|
|
|
bool found = false;
|
|
|
|
for (uint i = 0; i < identifiers.length; i++) {
|
|
|
|
if (identifiers[i] == _identifier) {
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
require(found);
|
|
|
|
|
|
|
|
entries[_identifier] = _address;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2023-03-21 14:44:54 +01:00
|
|
|
// Implements Registry
|
2021-11-14 05:23:44 +01:00
|
|
|
function bind(bytes32 _identifier, bytes32 _reference) public returns (bool) {
|
|
|
|
require(msg.sender == owner);
|
|
|
|
require(entries[_identifier] != address(0));
|
|
|
|
|
|
|
|
entryBindings[_identifier].push(_reference);
|
2023-03-17 23:10:56 +01:00
|
|
|
return true;
|
2021-11-14 05:23:44 +01:00
|
|
|
}
|
|
|
|
|
2021-04-30 12:01:08 +02:00
|
|
|
// Implements EIP 173
|
|
|
|
function transferOwnership(address _newOwner) public returns (bool) {
|
2023-03-21 14:44:54 +01:00
|
|
|
address _oldOwner;
|
|
|
|
|
2021-04-30 12:01:08 +02:00
|
|
|
require(msg.sender == owner);
|
2023-03-21 14:44:54 +01:00
|
|
|
_oldOwner = owner;
|
2021-04-30 12:01:08 +02:00
|
|
|
owner = _newOwner;
|
2023-03-21 14:44:54 +01:00
|
|
|
emit OwnershipTransferred(_oldOwner, _newOwner);
|
2021-04-30 12:01:08 +02:00
|
|
|
return true;
|
|
|
|
}
|
2021-03-16 13:53:22 +01:00
|
|
|
|
2023-03-21 14:44:54 +01:00
|
|
|
// Implements RegistryClient
|
2021-03-16 13:53:22 +01:00
|
|
|
function addressOf(bytes32 _identifier) public view returns (address) {
|
|
|
|
return entries[_identifier];
|
|
|
|
}
|
|
|
|
|
2023-03-21 14:44:54 +01:00
|
|
|
// Implements ERC165
|
2021-04-30 13:11:22 +02:00
|
|
|
function supportsInterface(bytes4 _sum) public pure returns (bool) {
|
2023-03-21 14:44:54 +01:00
|
|
|
if (_sum == 0xd719b0cc) { // Registry
|
2021-11-14 05:38:42 +01:00
|
|
|
return true;
|
|
|
|
}
|
2023-03-21 14:44:54 +01:00
|
|
|
if (_sum == 0x93c68796) { // RegistryClient
|
2021-04-30 13:11:22 +02:00
|
|
|
return true;
|
|
|
|
}
|
2023-03-21 14:44:54 +01:00
|
|
|
if (_sum == 0x01ffc9a7) { // ERC165
|
2021-04-30 13:11:22 +02:00
|
|
|
return true;
|
|
|
|
}
|
2023-03-21 14:44:54 +01:00
|
|
|
if (_sum == 0x9493f8b2) { // ERC173
|
2021-04-30 13:11:22 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2021-03-16 13:53:22 +01:00
|
|
|
}
|