mirror of
git://holbrook.no/eth-accounts-index
synced 2024-11-05 10:16:47 +01:00
47 lines
1.1 KiB
Solidity
47 lines
1.1 KiB
Solidity
pragma solidity >=0.6.12;
|
|
|
|
// 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);
|
|
|
|
constructor() public {
|
|
owner = msg.sender;
|
|
accounts.push(address(0));
|
|
count = 1;
|
|
}
|
|
|
|
function addWriter(address _writer) public returns (bool) {
|
|
require(owner == msg.sender);
|
|
writers[_writer] = true;
|
|
return true;
|
|
}
|
|
|
|
function deleteWriter(address _writer) public returns (bool) {
|
|
require(owner == msg.sender);
|
|
delete writers[_writer];
|
|
return true;
|
|
}
|
|
|
|
function add(address _account) external returns (bool) {
|
|
require(writers[msg.sender]);
|
|
require(accountsIndex[_account] == 0);
|
|
accounts.push(_account);
|
|
accountsIndex[_account] = count;
|
|
count++;
|
|
emit AccountAdded(_account, count-1);
|
|
return true;
|
|
}
|
|
|
|
function have(address _account) external view returns (bool) {
|
|
return accountsIndex[_account] > 0;
|
|
}
|
|
}
|