commit c4ebf45cc23154d2eccba54e5674e061911d66ec
parent af5fdb15fa00600aac7c9b35662f50a714455821
Author: nolash <dev@holbrook.no>
Date: Sat, 17 Apr 2021 11:55:44 +0200
Add owner and void cli tools
Diffstat:
6 files changed, 315 insertions(+), 2 deletions(-)
diff --git a/python/eth_owned/owned.py b/python/eth_owned/owned.py
@@ -62,3 +62,9 @@ class Owned(TxFactory):
tx = self.set_code(tx, data)
tx = self.finalize(tx, tx_format)
return tx
+
+
+ @classmethod
+ def parse_owner(self, v):
+ return abi_decode_single(ABIContractType.ADDRESS, v)
+
diff --git a/python/eth_owned/runnable/owner.py b/python/eth_owned/runnable/owner.py
@@ -0,0 +1,67 @@
+"""Query owner (EIP 173) of contract
+
+.. moduleauthor:: Louis Holbrook <dev@holbrook.no>
+.. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
+
+"""
+
+# standard imports
+import sys
+import os
+import json
+import argparse
+import logging
+
+# third-party imports
+from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer
+from crypto_dev_signer.keystore.dict import DictKeystore
+from crypto_dev_signer.eth.helper import EthTxExecutor
+from chainlib.chain import ChainSpec
+from chainlib.eth.connection import EthHTTPConnection
+from chainlib.error import JSONRPCException
+
+# local imports
+from eth_owned import Owned
+
+logging.basicConfig(level=logging.WARNING)
+logg = logging.getLogger()
+
+script_dir = os.path.dirname(__file__)
+data_dir = os.path.join(script_dir, '..', 'data')
+
+default_format = 'terminal'
+
+argparser = argparse.ArgumentParser()
+argparser.add_argument('-p', '--provider', dest='p', default='http://localhost:8545', type=str, help='RPC provider url (http only)')
+argparser.add_argument('-i', '--chain-spec', dest='i', type=str, default='evm:ethereum:1', help='Chain specification string')
+#argparser.add_argument('-a', '--contract-address', dest='a', required=True, type=str, help='Contract address')
+#argparser.add_argument('-f', '--format', dest='f', type=str, default=default_format, help='Output format [human, brief]')
+argparser.add_argument('-v', action='store_true', help='Be verbose')
+argparser.add_argument('-vv', action='store_true', help='Be more verbose')
+argparser.add_argument('--env-prefix', default=os.environ.get('CONFINI_ENV_PREFIX'), dest='env_prefix', type=str, help='environment prefix for variables to overwrite configuration')
+argparser.add_argument('address', type=str, nargs='?', help='Address to check registration for')
+args = argparser.parse_args()
+
+if args.vv:
+ logg.setLevel(logging.DEBUG)
+elif args.v:
+ logg.setLevel(logging.INFO)
+
+chain_spec = ChainSpec.from_chain_str(args.i)
+
+rpc = EthHTTPConnection(args.p)
+#account_registry_address = args.a
+address = args.address
+
+
+def main():
+ c = Owned(chain_spec)
+ o = c.owner(address)
+
+ r = rpc.do(o)
+ owner = c.parse_owner(r)
+ print(owner)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/python/eth_owned/runnable/void.py b/python/eth_owned/runnable/void.py
@@ -0,0 +1,120 @@
+"""Deploys the void owner contract
+
+.. moduleauthor:: Louis Holbrook <dev@holbrook.no>
+.. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
+
+"""
+
+# standard imports
+import sys
+import os
+import json
+import argparse
+import logging
+
+# third-party imports
+from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer
+from crypto_dev_signer.keystore.dict import DictKeystore
+from chainlib.chain import ChainSpec
+from chainlib.eth.nonce import (
+ RPCNonceOracle,
+ OverrideNonceOracle,
+ )
+from chainlib.eth.gas import (
+ RPCGasOracle,
+ OverrideGasOracle,
+ )
+from chainlib.eth.connection import EthHTTPConnection
+from chainlib.eth.tx import receipt
+
+# local imports
+from eth_owned.void import VoidOwner
+
+logging.basicConfig(level=logging.WARNING)
+logg = logging.getLogger()
+
+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', action='store_true', help='Wait for the last transaction to be confirmed')
+argparser.add_argument('-ww', action='store_true', help='Wait for every transaction to be confirmed')
+argparser.add_argument('-i', '--chain-spec', dest='i', type=str, default='evm:ethereum:1', help='Chain specification string')
+argparser.add_argument('-y', '--key-file', dest='y', type=str, help='Ethereum keystore file to use for signing')
+argparser.add_argument('-a', '--contract-address', dest='a', required=True, type=str, help='Void owner contract address')
+argparser.add_argument('-v', action='store_true', help='Be verbose')
+argparser.add_argument('-vv', action='store_true', help='Be more verbose')
+#argparser.add_argument('-d', action='store_true', help='Dump RPC calls to terminal and do not send')
+argparser.add_argument('--gas-price', type=int, dest='gas_price', help='Override gas price')
+argparser.add_argument('--nonce', type=int, help='Override transaction nonce')
+argparser.add_argument('--env-prefix', default=os.environ.get('CONFINI_ENV_PREFIX'), dest='env_prefix', type=str, help='environment prefix for variables to overwrite configuration')
+argparser.add_argument('address_to_void', type=str, help='EIP172 enabled contract to void ownership for')
+args = argparser.parse_args()
+
+if args.vv:
+ logg.setLevel(logging.DEBUG)
+elif args.v:
+ logg.setLevel(logging.INFO)
+
+block_last = args.w
+block_all = args.ww
+
+passphrase_env = 'ETH_PASSPHRASE'
+if args.env_prefix != None:
+ passphrase_env = args.env_prefix + '_' + passphrase_env
+passphrase = os.environ.get(passphrase_env)
+if passphrase == None:
+ logg.warning('no passphrase given')
+ passphrase=''
+
+signer_address = None
+keystore = DictKeystore()
+if args.y != None:
+ logg.debug('loading keystore file {}'.format(args.y))
+ signer_address = keystore.import_keystore_file(args.y, password=passphrase)
+ logg.debug('now have key for signer address {}'.format(signer_address))
+signer = EIP155Signer(keystore)
+
+chain_spec = ChainSpec.from_chain_str(args.i)
+
+rpc = EthHTTPConnection(args.p)
+nonce_oracle = None
+if args.nonce != None:
+ nonce_oracle = OverrideNonceOracle(signer_address, args.nonce)
+else:
+ nonce_oracle = RPCNonceOracle(signer_address, rpc)
+
+gas_oracle = None
+if args.gas_price !=None:
+ gas_oracle = OverrideGasOracle(price=args.gas_price, conn=rpc, code_callback=VoidOwner.gas)
+else:
+ gas_oracle = RPCGasOracle(rpc, code_callback=VoidOwner.gas)
+
+#dummy = args.d
+address_to_void = args.address_to_void
+void_receiver_address = args.a
+
+
+def main():
+ c = Owned(chain_spec, signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle)
+ (tx_hash_hex, o) = c.transfer_ownership(signer_address, address_to_void)
+ rpc.do(o)
+ r = rpc.wait(tx_hash_hex)
+ if r['status'] == 0:
+ sys.stderr.write('EVM revert while transferring ownership')
+ sys.exit(1)
+
+ c = VoidOwner(chain_spec, signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle)
+ (tx_hash_hex, o) = c.take_ownership(signer_address, void_receiver_address)
+ rpc.do(o)
+ r = rpc.wait(tx_hash_hex)
+ if r['status'] == 0:
+ sys.stderr.write('EVM revert while taking ownership')
+ sys.exit(1)
+
+ print(tx_hash_hex)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/python/eth_owned/runnable/void_deploy.py b/python/eth_owned/runnable/void_deploy.py
@@ -0,0 +1,117 @@
+"""Deploys the void owner contract
+
+.. moduleauthor:: Louis Holbrook <dev@holbrook.no>
+.. pgp:: 0826EDA1702D1E87C6E2875121D2E7BB88C2A746
+
+"""
+
+# standard imports
+import sys
+import os
+import json
+import argparse
+import logging
+
+# third-party imports
+from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer
+from crypto_dev_signer.keystore.dict import DictKeystore
+from chainlib.chain import ChainSpec
+from chainlib.eth.nonce import (
+ RPCNonceOracle,
+ OverrideNonceOracle,
+ )
+from chainlib.eth.gas import (
+ RPCGasOracle,
+ OverrideGasOracle,
+ )
+from chainlib.eth.connection import EthHTTPConnection
+from chainlib.eth.tx import receipt
+
+# local imports
+from eth_owned.void import VoidOwner
+
+logging.basicConfig(level=logging.WARNING)
+logg = logging.getLogger()
+
+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', action='store_true', help='Wait for the last transaction to be confirmed')
+argparser.add_argument('-ww', action='store_true', help='Wait for every transaction to be confirmed')
+argparser.add_argument('-i', '--chain-spec', dest='i', type=str, default='evm:ethereum:1', help='Chain specification string')
+argparser.add_argument('-y', '--key-file', dest='y', type=str, help='Ethereum keystore file to use for signing')
+argparser.add_argument('-v', action='store_true', help='Be verbose')
+argparser.add_argument('-vv', action='store_true', help='Be more verbose')
+argparser.add_argument('-d', action='store_true', help='Dump RPC calls to terminal and do not send')
+argparser.add_argument('--gas-price', type=int, dest='gas_price', help='Override gas price')
+argparser.add_argument('--nonce', type=int, help='Override transaction nonce')
+argparser.add_argument('--env-prefix', default=os.environ.get('CONFINI_ENV_PREFIX'), dest='env_prefix', type=str, help='environment prefix for variables to overwrite configuration')
+args = argparser.parse_args()
+
+if args.vv:
+ logg.setLevel(logging.DEBUG)
+elif args.v:
+ logg.setLevel(logging.INFO)
+
+block_last = args.w
+block_all = args.ww
+
+passphrase_env = 'ETH_PASSPHRASE'
+if args.env_prefix != None:
+ passphrase_env = args.env_prefix + '_' + passphrase_env
+passphrase = os.environ.get(passphrase_env)
+if passphrase == None:
+ logg.warning('no passphrase given')
+ passphrase=''
+
+signer_address = None
+keystore = DictKeystore()
+if args.y != None:
+ logg.debug('loading keystore file {}'.format(args.y))
+ signer_address = keystore.import_keystore_file(args.y, password=passphrase)
+ logg.debug('now have key for signer address {}'.format(signer_address))
+signer = EIP155Signer(keystore)
+
+chain_spec = ChainSpec.from_chain_str(args.i)
+
+rpc = EthHTTPConnection(args.p)
+nonce_oracle = None
+if args.nonce != None:
+ nonce_oracle = OverrideNonceOracle(signer_address, args.nonce)
+else:
+ nonce_oracle = RPCNonceOracle(signer_address, rpc)
+
+gas_oracle = None
+if args.gas_price !=None:
+ gas_oracle = OverrideGasOracle(price=args.gas_price, conn=rpc, code_callback=VoidOwner.gas)
+else:
+ gas_oracle = RPCGasOracle(rpc, code_callback=VoidOwner.gas)
+
+dummy = args.d
+
+
+def main():
+ c = VoidOwner(chain_spec, signer=signer, gas_oracle=gas_oracle, nonce_oracle=nonce_oracle)
+ (tx_hash_hex, o) = c.constructor(signer_address)
+ if dummy:
+ print(tx_hash_hex)
+ print(o)
+ else:
+ rpc.do(o)
+ if block_last:
+ r = rpc.wait(tx_hash_hex)
+ if r['status'] == 0:
+ sys.stderr.write('EVM revert while deploying contract. Wish I had more to tell you')
+ sys.exit(1)
+ # TODO: pass through translator for keys (evm tester uses underscore instead of camelcase)
+ address = r['contractAddress']
+
+ print(address)
+ else:
+ print(tx_hash_hex)
+
+
+if __name__ == '__main__':
+ main()
diff --git a/python/eth_owned/void.py b/python/eth_owned/void.py
@@ -55,7 +55,7 @@ class VoidOwner(TxFactory):
@staticmethod
def gas(code=None):
- return 700000
+ return 500000
def constructor(self, sender_address):
diff --git a/python/setup.cfg b/python/setup.cfg
@@ -1,7 +1,7 @@
[metadata]
name = eth-owned
version = 0.0.1a2
-description = EIP 172 interface and tools
+description = EIP 173 interface and tools
author = Louis Holbrook
author_email = dev@holbrook.no
url = https://gitlab.com/nolash/eth-owned
@@ -27,6 +27,7 @@ python_requires = >= 3.6
packages =
eth_owned
eth_owned.data
+ eth_owned.runnable
[options.extras_require]
testing =
@@ -42,3 +43,5 @@ testing =
[options.entry_points]
console_scripts =
eth-owner-void-deploy = eth_owned.runnable.void_deploy:main
+ eth-owner-void = eth_owned.runnable.void:main
+ eth-owner = eth_owned.runnable.owner:main