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 {
|
|
|
|
|
|
|
|
address[] public accounts;
|
|
|
|
mapping(address => uint256) public accountsIndex;
|
|
|
|
uint256 public count;
|
|
|
|
mapping(address => bool) writers;
|
|
|
|
address owner;
|
|
|
|
|
|
|
|
event AccountAdded(address indexed addedAccount, uint256 indexed accountIndex);
|
|
|
|
|
2020-12-01 23:51:17 +01:00
|
|
|
constructor() public {
|
2020-11-13 18:33:39 +01:00
|
|
|
owner = msg.sender;
|
2020-11-13 23:19:48 +01:00
|
|
|
accounts.push(address(0));
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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]);
|
2020-11-16 19:19:13 +01:00
|
|
|
require(accountsIndex[_account] == 0);
|
2020-11-13 18:33:39 +01:00
|
|
|
accounts.push(_account);
|
|
|
|
accountsIndex[_account] = count;
|
|
|
|
count++;
|
|
|
|
emit AccountAdded(_account, count-1);
|
2020-12-07 16:41:48 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function have(address _account) external view returns (bool) {
|
|
|
|
return accountsIndex[_account] > 0;
|
2020-11-13 18:33:39 +01:00
|
|
|
}
|
|
|
|
}
|