accounts-index

Accounts index evm contract tooling with permissioned writes
Log | Files | Refs

commit 7913bf42f218c1cf98d777a4ad7e536a68cc2c2c
parent ca05d2b2c76e36f8210ca31830f4c971de36f033
Author: Louis Holbrook <accounts-gitlab@holbrook.no>
Date:   Sun,  5 Feb 2023 04:54:50 +0000

- Updates data from compiled solc.

Diffstat:
Mpython/eth_accounts_index/data/AccountsIndex.bin | 4++--
Mpython/eth_accounts_index/data/AccountsIndex.json | 2+-
Mpython/eth_accounts_index/interface.py | 40+++++++++++++++++-----------------------
Mpython/eth_accounts_index/registry.py | 36+++++++++++++++---------------------
Mpython/setup.cfg | 2+-
Mpython/tests/test_app.py | 35+++++++++++++++++++++++++++++++++--
Msolidity/AccountsIndex.sol | 34+++++++++++++++++++---------------
Msolidity/Makefile | 3++-
8 files changed, 90 insertions(+), 66 deletions(-)

diff --git a/python/eth_accounts_index/data/AccountsIndex.bin b/python/eth_accounts_index/data/AccountsIndex.bin @@ -1 +1 @@ -608060405234801561001057600080fd5b5033600460006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060008080600181540180825580915050600190039060005260206000200160009091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506001600281905550610d0d806100cb6000396000f3fe608060405234801561001057600080fd5b50600436106100bb576000357c01000000000000000000000000000000000000000000000000000000009004806379ba50971161008357806379ba50971461019e5780638da5cb5b146101bc578063da2824a8146101da578063e2095c071461020a578063f2fde38b1461023a576100bb565b806301ffc9a7146100c05780630a3b0a4f146100f05780630cbb0f83146101205780633ef250131461013e5780635ae06f7e1461016e575b600080fd5b6100da60048036038101906100d59190610a95565b61026a565b6040516100e79190610b2f565b60405180910390f35b61010a60048036038101906101059190610a6c565b6103c2565b6040516101179190610b2f565b60405180910390f35b610128610570565b6040516101359190610b4a565b60405180910390f35b61015860048036038101906101539190610a6c565b610589565b6040516101659190610b2f565b60405180910390f35b61018860048036038101906101839190610a6c565b6105d4565b6040516101959190610b2f565b60405180910390f35b6101a6610688565b6040516101b39190610b2f565b60405180910390f35b6101c461082f565b6040516101d19190610b14565b60405180910390f35b6101f460048036038101906101ef9190610a6c565b610855565b6040516102019190610b2f565b60405180910390f35b610224600480360381019061021f9190610abe565b610912565b6040516102319190610b14565b60405180910390f35b610254600480360381019061024f9190610a6c565b61098b565b6040516102619190610b2f565b60405180910390f35b600063cbdb05c77c010000000000000000000000000000000000000000000000000000000002827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614156102bf57600190506103bd565b6301ffc9a77c010000000000000000000000000000000000000000000000000000000002827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916141561031257600190506103bd565b639493f8b27c010000000000000000000000000000000000000000000000000000000002827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916141561036557600190506103bd565b6337a47be47c010000000000000000000000000000000000000000000000000000000002827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff191614156103b857600190506103bd565b600090505b919050565b6000600360003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff1661041a57600080fd5b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541461046657600080fd5b600080549050600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020819055506000829080600181540180825580915050600190039060005260206000200160009091909190916101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555060016000805490506105249190610bbb565b8273ffffffffffffffffffffffffffffffffffffffff167f9cc987676e7d63379f176ea50df0ae8d2d9d1141d1231d4ce15b5965f73c943060405160405180910390a360019050919050565b600060016000805490506105849190610bbb565b905090565b600080600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054119050919050565b60003373ffffffffffffffffffffffffffffffffffffffff16600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461063057600080fd5b600360008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81549060ff021916905560019050919050565b600080600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146106e557600080fd5b600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050600560009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16600460006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506000600560006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35090565b600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60003373ffffffffffffffffffffffffffffffffffffffff16600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16146108b157600080fd5b6001600360008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555060019050919050565b6000806001836109229190610b65565b81548110610959577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b9060005260206000200160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050919050565b6000600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146109e757600080fd5b81600560006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550919050565b600081359050610a3c81610c92565b92915050565b600081359050610a5181610ca9565b92915050565b600081359050610a6681610cc0565b92915050565b600060208284031215610a7e57600080fd5b6000610a8c84828501610a2d565b91505092915050565b600060208284031215610aa757600080fd5b6000610ab584828501610a42565b91505092915050565b600060208284031215610ad057600080fd5b6000610ade84828501610a57565b91505092915050565b610af081610bef565b82525050565b610aff81610c01565b82525050565b610b0e81610c59565b82525050565b6000602082019050610b296000830184610ae7565b92915050565b6000602082019050610b446000830184610af6565b92915050565b6000602082019050610b5f6000830184610b05565b92915050565b6000610b7082610c59565b9150610b7b83610c59565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff03821115610bb057610baf610c63565b5b828201905092915050565b6000610bc682610c59565b9150610bd183610c59565b925082821015610be457610be3610c63565b5b828203905092915050565b6000610bfa82610c39565b9050919050565b60008115159050919050565b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b610c9b81610bef565b8114610ca657600080fd5b50565b610cb281610c0d565b8114610cbd57600080fd5b50565b610cc981610c59565b8114610cd457600080fd5b5056fea2646970667358221220f89a905a7d1b34f4616c7c88e97c0a10642a027985406572ad4e4db2604c0a6e64736f6c63430008030033 -\ No newline at end of file +608060405234801561001057600080fd5b5033600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550610d9e806100616000396000f3fe608060405234801561001057600080fd5b50600436106100c6576000357c0100000000000000000000000000000000000000000000000000000000900480635ae06f7e1161008e5780635ae06f7e146101a957806379ba5097146101d95780637d3374e5146101f75780638da5cb5b14610227578063da2824a814610245578063f2fde38b14610275576100c6565b806301ffc9a7146100cb5780630a3b0a4f146100fb5780630cbb0f831461012b57806329092d0e146101495780633ef2501314610179575b600080fd5b6100e560048036038101906100e09190610b85565b6102a5565b6040516100f29190610bcd565b60405180910390f35b61011560048036038101906101109190610c46565b61044b565b6040516101229190610bcd565b60405180910390f35b610133610595565b6040516101409190610c8c565b60405180910390f35b610163600480360381019061015e9190610c46565b61059b565b6040516101709190610bcd565b60405180910390f35b610193600480360381019061018e9190610c46565b6106a2565b6040516101a09190610bcd565b60405180910390f35b6101c360048036038101906101be9190610c46565b6106ed565b6040516101d09190610bcd565b60405180910390f35b6101e16107a1565b6040516101ee9190610bcd565b60405180910390f35b610211600480360381019061020c9190610c46565b610948565b60405161021e9190610bcd565b60405180910390f35b61022f6109a3565b60405161023c9190610cb6565b60405180910390f35b61025f600480360381019061025a9190610c46565b6109c9565b60405161026c9190610bcd565b60405180910390f35b61028f600480360381019061028a9190610c46565b610a86565b60405161029c9190610bcd565b60405180910390f35b600063cbdb05c77c010000000000000000000000000000000000000000000000000000000002827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916036102f95760019050610446565b6301ffc9a77c010000000000000000000000000000000000000000000000000000000002827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19160361034b5760019050610446565b639493f8b27c010000000000000000000000000000000000000000000000000000000002827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff19160361039d5760019050610446565b6337a47be47c010000000000000000000000000000000000000000000000000000000002827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916036103ef5760019050610446565b6380c84bd67c010000000000000000000000000000000000000000000000000000000002827bffffffffffffffffffffffffffffffffffffffffffffffffffffffff1916036104415760019050610446565b600090505b919050565b6000600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff166104a357600080fd5b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054146104ef57600080fd5b42600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555060016000546105429190610d00565b600081905550428273ffffffffffffffffffffffffffffffffffffffff167f9cc987676e7d63379f176ea50df0ae8d2d9d1141d1231d4ce15b5965f73c943060405160405180910390a360019050919050565b60005481565b6000600260003373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060009054906101000a900460ff166105f357600080fd5b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168152602001908152602001600020541161063f57600080fd5b6000600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000208190555060016000546106939190610d34565b60008190555060019050919050565b600080600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002054119050919050565b60003373ffffffffffffffffffffffffffffffffffffffff16600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff161461074957600080fd5b600260008373ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81549060ff021916905560019050919050565b600080600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff16146107fe57600080fd5b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff169050600460009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16600360006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055506000600460006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff167f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e060405160405180910390a35090565b600080600160008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1681526020019081526020016000205403610999576001905061099e565b600090505b919050565b600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b60003373ffffffffffffffffffffffffffffffffffffffff16600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff1614610a2557600080fd5b6001600260008473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16815260200190815260200160002060006101000a81548160ff02191690831515021790555060019050919050565b6000600360009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610ae257600080fd5b81600460006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550919050565b600080fd5b60007fffffffff0000000000000000000000000000000000000000000000000000000082169050919050565b610b6281610b2d565b8114610b6d57600080fd5b50565b600081359050610b7f81610b59565b92915050565b600060208284031215610b9b57610b9a610b28565b5b6000610ba984828501610b70565b91505092915050565b60008115159050919050565b610bc781610bb2565b82525050565b6000602082019050610be26000830184610bbe565b92915050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000610c1382610be8565b9050919050565b610c2381610c08565b8114610c2e57600080fd5b50565b600081359050610c4081610c1a565b92915050565b600060208284031215610c5c57610c5b610b28565b5b6000610c6a84828501610c31565b91505092915050565b6000819050919050565b610c8681610c73565b82525050565b6000602082019050610ca16000830184610c7d565b92915050565b610cb081610c08565b82525050565b6000602082019050610ccb6000830184610ca7565b92915050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b6000610d0b82610c73565b9150610d1683610c73565b9250828201905080821115610d2e57610d2d610cd1565b5b92915050565b6000610d3f82610c73565b9150610d4a83610c73565b9250828203905081811115610d6257610d61610cd1565b5b9291505056fea2646970667358221220bb3974285de177fcb410d25715db8c72660744f280fe34b0c9f5b37c6459d33e64736f6c63430008120033 +\ No newline at end of file diff --git a/python/eth_accounts_index/data/AccountsIndex.json b/python/eth_accounts_index/data/AccountsIndex.json @@ -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"}] diff --git a/python/eth_accounts_index/interface.py b/python/eth_accounts_index/interface.py @@ -5,22 +5,22 @@ import os # external imports from chainlib.eth.tx import ( - TxFactory, - TxFormat, - ) + TxFactory, + TxFormat, +) from chainlib.eth.contract import ( - ABIContractEncoder, - ABIContractDecoder, - ABIContractType, - abi_decode_single, - ) + ABIContractEncoder, + ABIContractDecoder, + ABIContractType, + abi_decode_single, +) from chainlib.eth.constant import ZERO_ADDRESS from chainlib.jsonrpc import JSONRPCRequest from chainlib.eth.error import RequestMismatchException from hexathon import ( - add_0x, - strip_0x, - ) + add_0x, + strip_0x, +) logg = logging.getLogger() @@ -35,13 +35,14 @@ class AccountsIndex(TxFactory): data = enc.get() tx = self.template(sender_address, contract_address, use_nonce=True) tx = self.set_code(tx, data) - tx = self.finalize(tx, tx_format) + 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,8 +58,7 @@ class AccountsIndex(TxFactory): o['params'].append(self.normalize(tx)) return o - - def entry_count(self, contract_address, sender_address=ZERO_ADDRESS, id_generator=None): + def entry_count(self, contract_address, sender_address=ZERO_ADDRESS, id_generator=None): j = JSONRPCRequest(id_generator) o = j.template() o['method'] = 'eth_call' @@ -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) @@ -121,6 +115,6 @@ class AccountsIndex(TxFactory): dec = ABIContractDecoder() dec.typ(ABIContractType.ADDRESS) - dec.val(v[cursor:cursor+64]) + dec.val(v[cursor:cursor + 64]) r = dec.decode() - return r + return r diff --git a/python/eth_accounts_index/registry.py b/python/eth_accounts_index/registry.py @@ -1,14 +1,16 @@ # standard imports import os +import json +import pathlib # external imports from chainlib.eth.tx import ( - TxFormat, - ) + TxFormat, +) from chainlib.eth.contract import ( - ABIContractEncoder, - ABIContractType, - ) + ABIContractEncoder, + ABIContractType, +) # local imports from .interface import AccountsIndex @@ -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') - AccountRegistry.__abi = json.load(f) - f.close() + if AccountRegistry.__abi is None: + with open(os.path.join(datadir, 'AccountsIndex.json'), 'r') as f: + AccountRegistry.__abi = json.load(f) 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) @@ -60,13 +56,11 @@ class AccountRegistry(AccountsIndex): data = enc.get() tx = self.template(sender_address, contract_address, use_nonce=True) tx = self.set_code(tx, data) - tx = self.finalize(tx, tx_format) + 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) diff --git a/python/setup.cfg b/python/setup.cfg @@ -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 diff --git a/python/tests/test_app.py b/python/tests/test_app.py @@ -50,8 +50,8 @@ 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) self.address = to_checksum_address(r['contract_address']) @@ -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 diff --git a/solidity/AccountsIndex.sol b/solidity/AccountsIndex.sol @@ -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,25 +34,24 @@ 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 have(address _account) external view returns (bool) { - return entryIndex[_account] > 0; - } - - // Implements AccountsIndex - function entry(uint256 _idx) public returns (address) { - return entries[_idx+1]; + function remove(address _account) external returns (bool) { + require(writers[msg.sender]); + require(entryIndex[_account] > 0); + entryIndex[_account] = 0; + entryCount = entryCount - 1; + return true; } // Implements AccountsIndex - function entryCount() public returns (uint256) { - return entries.length - 1; + function have(address _account) external view returns (bool) { + return entryIndex[_account] > 0; } // Implements EIP173 @@ -93,4 +90,11 @@ contract CustodialAccountIndex { } return false; } + + function isRemoved(address _account) external view returns (bool){ + if (entryIndex[_account] == 0) { + return true; + } + return false; + } } diff --git a/solidity/Makefile b/solidity/Makefile @@ -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/