From 1bc61f286aada982752358364d672c9ad50e3d27 Mon Sep 17 00:00:00 2001 From: nolash Date: Tue, 22 Dec 2020 14:45:43 +0100 Subject: [PATCH] Add executable to add writers and accounts after deploy --- python/CHANGELOG | 2 + python/MANIFEST.in | 2 +- ...ountsIndex.abi.json => AccountsIndex.json} | 0 python/eth_accounts_index/runnable/add.py | 66 +++++++++++++++++++ python/setup.cfg | 9 ++- solidity/test.py | 2 +- 6 files changed, 76 insertions(+), 5 deletions(-) rename python/eth_accounts_index/data/{AccountsIndex.abi.json => AccountsIndex.json} (100%) create mode 100644 python/eth_accounts_index/runnable/add.py diff --git a/python/CHANGELOG b/python/CHANGELOG index afd7b09..e3a698d 100644 --- a/python/CHANGELOG +++ b/python/CHANGELOG @@ -1,3 +1,5 @@ +- 0.0.8 + - Add executable to add writers and addresses after deploy - 0.0.7 - Rename contracts-dir flag to abi-dir - Use package data dir as default abi dir diff --git a/python/MANIFEST.in b/python/MANIFEST.in index 4bff9ca..ebc3162 100644 --- a/python/MANIFEST.in +++ b/python/MANIFEST.in @@ -1 +1 @@ -include **/*.abi.json +include **/data/*.json **/data/*.bin diff --git a/python/eth_accounts_index/data/AccountsIndex.abi.json b/python/eth_accounts_index/data/AccountsIndex.json similarity index 100% rename from python/eth_accounts_index/data/AccountsIndex.abi.json rename to python/eth_accounts_index/data/AccountsIndex.json diff --git a/python/eth_accounts_index/runnable/add.py b/python/eth_accounts_index/runnable/add.py new file mode 100644 index 0000000..07ffce0 --- /dev/null +++ b/python/eth_accounts_index/runnable/add.py @@ -0,0 +1,66 @@ +"""Adds writers and/or account entries to accounts index + +.. moduleauthor:: Louis Holbrook +.. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746 + +""" + +# standard imports +import os +import json +import argparse +import logging + +# third-party imports +import web3 + + +logging.basicConfig(level=logging.WARNING) +logg = logging.getLogger() + +logging.getLogger('web3').setLevel(logging.WARNING) +logging.getLogger('urllib3').setLevel(logging.WARNING) + +script_dir = os.path.dirname(__file__) +data_dir = os.path.join(script_dir, '..', 'data') + +argparser = argparse.ArgumentParser() +argparser.add_argument('-p', '--provider', dest='p', default='http://localhost:8545', type=str, help='Web3 provider url (http only)') +argparser.add_argument('-w', '--writer', dest='w', action='append', type=str, help='Writer to add') +argparser.add_argument('-o', '--owner', dest='o', type=str, help='Accounts index owner') +argparser.add_argument('-a', '--account', dest='a', action='append', type=str, help='Account to add') +argparser.add_argument('-r', '--accounts-index-address', dest='r', required=True, type=str, help='Contract address to account index to edit') +argparser.add_argument('--abi-dir', dest='abi_dir', type=str, default=data_dir, help='Directory containing bytecode and abi (default: {})'.format(data_dir)) +argparser.add_argument('-v', action='store_true', help='Be verbose') +args = argparser.parse_args() + +if args.v: + logg.setLevel(logging.DEBUG) + +def main(): + w3 = web3.Web3(web3.Web3.HTTPProvider(args.p)) + + f = open(os.path.join(args.abi_dir, 'AccountsIndex.json'), 'r') + abi = json.load(f) + f.close() + + w3.eth.defaultAccount = w3.eth.accounts[0] + if args.o != None: + w3.eth.defaultAccount = args.o + logg.debug('owner address {}'.format(w3.eth.defaultAccount)) + + c = w3.eth.contract(abi=abi, address=args.r) + + if args.w != None: + for w in args.w: + logg.info('adding {} to write list'.format(w)) + print(c.functions.addWriter(w).transact().hex()) + + if args.a != None: + for a in args.a: + logg.info('adding {} to accounts index'.format(a)) + print(c.functions.add(a).transact().hex()) + + +if __name__ == '__main__': + main() diff --git a/python/setup.cfg b/python/setup.cfg index c69a709..94a640c 100644 --- a/python/setup.cfg +++ b/python/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = eth-accounts-index -version = 0.0.7 +version = 0.0.8 description = Accounts index evm contract tooling with permissioned writes author = Louis Holbrook author_email = dev@holbrook.no @@ -27,7 +27,7 @@ packages = eth_accounts_index eth_accounts_index.runnable install_requires = - confini==0.3.4 + confini==0.3.5 web3==5.12.2 tests_require = pytest==6.0.1 @@ -41,8 +41,11 @@ testing = py-evm==0.3.0a20 [options.package_data] -* = **/*.abi.json +* = + **/data/*.json + **/data/*.bin [options.entry_points] console_scripts = accounts-index-deploy = eth_accounts_index.runnable.deploy:main + accounts-index-add = eth_accounts_index.runnable.add:main diff --git a/solidity/test.py b/solidity/test.py index 8b953b1..3d415f7 100644 --- a/solidity/test.py +++ b/solidity/test.py @@ -16,7 +16,7 @@ f = open('AccountsIndex.bin', 'r') bytecode = f.read() f.close() -f = open('AccountsIndex.abi.json', 'r') +f = open('AccountsIndex.json', 'r') abi = json.load(f) f.close()