implement gas tool on new settings module
This commit is contained in:
parent
05d3357318
commit
33d9877bac
@ -42,6 +42,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
|
||||||
|
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
|
|
||||||
@ -71,14 +72,13 @@ config = process_config_local(config, arg, args, flags)
|
|||||||
logg.debug('config loaded:\n{}'.format(config))
|
logg.debug('config loaded:\n{}'.format(config))
|
||||||
|
|
||||||
settings = ChainSettings()
|
settings = ChainSettings()
|
||||||
settings = settings.process_settings(settings, config)
|
settings = process_settings(settings, config)
|
||||||
|
logg.debug('settings loaded:\n{}'.format(settings))
|
||||||
|
|
||||||
value = config.get('_AMOUNT')
|
value = config.get('_AMOUNT')
|
||||||
|
|
||||||
send = config.true('_RPC_SEND')
|
|
||||||
|
|
||||||
|
def balance(conn, address, id_generator):
|
||||||
def balance(address, id_generator):
|
|
||||||
o = gas_balance(address, id_generator=id_generator)
|
o = gas_balance(address, id_generator=id_generator)
|
||||||
r = conn.do(o)
|
r = conn.do(o)
|
||||||
try:
|
try:
|
||||||
@ -92,33 +92,58 @@ def balance(address, id_generator):
|
|||||||
def main():
|
def main():
|
||||||
g = Gas(
|
g = Gas(
|
||||||
settings.get('CHAIN_SPEC'),
|
settings.get('CHAIN_SPEC'),
|
||||||
signer=settings.get('SIGNER'), gas_oracle=rpc.get_gas_oracle(), nonce_oracle=rpc.get_nonce_oracle())
|
signer=settings.get('SIGNER'),
|
||||||
|
gas_oracle=settings.get('GAS_ORACLE'),
|
||||||
|
nonce_oracle=settings.get('NONCE_ORACLE'),
|
||||||
|
)
|
||||||
|
|
||||||
recipient = to_checksum_address(config.get('_RECIPIENT'))
|
recipient = to_checksum_address(config.get('_RECIPIENT'))
|
||||||
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(signer_address, recipient, value))
|
logg.info('gas transfer from {} to {} value {}'.format(settings.get('SENDER_ADDRESS'), settings.get('RECIPIENT'), value))
|
||||||
if logg.isEnabledFor(logging.DEBUG):
|
if logg.isEnabledFor(logging.DEBUG):
|
||||||
try:
|
try:
|
||||||
sender_balance = balance(add_0x(signer_address), rpc.id_generator)
|
sender_balance = balance(
|
||||||
recipient_balance = balance(add_0x(recipient), rpc.id_generator)
|
settings.get('CONN'),
|
||||||
logg.debug('sender {} balance before: {}'.format(signer_address, sender_balance))
|
settings.get('SENDER_ADDRESS'),
|
||||||
logg.debug('recipient {} balance before: {}'.format(recipient, recipient_balance))
|
settings.get('RPC_ID_GENERATOR'),
|
||||||
|
)
|
||||||
|
recipient_balance = balance(
|
||||||
|
settings.get('CONN'),
|
||||||
|
settings.get('RECIPIENT'),
|
||||||
|
settings.get('RPC_ID_GENERATOR'),
|
||||||
|
)
|
||||||
|
logg.debug('sender {} balance before: {}'.format(settings.get('SENDER_ADDRESS'), sender_balance))
|
||||||
|
logg.debug('recipient {} balance before: {}'.format(settings.get('RECIPIENT'), recipient_balance))
|
||||||
except urllib.error.URLError:
|
except urllib.error.URLError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
(tx_hash_hex, o) = g.create(signer_address, add_0x(recipient), value, data=config.get('_DATA'), id_generator=rpc.id_generator)
|
(tx_hash_hex, o) = g.create(
|
||||||
|
settings.get('SENDER_ADDRESS'),
|
||||||
|
settings.get('RECIPIENT'),
|
||||||
|
value,
|
||||||
|
data=config.get('_DATA'),
|
||||||
|
id_generator=settings.get('RPC_ID_GENERATOR'),
|
||||||
|
)
|
||||||
|
|
||||||
if send:
|
if settings.get('RPC_SEND'):
|
||||||
conn.do(o)
|
settings.get('CONN').do(o)
|
||||||
if config.true('_WAIT'):
|
if config.true('_WAIT'):
|
||||||
r = conn.wait(tx_hash_hex)
|
r = settings.get('CONN').wait(tx_hash_hex)
|
||||||
if logg.isEnabledFor(logging.DEBUG):
|
if logg.isEnabledFor(logging.DEBUG):
|
||||||
sender_balance = balance(add_0x(signer_address), rpc.id_generator)
|
sender_balance = balance(
|
||||||
recipient_balance = balance(add_0x(recipient), rpc.id_generator)
|
settings.get('CONN'),
|
||||||
logg.debug('sender {} balance after: {}'.format(signer_address, sender_balance))
|
settings.get('SENDER_ADDRESS'),
|
||||||
logg.debug('recipient {} balance after: {}'.format(recipient, recipient_balance))
|
settings.get('RPC_ID_GENERATOR'),
|
||||||
|
)
|
||||||
|
recipient_balance = balance(
|
||||||
|
settings.get('CONN'),
|
||||||
|
settings.get('RECIPIENT'),
|
||||||
|
settings.get('RPC_ID_GENERATOR'),
|
||||||
|
)
|
||||||
|
logg.debug('sender {} balance before: {}'.format(settings.get('SENDER_ADDRESS'), sender_balance))
|
||||||
|
logg.debug('recipient {} balance before: {}'.format(settings.get('RECIPIENT'), recipient_balance))
|
||||||
if r['status'] == 0:
|
if r['status'] == 0:
|
||||||
logg.critical('VM revert for {}. Wish I could tell you more'.format(tx_hash_hex))
|
logg.critical('VM revert for {}. Wish I could tell you more'.format(tx_hash_hex))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@ -128,7 +153,7 @@ def main():
|
|||||||
print(o['params'][0])
|
print(o['params'][0])
|
||||||
else:
|
else:
|
||||||
io_str = io.StringIO()
|
io_str = io.StringIO()
|
||||||
decode_for_puny_humans(o['params'][0], chain_spec, io_str)
|
decode_for_puny_humans(o['params'][0], settings.get('CHAIN_SPEC'), io_str)
|
||||||
print(io_str.getvalue())
|
print(io_str.getvalue())
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,22 +1,31 @@
|
|||||||
# external imports
|
# external imports
|
||||||
from chainlib.settings import process_settings as base_process_settings
|
from chainlib.settings import process_settings as base_process_settings
|
||||||
|
from hexathon import add_0x
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
import chainlib.eth.cli
|
import chainlib.eth.cli
|
||||||
|
|
||||||
|
|
||||||
def process_settings_rpc(settings, config):
|
def process_settings_rpc(settings, config):
|
||||||
rpc = chainlib.eth.cli.Rpc()
|
rpc = chainlib.eth.cli.Rpc(settings.get('WALLET'))
|
||||||
conn = rpc.connect_by_config(config)
|
conn = rpc.connect_by_config(config)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
settings.set('SIGNER', rpc.get_signer())
|
settings.set('SIGNER', rpc.get_signer())
|
||||||
settings.set('SENDER_ADDRESS', rpc.get_sender_address())
|
sender_address = rpc.get_sender_address()
|
||||||
|
settings.set('SENDER_ADDRESS', add_0x(sender_address))
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
gas_oracle = rpc.get_gas_oracle()
|
||||||
|
settings.set('GAS_ORACLE', gas_oracle)
|
||||||
|
|
||||||
|
nonce_oracle = rpc.get_nonce_oracle()
|
||||||
|
settings.set('NONCE_ORACLE', nonce_oracle)
|
||||||
|
|
||||||
settings.set('CONN', conn)
|
settings.set('CONN', conn)
|
||||||
settings.set('RPC_ID_GENERATOR', rpc.id_generator)
|
settings.set('RPC_ID_GENERATOR', rpc.id_generator)
|
||||||
|
settings.set('RPC_SEND', config.true('_RPC_SEND'))
|
||||||
return settings
|
return settings
|
||||||
|
|
||||||
|
|
||||||
@ -32,19 +41,11 @@ def process_settings_wallet(settings, config):
|
|||||||
if wallet.get_signer_address() == None and recipient != None:
|
if wallet.get_signer_address() == None and recipient != None:
|
||||||
recipient = wallet.from_address(recipient)
|
recipient = wallet.from_address(recipient)
|
||||||
|
|
||||||
settings.set('RECIPIENT', recipient)
|
settings.set('WALLET', wallet)
|
||||||
|
settings.set('RECIPIENT', add_0x(recipient))
|
||||||
return settings
|
return settings
|
||||||
|
|
||||||
|
|
||||||
def process_settings_chain(settings, config):
|
|
||||||
gas_oracle = rpc.get_gas_oracle()
|
|
||||||
settings.set('GAS_ORACLE', gas_oracle)
|
|
||||||
|
|
||||||
nonce_oracle = rpc.get_nonce_oracle()
|
|
||||||
settings.set('NONCE_ORACLE', nonce_oracle)
|
|
||||||
return settings
|
|
||||||
|
|
||||||
|
|
||||||
def process_settings(settings, config):
|
def process_settings(settings, config):
|
||||||
settings = base_process_settings(settings, config)
|
settings = base_process_settings(settings, config)
|
||||||
settings = process_settings_wallet(settings, config)
|
settings = process_settings_wallet(settings, config)
|
||||||
|
Loading…
Reference in New Issue
Block a user