Implement info cli tool on settings module
This commit is contained in:
parent
9470b81fad
commit
e723f26267
@ -75,8 +75,6 @@ settings = ChainSettings()
|
|||||||
settings = process_settings(settings, config)
|
settings = process_settings(settings, config)
|
||||||
logg.debug('settings loaded:\n{}'.format(settings))
|
logg.debug('settings loaded:\n{}'.format(settings))
|
||||||
|
|
||||||
value = config.get('_AMOUNT')
|
|
||||||
|
|
||||||
|
|
||||||
def balance(conn, address, id_generator):
|
def balance(conn, address, id_generator):
|
||||||
o = gas_balance(address, id_generator=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):
|
if not config.true('_UNSAFE') and not is_checksum_address(recipient):
|
||||||
raise ValueError('invalid checksum address')
|
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):
|
if logg.isEnabledFor(logging.DEBUG):
|
||||||
try:
|
try:
|
||||||
sender_balance = balance(
|
sender_balance = balance(
|
||||||
@ -122,7 +120,7 @@ def main():
|
|||||||
(tx_hash_hex, o) = g.create(
|
(tx_hash_hex, o) = g.create(
|
||||||
settings.get('SENDER_ADDRESS'),
|
settings.get('SENDER_ADDRESS'),
|
||||||
settings.get('RECIPIENT'),
|
settings.get('RECIPIENT'),
|
||||||
value,
|
config.get('_AMOUNT'),
|
||||||
data=config.get('_DATA'),
|
data=config.get('_DATA'),
|
||||||
id_generator=settings.get('RPC_ID_GENERATOR'),
|
id_generator=settings.get('RPC_ID_GENERATOR'),
|
||||||
)
|
)
|
||||||
|
@ -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
|
||||||
@ -51,16 +52,23 @@ 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
|
||||||
|
|
||||||
|
|
||||||
logging.basicConfig(level=logging.WARNING, format='%(asctime)s %(levelname)s %(filename)s:%(lineno)d %(message)s')
|
|
||||||
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.item, '_ITEM', False)
|
||||||
|
return config
|
||||||
|
|
||||||
|
|
||||||
arg_flags = ArgFlag()
|
arg_flags = ArgFlag()
|
||||||
arg = Arg(arg_flags)
|
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)
|
flags = arg_flags.less(flags, arg_flags.CHAIN_SPEC)
|
||||||
|
|
||||||
argparser = chainlib.eth.cli.ArgumentParser()
|
argparser = chainlib.eth.cli.ArgumentParser()
|
||||||
@ -72,17 +80,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.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)
|
tx_hash = add_0x(tx_hash)
|
||||||
j = JSONRPCRequest(id_generator=id_generator)
|
j = JSONRPCRequest(id_generator=id_generator)
|
||||||
o = j.template()
|
o = j.template()
|
||||||
@ -107,7 +114,6 @@ def get_transaction(conn, tx_hash, id_generator):
|
|||||||
o['params'].append(tx_hash)
|
o['params'].append(tx_hash)
|
||||||
o = j.finalize(o)
|
o = j.finalize(o)
|
||||||
rcpt = conn.do(o)
|
rcpt = conn.do(o)
|
||||||
#status = int(strip_0x(rcpt['status']), 16)
|
|
||||||
|
|
||||||
if tx == None:
|
if tx == None:
|
||||||
tx = Tx(tx_src)
|
tx = Tx(tx_src)
|
||||||
@ -142,18 +148,27 @@ def get_address(conn, address, id_generator, height):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
address = item
|
|
||||||
r = None
|
r = None
|
||||||
if len(address) > 42:
|
if len(config.get('_ITEM')) > 42:
|
||||||
r = get_transaction(conn, address, rpc.id_generator)
|
r = get_transaction(
|
||||||
|
settings.get('CONN'),
|
||||||
|
settings.get('CHAIN_SPEC'),
|
||||||
|
config.get('_ITEM'),
|
||||||
|
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:
|
||||||
if config.get('_UNSAFE'):
|
if config.true('_UNSAFE'):
|
||||||
address = to_checksum_address(address)
|
address = to_checksum_address(config.get('_ITEM'))
|
||||||
elif not is_checksum_address(address):
|
elif not is_checksum_address(config.get('_ITEM')):
|
||||||
raise ValueError('invalid checksum address: {}'.format(address))
|
raise ValueError('invalid checksum address: {}'.format(config.get('_ITEM')))
|
||||||
r = get_address(conn, address, rpc.id_generator, config.get('_HEIGHT'))
|
r = get_address(
|
||||||
|
settings.get('CONN'),
|
||||||
|
config.get('_ITEM'),
|
||||||
|
settings.get('RPC_ID_GENERATOR'),
|
||||||
|
config.get('_HEIGHT'),
|
||||||
|
)
|
||||||
if r != None:
|
if r != None:
|
||||||
print(r)
|
print(r)
|
||||||
|
|
||||||
|
@ -17,6 +17,7 @@ from hexathon import (
|
|||||||
)
|
)
|
||||||
import sha3
|
import sha3
|
||||||
from funga.eth.signer import EIP155Signer
|
from funga.eth.signer import EIP155Signer
|
||||||
|
from chainlib.settings import ChainSettings
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
from chainlib.eth.address import AddressChecksum
|
from chainlib.eth.address import AddressChecksum
|
||||||
@ -45,7 +46,7 @@ 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
|
||||||
|
|
||||||
BLOCK_SAMPLES = 10
|
BLOCK_SAMPLES = 10
|
||||||
|
|
||||||
@ -68,6 +69,9 @@ def process_config_local(config, arg, args, flags):
|
|||||||
config.add(args.local, '_LOCAL', False)
|
config.add(args.local, '_LOCAL', False)
|
||||||
config.add(args.long, '_LONG', False)
|
config.add(args.long, '_LONG', False)
|
||||||
config.add(args.entry, '_ENTRY', 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
|
return config
|
||||||
|
|
||||||
arg_flags = ArgFlag()
|
arg_flags = ArgFlag()
|
||||||
@ -88,20 +92,10 @@ config = process_config(config, arg, args, flags)
|
|||||||
config = process_config_local(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))
|
||||||
|
|
||||||
if config.get('_ENTRY') != None:
|
settings = ChainSettings()
|
||||||
if config.get('_ENTRY') not in results_translation.keys():
|
settings = process_settings(settings, config)
|
||||||
raise ValueError('Unknown entry {}'.format(config.get('_ENTRY')))
|
logg.debug('settings loaded:\n{}'.format(settings))
|
||||||
|
|
||||||
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')
|
|
||||||
|
|
||||||
longmode = config.true('_LONG')
|
|
||||||
|
|
||||||
def set_result(results, k, v, w=sys.stdout):
|
def set_result(results, k, v, w=sys.stdout):
|
||||||
kt = results_translation[k]
|
kt = results_translation[k]
|
||||||
@ -114,17 +108,16 @@ def set_result(results, k, v, w=sys.stdout):
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
human = not config.true('_RAW')
|
||||||
results = {}
|
results = {}
|
||||||
|
|
||||||
o = network_id(id_generator=rpc.id_generator)
|
o = network_id(id_generator=settings.get('RPC_ID_GENERATOR'))
|
||||||
r = conn.do(o)
|
r = settings.get('CONN').do(o)
|
||||||
#if human:
|
|
||||||
# n = format(n, ',')
|
|
||||||
if set_result(results, 'network_id', r):
|
if set_result(results, 'network_id', r):
|
||||||
return
|
return
|
||||||
|
|
||||||
o = block_latest(id_generator=rpc.id_generator)
|
o = block_latest(id_generator=settings.get('RPC_ID_GENERATOR'))
|
||||||
r = conn.do(o)
|
r = settings.get('CONN').do(o)
|
||||||
try:
|
try:
|
||||||
n = int(r, 16)
|
n = int(r, 16)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
@ -135,17 +128,17 @@ def main():
|
|||||||
if set_result(results, 'block', n):
|
if set_result(results, 'block', n):
|
||||||
return
|
return
|
||||||
|
|
||||||
o = block_by_number(first_block_number, False, id_generator=rpc.id_generator)
|
o = block_by_number(first_block_number, False, id_generator=settings.get('RPC_ID_GENERATOR'))
|
||||||
r = conn.do(o)
|
r = settings.get('CONN').do(o)
|
||||||
last_block = Block(r)
|
last_block = Block(r)
|
||||||
last_timestamp = last_block.timestamp
|
last_timestamp = last_block.timestamp
|
||||||
|
|
||||||
if longmode:
|
if config.true('_LONG'):
|
||||||
aggr_time = 0.0
|
aggr_time = 0.0
|
||||||
aggr_gas = 0
|
aggr_gas = 0
|
||||||
for i in range(BLOCK_SAMPLES):
|
for i in range(BLOCK_SAMPLES):
|
||||||
o = block_by_number(first_block_number-i, False, id_generator=rpc.id_generator)
|
o = block_by_number(first_block_number-i, False, id_generator=settings.get('RPC_ID_GENERATOR'))
|
||||||
r = conn.do(o)
|
r = settings.get('CONN').do(o)
|
||||||
block = Block(r)
|
block = Block(r)
|
||||||
aggr_time += last_block.timestamp - block.timestamp
|
aggr_time += last_block.timestamp - block.timestamp
|
||||||
|
|
||||||
@ -164,8 +157,8 @@ def main():
|
|||||||
if set_result(results, 'block_time', aggr_time / BLOCK_SAMPLES):
|
if set_result(results, 'block_time', aggr_time / BLOCK_SAMPLES):
|
||||||
return
|
return
|
||||||
|
|
||||||
o = price(id_generator=rpc.id_generator)
|
o = price(id_generator=settings.get('RPC_ID_GENERATOR'))
|
||||||
r = conn.do(o)
|
r = settings.get('CONN').do(o)
|
||||||
n = int(r, 16)
|
n = int(r, 16)
|
||||||
if human:
|
if human:
|
||||||
n = format(n, ',')
|
n = format(n, ',')
|
||||||
@ -174,7 +167,7 @@ def main():
|
|||||||
|
|
||||||
if config.get('_LOCAL'):
|
if config.get('_LOCAL'):
|
||||||
o = syncing()
|
o = syncing()
|
||||||
r = conn.do(o)
|
r = settings.get('CONN').do(o)
|
||||||
if set_result(results, 'syncing', r):
|
if set_result(results, 'syncing', r):
|
||||||
return
|
return
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user