Enable writers for accounts index
This commit is contained in:
parent
173b4879d7
commit
59f11e3df3
@ -40,7 +40,7 @@ class AccountsIndexAddressDeclarator(AccountsIndex):
|
||||
|
||||
@staticmethod
|
||||
def gas(code=None):
|
||||
return 700000
|
||||
return 1500000
|
||||
|
||||
|
||||
def constructor(self, sender_address, context_address, address_declarator_address):
|
||||
|
@ -17,6 +17,10 @@ import chainlib.eth.cli
|
||||
from chainlib.chain import ChainSpec
|
||||
from chainlib.eth.connection import EthHTTPConnection
|
||||
from chainlib.eth.tx import receipt
|
||||
from chainlib.eth.address import (
|
||||
is_checksum_address,
|
||||
is_address,
|
||||
)
|
||||
|
||||
# local imports
|
||||
from okota.accounts_index import AccountsIndexAddressDeclarator
|
||||
|
File diff suppressed because one or more lines are too long
@ -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"}]
|
||||
|
@ -1,6 +1,6 @@
|
||||
[metadata]
|
||||
name = okota
|
||||
version = 0.2.4a6
|
||||
version = 0.2.4a14
|
||||
description = Registries for CIC using the eth-address-index backend
|
||||
author = Louis Holbrook
|
||||
author_email = dev@holbrook.no
|
||||
|
@ -3,13 +3,16 @@ pragma solidity >0.6.11;
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
|
||||
// TODO: inherit accounts index contract
|
||||
contract AccountsIndexAddressDeclarator {
|
||||
|
||||
address public tokenAddress;
|
||||
bytes32 tokenAddressHash;
|
||||
address public addressDeclaratorAddress;
|
||||
mapping(address => uint256) entryIndex;
|
||||
uint256 count;
|
||||
//uint256 count;
|
||||
mapping(address => bool) writers;
|
||||
address[] entries;
|
||||
|
||||
address public owner;
|
||||
address newOwner;
|
||||
@ -24,7 +27,7 @@ contract AccountsIndexAddressDeclarator {
|
||||
tokenAddress = _tokenAddress;
|
||||
_tokenAddressPadded = abi.encode(tokenAddress);
|
||||
tokenAddressHash = sha256(_tokenAddressPadded);
|
||||
count = 1;
|
||||
entries.push(address(0));
|
||||
}
|
||||
|
||||
function add(address _account) external returns (bool) {
|
||||
@ -32,19 +35,64 @@ contract AccountsIndexAddressDeclarator {
|
||||
bytes memory r;
|
||||
uint256 oldEntryIndex;
|
||||
|
||||
require(writers[msg.sender]);
|
||||
require(entryIndex[_account] == 0);
|
||||
|
||||
(ok, r) = addressDeclaratorAddress.call(abi.encodeWithSignature("addDeclaration(address,bytes32)", _account, tokenAddressHash));
|
||||
require(ok);
|
||||
require(r[31] == 0x01);
|
||||
|
||||
oldEntryIndex = count;
|
||||
oldEntryIndex = entries.length - 1;
|
||||
entryIndex[_account] = oldEntryIndex;
|
||||
count++;
|
||||
entries.push(_account);
|
||||
|
||||
emit AddressAdded(_account, oldEntryIndex);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Implements AccountsIndex
|
||||
function have(address _account) external view returns (bool) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user