Merge branch 'dev-0.3.1' into 'master'

- Updates data from compiled solc.

See merge request cicnet/eth-accounts-index!6
This commit is contained in:
Louis Holbrook 2023-02-05 04:54:50 +00:00
commit 63e99d7b18
8 changed files with 90 additions and 66 deletions

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
[{"inputs":[],"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":[{"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":[{"internalType":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]
[{"inputs":[],"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":[{"internalType":"address","name":"_writer","type":"address"}],"name":"deleteWriter","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"entryCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"have","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"isRemoved","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_account","type":"address"}],"name":"remove","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"_sum","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"_newOwner","type":"address"}],"name":"transferOwnership","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"nonpayable","type":"function"}]

View File

@ -38,10 +38,11 @@ class AccountsIndex(TxFactory):
tx = self.finalize(tx, tx_format)
return tx
def add(self, contract_address, sender_address, address, tx_format=TxFormat.JSONRPC):
return self.__single_address_method('add', contract_address, sender_address, address, tx_format)
def remove(self, contract_address, sender_address, address, tx_format=TxFormat.JSONRPC):
return self.__single_address_method('remove', contract_address, sender_address, address, tx_format)
def have(self, contract_address, address, sender_address=ZERO_ADDRESS, id_generator=None):
j = JSONRPCRequest(id_generator)
@ -57,7 +58,6 @@ class AccountsIndex(TxFactory):
o['params'].append(self.normalize(tx))
return o
def entry_count(self, contract_address, sender_address=ZERO_ADDRESS, id_generator=None):
j = JSONRPCRequest(id_generator)
o = j.template()
@ -70,11 +70,9 @@ class AccountsIndex(TxFactory):
o['params'].append(self.normalize(tx))
return o
def count(self, contract_address, sender_address=ZERO_ADDRESS, id_generator=None):
return self.entry_count(contract_address, sender_address=sender_address, id_generator=id_generator)
def entry(self, contract_address, idx, sender_address=ZERO_ADDRESS, id_generator=None):
j = JSONRPCRequest(id_generator)
o = j.template()
@ -89,22 +87,18 @@ class AccountsIndex(TxFactory):
o['params'].append(self.normalize(tx))
return o
@classmethod
def parse_account(self, v):
return abi_decode_single(ABIContractType.ADDRESS, v)
@classmethod
def parse_entry_count(self, v):
return abi_decode_single(ABIContractType.UINT256, v)
@classmethod
def parse_have(self, v):
return abi_decode_single(ABIContractType.BOOLEAN, v)
@classmethod
def parse_add_request(self, v):
v = strip_0x(v)

View File

@ -1,6 +1,8 @@
# standard imports
import os
import json
import pathlib
# external imports
from chainlib.eth.tx import (
TxFormat,
@ -18,40 +20,34 @@ datadir = os.path.join(moddir, 'data')
class AccountRegistry(AccountsIndex):
__abi = None
__bytecode = None
@staticmethod
def abi():
if AccountRegistry.__abi == None:
f = open(os.path.join(datadir, 'AccountsIndex.json'), 'r')
if AccountRegistry.__abi is None:
with open(os.path.join(datadir, 'AccountsIndex.json'), 'r') as f:
AccountRegistry.__abi = json.load(f)
f.close()
return AccountRegistry.__abi
@staticmethod
def bytecode():
if AccountRegistry.__bytecode == None:
f = open(os.path.join(datadir, 'AccountsIndex.bin'))
AccountRegistry.__bytecode = f.read()
f.close()
if AccountRegistry.__bytecode is None:
AccountRegistry.__bytecode = pathlib.Path(
os.path.join(datadir, 'AccountsIndex.bin')
).read_text()
return AccountRegistry.__bytecode
@staticmethod
def gas(code=None):
return 1200000
def constructor(self, sender_address):
code = AccountRegistry.bytecode()
tx = self.template(sender_address, None, use_nonce=True)
tx = self.set_code(tx, code)
return self.build(tx)
def __single_address_method(self, method, contract_address, sender_address, address, tx_format=TxFormat.JSONRPC):
enc = ABIContractEncoder()
enc.method(method)
@ -63,10 +59,8 @@ class AccountRegistry(AccountsIndex):
tx = self.finalize(tx, tx_format)
return tx
def add_writer(self, contract_address, sender_address, address, tx_format=TxFormat.JSONRPC):
return self.__single_address_method('addWriter', contract_address, sender_address, address, tx_format)
def delete_writer(self, contract_address, sender_address, address, tx_format=TxFormat.JSONRPC):
return self.__single_address_method('deleteWriter', contract_address, sender_address, address, tx_format)

View File

@ -1,6 +1,6 @@
[metadata]
name = eth-accounts-index
version = 0.3.0
version = 0.3.1
description = Accounts index evm contract tooling with permissioned writes
author = Louis Holbrook
author_email = dev@holbrook.no

View File

@ -50,7 +50,7 @@ class Test(EthTesterCase):
(tx_hash, o) = c.constructor(self.accounts[0])
self.conn = RPCConnection.connect(self.chain_spec, 'default')
r = self.conn.do(o)
logg.debug('deployed with hash {}'.format(r))
logg.debug(f'deployed with hash {r}')
o = receipt(r)
r = self.conn.do(o)
@ -133,6 +133,37 @@ class Test(EthTesterCase):
#self.assertFalse(registry.have(self.w3.eth.accounts[3]))
def test_5_remove(self):
nonce_oracle = RPCNonceOracle(self.accounts[0], self.conn)
c = AccountsIndex(self.chain_spec, signer=self.signer, nonce_oracle=nonce_oracle)
b = os.urandom(20)
a = to_checksum_address(b.hex())
(tx_hash, o) = c.add(self.address, self.accounts[0], a)
r = self.conn.do(o)
o = c.entry_count(self.address, sender_address=self.accounts[0])
r = self.conn.do(o)
count = c.parse_entry_count(r)
self.assertEqual(count, 1)
b = os.urandom(20)
a = to_checksum_address(b.hex())
(tx_hash, o) = c.add(self.address, self.accounts[0], a)
r = self.conn.do(o)
o = c.entry_count(self.address, sender_address=self.accounts[0])
r = self.conn.do(o)
count = c.parse_entry_count(r)
self.assertEqual(count, 2)
(tx_hash, o) = c.remove(self.address, self.accounts[0], a)
r = self.conn.do(o)
o = c.entry_count(self.address, sender_address=self.accounts[0])
r = self.conn.do(o)
count = c.parse_entry_count(r)
self.assertEqual(count, 1)
# TODO: reinstate all tests

View File

@ -5,7 +5,7 @@ pragma solidity >0.6.11;
contract CustodialAccountIndex {
address[] entries;
uint256 public entryCount;
mapping(address => uint256) entryIndex;
mapping(address => bool) writers;
address public owner;
@ -16,8 +16,6 @@ contract CustodialAccountIndex {
constructor() public {
owner = msg.sender;
entries.push(address(0));
count = 1;
}
function addWriter(address _writer) public returns (bool) {
@ -36,9 +34,18 @@ contract CustodialAccountIndex {
function add(address _account) external returns (bool) {
require(writers[msg.sender]);
require(entryIndex[_account] == 0);
entryIndex[_account] = entries.length;
entries.push(_account);
emit AddressAdded(_account, entries.length-1);
entryIndex[_account] = block.timestamp;
entryCount = entryCount + 1;
emit AddressAdded(_account, block.timestamp);
return true;
}
// Implements AccountsIndex
function remove(address _account) external returns (bool) {
require(writers[msg.sender]);
require(entryIndex[_account] > 0);
entryIndex[_account] = 0;
entryCount = entryCount - 1;
return true;
}
@ -47,16 +54,6 @@ contract CustodialAccountIndex {
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;
}
// Implements EIP173
function transferOwnership(address _newOwner) public returns (bool) {
require(msg.sender == owner);
@ -93,4 +90,11 @@ contract CustodialAccountIndex {
}
return false;
}
function isRemoved(address _account) external view returns (bool){
if (entryIndex[_account] == 0) {
return true;
}
return false;
}
}

View File

@ -6,5 +6,6 @@ all:
$(SOLC) --abi AccountsIndex.sol --evm-version byzantium | awk 'NR>3' > AccountsIndex.json
install: all
cp -v *{json,bin} ../python/eth_accounts_index/data/
cp -v *"json" ../python/eth_accounts_index/data/
cp -v *"bin" ../python/eth_accounts_index/data/