commit 33d9877bac512c6a8e3daa7d0a82793711afe122
parent 05d3357318ee30c2c22f500457071445b9394418
Author: lash <dev@holbrook.no>
Date: Thu, 12 May 2022 14:08:36 +0000
implement gas tool on new settings module
Diffstat:
2 files changed, 57 insertions(+), 31 deletions(-)
diff --git a/chainlib/eth/runnable/gas.py b/chainlib/eth/runnable/gas.py
@@ -42,6 +42,7 @@ from chainlib.eth.cli.config import (
process_config,
)
from chainlib.eth.cli.log import process_log
+from chainlib.eth.settings import process_settings
logg = logging.getLogger()
@@ -71,14 +72,13 @@ config = process_config_local(config, arg, args, flags)
logg.debug('config loaded:\n{}'.format(config))
settings = ChainSettings()
-settings = settings.process_settings(settings, config)
+settings = process_settings(settings, config)
+logg.debug('settings loaded:\n{}'.format(settings))
value = config.get('_AMOUNT')
-send = config.true('_RPC_SEND')
-
-def balance(address, id_generator):
+def balance(conn, address, id_generator):
o = gas_balance(address, id_generator=id_generator)
r = conn.do(o)
try:
@@ -92,33 +92,58 @@ def balance(address, id_generator):
def main():
g = Gas(
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'))
if not config.true('_UNSAFE') and not is_checksum_address(recipient):
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):
try:
- sender_balance = balance(add_0x(signer_address), rpc.id_generator)
- recipient_balance = balance(add_0x(recipient), rpc.id_generator)
- logg.debug('sender {} balance before: {}'.format(signer_address, sender_balance))
- logg.debug('recipient {} balance before: {}'.format(recipient, recipient_balance))
+ sender_balance = balance(
+ settings.get('CONN'),
+ settings.get('SENDER_ADDRESS'),
+ 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:
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:
- conn.do(o)
+ if settings.get('RPC_SEND'):
+ settings.get('CONN').do(o)
if config.true('_WAIT'):
- r = conn.wait(tx_hash_hex)
+ r = settings.get('CONN').wait(tx_hash_hex)
if logg.isEnabledFor(logging.DEBUG):
- sender_balance = balance(add_0x(signer_address), rpc.id_generator)
- recipient_balance = balance(add_0x(recipient), rpc.id_generator)
- logg.debug('sender {} balance after: {}'.format(signer_address, sender_balance))
- logg.debug('recipient {} balance after: {}'.format(recipient, recipient_balance))
+ sender_balance = balance(
+ settings.get('CONN'),
+ settings.get('SENDER_ADDRESS'),
+ 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:
logg.critical('VM revert for {}. Wish I could tell you more'.format(tx_hash_hex))
sys.exit(1)
@@ -128,7 +153,7 @@ def main():
print(o['params'][0])
else:
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())
diff --git a/chainlib/eth/settings.py b/chainlib/eth/settings.py
@@ -1,22 +1,31 @@
# external imports
from chainlib.settings import process_settings as base_process_settings
+from hexathon import add_0x
# local imports
import chainlib.eth.cli
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)
try:
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:
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('RPC_ID_GENERATOR', rpc.id_generator)
+ settings.set('RPC_SEND', config.true('_RPC_SEND'))
return settings
@@ -32,19 +41,11 @@ def process_settings_wallet(settings, config):
if wallet.get_signer_address() == None and recipient != None:
recipient = wallet.from_address(recipient)
- settings.set('RECIPIENT', recipient)
+ settings.set('WALLET', wallet)
+ settings.set('RECIPIENT', add_0x(recipient))
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):
settings = base_process_settings(settings, config)
settings = process_settings_wallet(settings, config)