Split index interface and registry implementation

This commit is contained in:
nolash
2021-04-30 12:46:53 +02:00
parent 6aa5da01bd
commit 9363ed3bfb
7 changed files with 168 additions and 118 deletions

View File

@@ -4,9 +4,9 @@ pragma solidity >0.6.11;
contract CustodialAccountIndex {
address[] public entry;
mapping(address => uint256) public entryIndex;
uint256 public count;
address[] entries;
mapping(address => uint256) entryIndex;
uint256 count;
mapping(address => bool) writers;
address public owner;
address newOwner;
@@ -16,7 +16,7 @@ contract CustodialAccountIndex {
constructor() public {
owner = msg.sender;
entry.push(address(0));
entries.push(address(0));
count = 1;
}
@@ -32,29 +32,38 @@ contract CustodialAccountIndex {
return true;
}
// Implements AccountsIndex
function add(address _account) external returns (bool) {
require(writers[msg.sender]);
require(entryIndex[_account] == 0);
entry.push(_account);
entryIndex[_account] = count;
count++;
emit AccountAdded(_account, count-1);
entryIndex[_account] = entries.length;
entries.push(_account);
emit AccountAdded(_account, entries.length-1);
return true;
}
// Implements AccountsIndex
function have(address _account) external view returns (bool) {
return entryIndex[_account] > 0;
}
function entryCount() public returns (uint256) {
return count;
// Implements AccountsIndex
function entry(uint256 _idx) public returns (address) {
return entries[_idx+1];
}
// Implements AccountsIndex
function entryCount() public returns (uint256) {
return count - 1;
}
// Implements EIP173
function transferOwnership(address _newOwner) public returns (bool) {
require(msg.sender == owner);
newOwner = _newOwner;
}
// Implements OwnedAccepter
function acceptOwnership() public returns (bool) {
address oldOwner;
@@ -65,6 +74,7 @@ contract CustodialAccountIndex {
emit OwnershipTransferred(oldOwner, owner);
}
// Implements EIP165
function supportsInterface(bytes4 _sum) public pure returns (bool) {
if (_sum == 0xcbdb05c7) { // AccountsIndex
return true;