2021-01-10 20:40:29 +01:00
|
|
|
pragma solidity >0.6.11;
|
2020-11-13 18:33:39 +01:00
|
|
|
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
|
|
|
contract CustodialAccountIndex {
|
|
|
|
|
2021-04-30 12:46:53 +02:00
|
|
|
address[] entries;
|
|
|
|
mapping(address => uint256) entryIndex;
|
|
|
|
uint256 count;
|
2020-11-13 18:33:39 +01:00
|
|
|
mapping(address => bool) writers;
|
2021-04-30 11:36:56 +02:00
|
|
|
address public owner;
|
|
|
|
address newOwner;
|
2020-11-13 18:33:39 +01:00
|
|
|
|
2021-04-30 17:25:47 +02:00
|
|
|
event AddressAdded(address indexed addedAccount, uint256 indexed accountIndex); // AccountsIndex
|
2021-04-30 11:36:56 +02:00
|
|
|
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner); // EIP173
|
2020-11-13 18:33:39 +01:00
|
|
|
|
2020-12-01 23:51:17 +01:00
|
|
|
constructor() public {
|
2020-11-13 18:33:39 +01:00
|
|
|
owner = msg.sender;
|
2021-04-30 12:46:53 +02:00
|
|
|
entries.push(address(0));
|
2020-11-13 23:19:48 +01:00
|
|
|
count = 1;
|
2020-11-13 18:33:39 +01:00
|
|
|
}
|
|
|
|
|
2020-12-07 16:41:48 +01:00
|
|
|
function addWriter(address _writer) public returns (bool) {
|
2020-11-13 18:33:39 +01:00
|
|
|
require(owner == msg.sender);
|
|
|
|
writers[_writer] = true;
|
2020-12-07 16:41:48 +01:00
|
|
|
return true;
|
2020-11-13 18:33:39 +01:00
|
|
|
}
|
|
|
|
|
2020-12-07 16:41:48 +01:00
|
|
|
function deleteWriter(address _writer) public returns (bool) {
|
2020-11-13 18:33:39 +01:00
|
|
|
require(owner == msg.sender);
|
|
|
|
delete writers[_writer];
|
2020-12-07 16:41:48 +01:00
|
|
|
return true;
|
2020-11-13 18:33:39 +01:00
|
|
|
}
|
|
|
|
|
2021-04-30 12:46:53 +02:00
|
|
|
// Implements AccountsIndex
|
2020-12-07 16:41:48 +01:00
|
|
|
function add(address _account) external returns (bool) {
|
2020-11-13 18:33:39 +01:00
|
|
|
require(writers[msg.sender]);
|
2021-04-30 11:36:56 +02:00
|
|
|
require(entryIndex[_account] == 0);
|
2021-04-30 12:46:53 +02:00
|
|
|
entryIndex[_account] = entries.length;
|
|
|
|
entries.push(_account);
|
2021-04-30 17:25:47 +02:00
|
|
|
emit AddressAdded(_account, entries.length-1);
|
2020-12-07 16:41:48 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-04-30 12:46:53 +02:00
|
|
|
// Implements AccountsIndex
|
2020-12-07 16:41:48 +01:00
|
|
|
function have(address _account) external view returns (bool) {
|
2021-04-30 11:36:56 +02:00
|
|
|
return entryIndex[_account] > 0;
|
|
|
|
}
|
|
|
|
|
2021-04-30 12:46:53 +02:00
|
|
|
// Implements AccountsIndex
|
|
|
|
function entry(uint256 _idx) public returns (address) {
|
|
|
|
return entries[_idx+1];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Implements AccountsIndex
|
2021-04-30 11:36:56 +02:00
|
|
|
function entryCount() public returns (uint256) {
|
2021-04-30 12:46:53 +02:00
|
|
|
return count - 1;
|
2021-04-30 11:36:56 +02:00
|
|
|
}
|
|
|
|
|
2021-04-30 12:46:53 +02:00
|
|
|
// Implements EIP173
|
2021-04-30 11:36:56 +02:00
|
|
|
function transferOwnership(address _newOwner) public returns (bool) {
|
|
|
|
require(msg.sender == owner);
|
|
|
|
newOwner = _newOwner;
|
|
|
|
}
|
|
|
|
|
2021-04-30 12:46:53 +02:00
|
|
|
// Implements OwnedAccepter
|
2021-04-30 11:36:56 +02:00
|
|
|
function acceptOwnership() public returns (bool) {
|
|
|
|
address oldOwner;
|
|
|
|
|
|
|
|
require(msg.sender == newOwner);
|
|
|
|
oldOwner = owner;
|
|
|
|
owner = newOwner;
|
|
|
|
newOwner = address(0);
|
|
|
|
emit OwnershipTransferred(oldOwner, owner);
|
|
|
|
}
|
|
|
|
|
2021-04-30 12:46:53 +02:00
|
|
|
// Implements EIP165
|
2021-04-30 11:36:56 +02:00
|
|
|
function supportsInterface(bytes4 _sum) public pure returns (bool) {
|
|
|
|
if (_sum == 0xcbdb05c7) { // AccountsIndex
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (_sum == 0x01ffc9a7) { // EIP165
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (_sum == 0x9493f8b2) { // EIP173
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
if (_sum == 0x37a47be4) { // OwnedAccepter
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
2020-11-13 18:33:39 +01:00
|
|
|
}
|
|
|
|
}
|