Implement block cli tool on settings module
This commit is contained in:
parent
33d9877bac
commit
2d06d60eed
@ -23,6 +23,7 @@ from chainlib.jsonrpc import (
|
|||||||
)
|
)
|
||||||
from chainlib.chain import ChainSpec
|
from chainlib.chain import ChainSpec
|
||||||
from chainlib.status import Status
|
from chainlib.status import Status
|
||||||
|
from chainlib.settings import ChainSettings
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from chainlib.eth.connection import EthHTTPConnection
|
from chainlib.eth.connection import EthHTTPConnection
|
||||||
@ -52,12 +53,18 @@ from chainlib.eth.cli.config import (
|
|||||||
process_config,
|
process_config,
|
||||||
)
|
)
|
||||||
from chainlib.eth.cli.log import process_log
|
from chainlib.eth.cli.log import process_log
|
||||||
|
from chainlib.eth.settings import process_settings
|
||||||
|
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
|
|
||||||
script_dir = os.path.dirname(os.path.realpath(__file__))
|
script_dir = os.path.dirname(os.path.realpath(__file__))
|
||||||
config_dir = os.path.join(script_dir, '..', 'data', 'config')
|
config_dir = os.path.join(script_dir, '..', 'data', 'config')
|
||||||
|
|
||||||
|
def process_config_local(config, arg, args, flags):
|
||||||
|
config.add(args.block, '_BLOCK', False)
|
||||||
|
return config
|
||||||
|
|
||||||
|
|
||||||
argparser = chainlib.eth.cli.ArgumentParser()
|
argparser = chainlib.eth.cli.ArgumentParser()
|
||||||
arg_flags = ArgFlag()
|
arg_flags = ArgFlag()
|
||||||
arg = Arg(arg_flags)
|
arg = Arg(arg_flags)
|
||||||
@ -71,17 +78,16 @@ logg = process_log(args, logg)
|
|||||||
|
|
||||||
config = Config()
|
config = Config()
|
||||||
config = process_config(config, arg, args, flags)
|
config = process_config(config, arg, args, flags)
|
||||||
|
config = process_config_local(config, arg, args, flags)
|
||||||
logg.debug('config loaded:\n{}'.format(config))
|
logg.debug('config loaded:\n{}'.format(config))
|
||||||
|
|
||||||
rpc = chainlib.eth.cli.Rpc()
|
settings = ChainSettings()
|
||||||
conn = rpc.connect_by_config(config)
|
settings = process_settings(settings, config)
|
||||||
|
logg.debug('settings loaded:\n{}'.format(settings))
|
||||||
chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC'))
|
|
||||||
|
|
||||||
item = add_0x(args.block)
|
|
||||||
|
|
||||||
|
|
||||||
def get_block(conn, block_identifier, id_generator):
|
def get_block(conn, block_identifier, id_generator):
|
||||||
|
|
||||||
maybe_hex = None
|
maybe_hex = None
|
||||||
r = None
|
r = None
|
||||||
try:
|
try:
|
||||||
@ -89,11 +95,11 @@ def get_block(conn, block_identifier, id_generator):
|
|||||||
except ValueError:
|
except ValueError:
|
||||||
r = get_block_number(conn, block_identifier, id_generator)
|
r = get_block_number(conn, block_identifier, id_generator)
|
||||||
|
|
||||||
if len(maybe_hex) != 64:
|
if maybe_hex != None:
|
||||||
r = get_block_number(conn, block_identifier, id_generator)
|
if len(maybe_hex) != 64:
|
||||||
|
r = get_block_number(conn, block_identifier, id_generator)
|
||||||
if maybe_hex != block_identifier:
|
elif maybe_hex != block_identifier:
|
||||||
r = get_block_hash(conn, block_identifier, id_generator)
|
r = get_block_hash(conn, block_identifier, id_generator)
|
||||||
else:
|
else:
|
||||||
r = get_block_number(conn, block_identifier, id_generator)
|
r = get_block_number(conn, block_identifier, id_generator)
|
||||||
|
|
||||||
@ -109,6 +115,7 @@ def get_block_number(conn, block_number, id_generator):
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
return block_src
|
return block_src
|
||||||
|
|
||||||
|
|
||||||
def get_block_hash(conn, block_hash, id_generator):
|
def get_block_hash(conn, block_hash, id_generator):
|
||||||
block_hash = add_0x(block_hash)
|
block_hash = add_0x(block_hash)
|
||||||
o = block_by_hash(block_hash, include_tx=False)
|
o = block_by_hash(block_hash, include_tx=False)
|
||||||
@ -124,8 +131,12 @@ def block_process(block_src):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
block_identifier = item
|
r = get_block(
|
||||||
r = get_block(conn, block_identifier, rpc.id_generator)
|
settings.get('CONN'),
|
||||||
|
config.get('_BLOCK'),
|
||||||
|
settings.get('RPC_ID_GENERATOR'),
|
||||||
|
)
|
||||||
|
|
||||||
if not config.true('_RAW'):
|
if not config.true('_RAW'):
|
||||||
r = r.to_human()
|
r = r.to_human()
|
||||||
else:
|
else:
|
||||||
|
Loading…
Reference in New Issue
Block a user