commit e723f26267e892928ffcd5976ff536455cc083a5
parent 9470b81fad996f8c46bceba8e9ae117da47fb5a7
Author: lash <dev@holbrook.no>
Date: Thu, 12 May 2022 15:46:29 +0000
Implement info cli tool on settings module
Diffstat:
3 files changed, 55 insertions(+), 49 deletions(-)
diff --git a/chainlib/eth/runnable/gas.py b/chainlib/eth/runnable/gas.py
@@ -75,8 +75,6 @@ settings = ChainSettings()
settings = process_settings(settings, config)
logg.debug('settings loaded:\n{}'.format(settings))
-value = config.get('_AMOUNT')
-
def balance(conn, address, id_generator):
o = gas_balance(address, id_generator=id_generator)
@@ -101,7 +99,7 @@ def main():
if not config.true('_UNSAFE') and not is_checksum_address(recipient):
raise ValueError('invalid checksum address')
- logg.info('gas transfer from {} to {} value {}'.format(settings.get('SENDER_ADDRESS'), settings.get('RECIPIENT'), value))
+ logg.info('gas transfer from {} to {} value {}'.format(settings.get('SENDER_ADDRESS'), settings.get('RECIPIENT'), config.get('_AMOUNT')))
if logg.isEnabledFor(logging.DEBUG):
try:
sender_balance = balance(
@@ -122,7 +120,7 @@ def main():
(tx_hash_hex, o) = g.create(
settings.get('SENDER_ADDRESS'),
settings.get('RECIPIENT'),
- value,
+ config.get('_AMOUNT'),
data=config.get('_DATA'),
id_generator=settings.get('RPC_ID_GENERATOR'),
)
diff --git a/chainlib/eth/runnable/get.py b/chainlib/eth/runnable/get.py
@@ -23,6 +23,7 @@ from chainlib.jsonrpc import (
)
from chainlib.chain import ChainSpec
from chainlib.status import Status
+from chainlib.settings import ChainSettings
# local imports
from chainlib.eth.connection import EthHTTPConnection
@@ -51,16 +52,23 @@ 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, format='%(asctime)s %(levelname)s %(filename)s:%(lineno)d %(message)s')
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.item, '_ITEM', False)
+ return config
+
+
arg_flags = ArgFlag()
arg = Arg(arg_flags)
-flags = arg_flags.STD_BASE_READ
+flags = arg_flags.STD_BASE_READ | arg_flags.TARGET
flags = arg_flags.less(flags, arg_flags.CHAIN_SPEC)
argparser = chainlib.eth.cli.ArgumentParser()
@@ -72,17 +80,16 @@ 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))
-rpc = chainlib.eth.cli.Rpc()
-conn = rpc.connect_by_config(config)
-
-chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC'))
+settings = ChainSettings()
+settings = process_settings(settings, config)
+logg.debug('settings loaded:\n{}'.format(settings))
-item = add_0x(args.item)
-def get_transaction(conn, tx_hash, id_generator):
+def get_transaction(conn, chain_spec, tx_hash, id_generator):
tx_hash = add_0x(tx_hash)
j = JSONRPCRequest(id_generator=id_generator)
o = j.template()
@@ -107,7 +114,6 @@ def get_transaction(conn, tx_hash, id_generator):
o['params'].append(tx_hash)
o = j.finalize(o)
rcpt = conn.do(o)
- #status = int(strip_0x(rcpt['status']), 16)
if tx == None:
tx = Tx(tx_src)
@@ -142,18 +148,27 @@ def get_address(conn, address, id_generator, height):
def main():
- address = item
r = None
- if len(address) > 42:
- r = get_transaction(conn, address, rpc.id_generator)
+ if len(config.get('_ITEM')) > 42:
+ r = get_transaction(
+ settings.get('CONN'),
+ settings.get('CHAIN_SPEC'),
+ config.get('_ITEM'),
+ settings.get('RPC_ID_GENERATOR'),
+ )
if not config.true('_RAW'):
r = r.to_human()
else:
- if config.get('_UNSAFE'):
- address = to_checksum_address(address)
- elif not is_checksum_address(address):
- raise ValueError('invalid checksum address: {}'.format(address))
- r = get_address(conn, address, rpc.id_generator, config.get('_HEIGHT'))
+ if config.true('_UNSAFE'):
+ address = to_checksum_address(config.get('_ITEM'))
+ elif not is_checksum_address(config.get('_ITEM')):
+ raise ValueError('invalid checksum address: {}'.format(config.get('_ITEM')))
+ r = get_address(
+ settings.get('CONN'),
+ config.get('_ITEM'),
+ settings.get('RPC_ID_GENERATOR'),
+ config.get('_HEIGHT'),
+ )
if r != None:
print(r)
diff --git a/chainlib/eth/runnable/info.py b/chainlib/eth/runnable/info.py
@@ -17,6 +17,7 @@ from hexathon import (
)
import sha3
from funga.eth.signer import EIP155Signer
+from chainlib.settings import ChainSettings
# local imports
from chainlib.eth.address import AddressChecksum
@@ -45,7 +46,7 @@ from chainlib.eth.cli.config import (
process_config,
)
from chainlib.eth.cli.log import process_log
-
+from chainlib.eth.settings import process_settings
BLOCK_SAMPLES = 10
@@ -68,6 +69,9 @@ def process_config_local(config, arg, args, flags):
config.add(args.local, '_LOCAL', False)
config.add(args.long, '_LONG', False)
config.add(args.entry, '_ENTRY', False)
+ if config.get('_ENTRY') != None:
+ if config.get('_ENTRY') not in results_translation.keys():
+ raise ValueError('Unknown entry {}'.format(config.get('_ENTRY')))
return config
arg_flags = ArgFlag()
@@ -88,20 +92,10 @@ config = process_config(config, arg, args, flags)
config = process_config_local(config, arg, args, flags)
logg.debug('config loaded:\n{}'.format(config))
-if config.get('_ENTRY') != None:
- if config.get('_ENTRY') not in results_translation.keys():
- raise ValueError('Unknown entry {}'.format(config.get('_ENTRY')))
-
-rpc = chainlib.eth.cli.Rpc()
-conn = rpc.connect_by_config(config)
-
-token_symbol = 'eth'
-
-chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC'))
-
-human = not config.true('_RAW')
+settings = ChainSettings()
+settings = process_settings(settings, config)
+logg.debug('settings loaded:\n{}'.format(settings))
-longmode = config.true('_LONG')
def set_result(results, k, v, w=sys.stdout):
kt = results_translation[k]
@@ -114,17 +108,16 @@ def set_result(results, k, v, w=sys.stdout):
def main():
+ human = not config.true('_RAW')
results = {}
- o = network_id(id_generator=rpc.id_generator)
- r = conn.do(o)
- #if human:
- # n = format(n, ',')
+ o = network_id(id_generator=settings.get('RPC_ID_GENERATOR'))
+ r = settings.get('CONN').do(o)
if set_result(results, 'network_id', r):
return
- o = block_latest(id_generator=rpc.id_generator)
- r = conn.do(o)
+ o = block_latest(id_generator=settings.get('RPC_ID_GENERATOR'))
+ r = settings.get('CONN').do(o)
try:
n = int(r, 16)
except ValueError:
@@ -135,17 +128,17 @@ def main():
if set_result(results, 'block', n):
return
- o = block_by_number(first_block_number, False, id_generator=rpc.id_generator)
- r = conn.do(o)
+ o = block_by_number(first_block_number, False, id_generator=settings.get('RPC_ID_GENERATOR'))
+ r = settings.get('CONN').do(o)
last_block = Block(r)
last_timestamp = last_block.timestamp
- if longmode:
+ if config.true('_LONG'):
aggr_time = 0.0
aggr_gas = 0
for i in range(BLOCK_SAMPLES):
- o = block_by_number(first_block_number-i, False, id_generator=rpc.id_generator)
- r = conn.do(o)
+ o = block_by_number(first_block_number-i, False, id_generator=settings.get('RPC_ID_GENERATOR'))
+ r = settings.get('CONN').do(o)
block = Block(r)
aggr_time += last_block.timestamp - block.timestamp
@@ -164,8 +157,8 @@ def main():
if set_result(results, 'block_time', aggr_time / BLOCK_SAMPLES):
return
- o = price(id_generator=rpc.id_generator)
- r = conn.do(o)
+ o = price(id_generator=settings.get('RPC_ID_GENERATOR'))
+ r = settings.get('CONN').do(o)
n = int(r, 16)
if human:
n = format(n, ',')
@@ -174,7 +167,7 @@ def main():
if config.get('_LOCAL'):
o = syncing()
- r = conn.do(o)
+ r = settings.get('CONN').do(o)
if set_result(results, 'syncing', r):
return