chainlib-eth

Ethereum implementation of the chainlib interface
Log | Files | Refs | README | LICENSE

commit 9470b81fad996f8c46bceba8e9ae117da47fb5a7
parent 2d06d60eedd4fc34b106985ef0c1eac81b708a61
Author: lash <dev@holbrook.no>
Date:   Thu, 12 May 2022 15:19:16 +0000

Implement decode tool on settings module

Diffstat:
Mchainlib/eth/runnable/count.py | 38+++++++++++++++++++++++---------------
Mchainlib/eth/runnable/decode.py | 20+++++++++++++++++---
Mchainlib/eth/settings.py | 3+++
3 files changed, 43 insertions(+), 18 deletions(-)

diff --git a/chainlib/eth/runnable/count.py b/chainlib/eth/runnable/count.py @@ -8,6 +8,14 @@ import json import logging import select +# external imports +from chainlib.settings import ChainSettings +from chainlib.chain import ChainSpec +from chainlib.jsonrpc import IntSequenceGenerator +from funga.eth.keystore.dict import DictKeystore +from funga.eth.signer import EIP155Signer +from hexathon import add_0x + # local imports import chainlib.eth.cli from chainlib.eth.cli.arg import ( @@ -23,17 +31,18 @@ from chainlib.eth.cli.log import process_log from chainlib.eth.address import AddressChecksum from chainlib.eth.connection import EthHTTPConnection from chainlib.eth.tx import count -from chainlib.chain import ChainSpec -from chainlib.jsonrpc import IntSequenceGenerator -from funga.eth.keystore.dict import DictKeystore -from funga.eth.signer import EIP155Signer -from hexathon import add_0x +from chainlib.eth.settings import process_settings logg = logging.getLogger() script_dir = os.path.dirname(os.path.realpath(__file__)) config_dir = os.path.join(script_dir, '..', 'data', 'config') + +def process_config_local(config, arg, args, flags): + config.add(args.address, '_RECIPIENT', False) + return config + argparser = chainlib.eth.cli.ArgumentParser() arg_flags = ArgFlag() arg = Arg(arg_flags) @@ -48,22 +57,21 @@ logg.debug('flags {} {} {}'.format(flags, arg_flags.SEQ, flags & arg_flags.SEQ)) config = Config() config = process_config(config, arg, args, flags) +config = process_config_local(config, arg, args, flags) logg.debug('config loaded:\n{}'.format(config)) -holder_address = args.address -wallet = chainlib.eth.cli.Wallet() -wallet.from_config(config) -if wallet.get_signer_address() == None and holder_address != None: - wallet.from_address(holder_address) - -rpc = chainlib.eth.cli.Rpc(wallet=wallet) -conn = rpc.connect_by_config(config) +settings = ChainSettings() +settings = process_settings(settings, config) +logg.debug('settings loaded:\n{}'.format(settings)) def main(): # TODO: should tolerate if address not prefixed with 0x - o = count(add_0x(holder_address), id_generator=rpc.id_generator) - r = conn.do(o) + o = count( + settings.get('RECIPIENT'), + id_generator=settings.get('RPC_ID_GENERATOR'), + ) + r = settings.get('CONN').do(o) count_result = None try: count_result = int(r, 16) diff --git a/chainlib/eth/runnable/decode.py b/chainlib/eth/runnable/decode.py @@ -11,6 +11,7 @@ import select # external imports import chainlib.eth.cli from chainlib.eth.tx import unpack +from chainlib.settings import ChainSettings from chainlib.chain import ChainSpec # local imports @@ -26,6 +27,7 @@ from chainlib.eth.cli.config import ( process_config, ) from chainlib.eth.cli.log import process_log +from chainlib.eth.settings import process_settings logging.basicConfig(level=logging.WARNING) @@ -35,9 +37,14 @@ script_dir = os.path.dirname(os.path.realpath(__file__)) config_dir = os.path.join(script_dir, '..', 'data', 'config') +def process_config_local(config, arg, args, flags): + config.add(args.tx_data, '_TX_DATA', False) + return config + + arg_flags = ArgFlag() arg = Arg(arg_flags) -flags = arg_flags.VERBOSE | arg_flags.CHAIN_SPEC | arg_flags.RAW | arg_flags.ENV +flags = arg_flags.VERBOSE | arg_flags.CHAIN_SPEC | arg_flags.RAW | arg_flags.ENV | arg_flags.SEQ argparser = chainlib.eth.cli.ArgumentParser() argparser = process_args(argparser, arg, flags) @@ -48,13 +55,20 @@ logg = process_log(args, logg) config = Config() config = process_config(config, arg, args, flags) +config = process_config_local(config, arg, args, flags) logg.debug('config loaded:\n{}'.format(config)) +settings = ChainSettings() +settings = process_settings(settings, config) +logg.debug('settings loaded:\n{}'.format(settings)) -chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC')) def main(): - decode_for_puny_humans(args.tx_data, chain_spec, sys.stdout) + decode_for_puny_humans( + config.get('_TX_DATA'), + settings.get('CHAIN_SPEC'), + sys.stdout, + ) if __name__ == '__main__': main() diff --git a/chainlib/eth/settings.py b/chainlib/eth/settings.py @@ -1,5 +1,6 @@ # external imports from chainlib.settings import process_settings as base_process_settings +from chainlib.error import SignerMissingException from hexathon import add_0x # local imports @@ -16,6 +17,8 @@ def process_settings_rpc(settings, config): settings.set('SENDER_ADDRESS', add_0x(sender_address)) except AttributeError: pass + except SignerMissingException: + pass gas_oracle = rpc.get_gas_oracle() settings.set('GAS_ORACLE', gas_oracle)