Add settings module, implement for balance tool

This commit is contained in:
lash 2022-05-12 13:53:33 +00:00
parent 85e5359e7c
commit 05d3357318
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
2 changed files with 21 additions and 16 deletions

View File

@ -14,17 +14,18 @@ from hexathon import (
add_0x, add_0x,
strip_0x, strip_0x,
) )
from chainlib.settings import ChainSettings
# local imports
from chainlib.eth.address import to_checksum_address
from chainlib.eth.connection import EthHTTPConnection
from chainlib.jsonrpc import ( from chainlib.jsonrpc import (
JSONRPCRequest, JSONRPCRequest,
IntSequenceGenerator, IntSequenceGenerator,
) )
from chainlib.chain import ChainSpec
# local imports
from chainlib.eth.address import to_checksum_address
from chainlib.eth.connection import EthHTTPConnection
from chainlib.eth.gas import Gas from chainlib.eth.gas import Gas
from chainlib.eth.gas import balance as gas_balance from chainlib.eth.gas import balance as gas_balance
from chainlib.chain import ChainSpec
from chainlib.eth.runnable.util import decode_for_puny_humans from chainlib.eth.runnable.util import decode_for_puny_humans
from chainlib.eth.address import ( from chainlib.eth.address import (
is_same_address, is_same_address,
@ -69,13 +70,8 @@ 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))
wallet = chainlib.eth.cli.Wallet() settings = ChainSettings()
wallet.from_config(config) settings = settings.process_settings(settings, config)
rpc = chainlib.eth.cli.Rpc(wallet=wallet)
conn = rpc.connect_by_config(config)
chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC'))
value = config.get('_AMOUNT') value = config.get('_AMOUNT')
@ -94,10 +90,9 @@ def balance(address, id_generator):
def main(): def main():
signer = rpc.get_signer() g = Gas(
signer_address = rpc.get_sender_address() settings.get('CHAIN_SPEC'),
signer=settings.get('SIGNER'), gas_oracle=rpc.get_gas_oracle(), nonce_oracle=rpc.get_nonce_oracle())
g = Gas(chain_spec, signer=signer, gas_oracle=rpc.get_gas_oracle(), nonce_oracle=rpc.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):

View File

@ -11,6 +11,7 @@ def process_settings_rpc(settings, config):
try: try:
settings.set('SIGNER', rpc.get_signer()) settings.set('SIGNER', rpc.get_signer())
settings.set('SENDER_ADDRESS', rpc.get_sender_address())
except AttributeError: except AttributeError:
pass pass
@ -35,6 +36,15 @@ def process_settings_wallet(settings, config):
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)