Enable writers for accounts index

This commit is contained in:
nolash 2021-10-20 14:49:52 +02:00
parent 173b4879d7
commit 59f11e3df3
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
6 changed files with 60 additions and 8 deletions

View File

@ -40,7 +40,7 @@ class AccountsIndexAddressDeclarator(AccountsIndex):
@staticmethod @staticmethod
def gas(code=None): def gas(code=None):
return 700000 return 1500000
def constructor(self, sender_address, context_address, address_declarator_address): def constructor(self, sender_address, context_address, address_declarator_address):

View File

@ -17,6 +17,10 @@ import chainlib.eth.cli
from chainlib.chain import ChainSpec from chainlib.chain import ChainSpec
from chainlib.eth.connection import EthHTTPConnection from chainlib.eth.connection import EthHTTPConnection
from chainlib.eth.tx import receipt from chainlib.eth.tx import receipt
from chainlib.eth.address import (
is_checksum_address,
is_address,
)
# local imports # local imports
from okota.accounts_index import AccountsIndexAddressDeclarator from okota.accounts_index import AccountsIndexAddressDeclarator

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
[{"inputs":[{"internalType":"address","name":"_tokenAddress","type":"address"},{"internalType":"address","name":"_addressDeclaratorAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"addedAccount","type":"address"},{"indexed":true,"internalType":"uint256","name":"accountIndex","type":"uint256"}],"name":"AddressAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"add","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"addressDeclaratorAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"have","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokenAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}] [{"inputs":[{"internalType":"address","name":"_tokenAddress","type":"address"},{"internalType":"address","name":"_addressDeclaratorAddress","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"addedAccount","type":"address"},{"indexed":true,"internalType":"uint256","name":"accountIndex","type":"uint256"}],"name":"AddressAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"previousOwner","type":"address"},{"indexed":true,"internalType":"address","name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"},{"inputs":[],"name":"acceptOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"add","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_writer","type":"address"}],"name":"addWriter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"addressDeclaratorAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_writer","type":"address"}],"name":"deleteWriter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_idx","type":"uint256"}],"name":"entry","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"entryCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"have","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"tokenAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]

View File

@ -1,6 +1,6 @@
[metadata] [metadata]
name = okota name = okota
version = 0.2.4a6 version = 0.2.4a14
description = Registries for CIC using the eth-address-index backend description = Registries for CIC using the eth-address-index backend
author = Louis Holbrook author = Louis Holbrook
author_email = dev@holbrook.no author_email = dev@holbrook.no

View File

@ -3,13 +3,16 @@ pragma solidity >0.6.11;
// SPDX-License-Identifier: GPL-3.0-or-later // SPDX-License-Identifier: GPL-3.0-or-later
// TODO: inherit accounts index contract
contract AccountsIndexAddressDeclarator { contract AccountsIndexAddressDeclarator {
address public tokenAddress; address public tokenAddress;
bytes32 tokenAddressHash; bytes32 tokenAddressHash;
address public addressDeclaratorAddress; address public addressDeclaratorAddress;
mapping(address => uint256) entryIndex; mapping(address => uint256) entryIndex;
uint256 count; //uint256 count;
mapping(address => bool) writers;
address[] entries;
address public owner; address public owner;
address newOwner; address newOwner;
@ -24,7 +27,7 @@ contract AccountsIndexAddressDeclarator {
tokenAddress = _tokenAddress; tokenAddress = _tokenAddress;
_tokenAddressPadded = abi.encode(tokenAddress); _tokenAddressPadded = abi.encode(tokenAddress);
tokenAddressHash = sha256(_tokenAddressPadded); tokenAddressHash = sha256(_tokenAddressPadded);
count = 1; entries.push(address(0));
} }
function add(address _account) external returns (bool) { function add(address _account) external returns (bool) {
@ -32,19 +35,64 @@ contract AccountsIndexAddressDeclarator {
bytes memory r; bytes memory r;
uint256 oldEntryIndex; uint256 oldEntryIndex;
require(writers[msg.sender]);
require(entryIndex[_account] == 0);
(ok, r) = addressDeclaratorAddress.call(abi.encodeWithSignature("addDeclaration(address,bytes32)", _account, tokenAddressHash)); (ok, r) = addressDeclaratorAddress.call(abi.encodeWithSignature("addDeclaration(address,bytes32)", _account, tokenAddressHash));
require(ok); require(ok);
require(r[31] == 0x01); require(r[31] == 0x01);
oldEntryIndex = count; oldEntryIndex = entries.length - 1;
entryIndex[_account] = oldEntryIndex; entryIndex[_account] = oldEntryIndex;
count++; entries.push(_account);
emit AddressAdded(_account, oldEntryIndex); emit AddressAdded(_account, oldEntryIndex);
return true; return true;
} }
// Implements AccountsIndex
function have(address _account) external view returns (bool) { function have(address _account) external view returns (bool) {
return entryIndex[_account] > 0; return entryIndex[_account] > 0;
} }
// Implements AccountsIndex
function entry(uint256 _idx) public returns (address) {
return entries[_idx+1];
}
// Implements AccountsIndex
function entryCount() public returns (uint256) {
return entries.length - 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;
}
// Implements EIP173
function transferOwnership(address _newOwner) public returns (bool) {
require(msg.sender == owner);
newOwner = _newOwner;
return true;
}
// Implements OwnedAccepter
function acceptOwnership() public returns (bool) {
address oldOwner;
require(msg.sender == newOwner);
oldOwner = owner;
owner = newOwner;
newOwner = address(0);
emit OwnershipTransferred(oldOwner, owner);
return true;
}
} }