Implement chainlib cli util for resend cli
This commit is contained in:
parent
127a16ac07
commit
0c5c6146d6
@ -5,65 +5,38 @@ import re
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
# third-party imports
|
# third-party imports
|
||||||
import celery
|
|
||||||
import confini
|
|
||||||
from chainlib.chain import ChainSpec
|
from chainlib.chain import ChainSpec
|
||||||
from chainlib.eth.connection import EthHTTPConnection
|
from chainlib.eth.connection import EthHTTPConnection
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
|
import cic_eth.cli
|
||||||
from cic_eth.api.admin import AdminApi
|
from cic_eth.api.admin import AdminApi
|
||||||
|
|
||||||
logging.basicConfig(level=logging.WARNING)
|
logging.basicConfig(level=logging.WARNING)
|
||||||
logg = logging.getLogger()
|
logg = logging.getLogger()
|
||||||
|
|
||||||
logging.getLogger('web3').setLevel(logging.WARNING)
|
arg_flags = cic_eth.cli.argflag_std_base
|
||||||
logging.getLogger('urllib3').setLevel(logging.WARNING)
|
local_arg_flags = cic_eth.cli.argflag_local_taskcallback
|
||||||
|
argparser = cic_eth.cli.ArgumentParser(arg_flags)
|
||||||
default_config_dir = os.environ.get('CONFINI_DIR', '/usr/local/etc/cic')
|
argparser.add_argument('--unlock', action='store_true', help='Unlock account after resend')
|
||||||
|
argparser.add_positional('tx_hash', type=str, help='Transaction hash')
|
||||||
|
argparser.process_local_flags(local_arg_flags)
|
||||||
argparser = argparse.ArgumentParser()
|
extra_args = {
|
||||||
argparser.add_argument('-c', type=str, default=default_config_dir, help='config root to use')
|
'unlock': None,
|
||||||
argparser.add_argument('-p', '--provider', dest='p', default='http://localhost:8545', type=str, help='Web3 provider url (http only)')
|
'tx_hash': None,
|
||||||
argparser.add_argument('-i', '--chain-spec', dest='i', type=str, default='Ethereum:1', help='Chain specification string')
|
}
|
||||||
argparser.add_argument('--unlock', action='store_true', help='Append task to unlock account')
|
|
||||||
argparser.add_argument('--env-prefix', default=os.environ.get('CONFINI_ENV_PREFIX'), dest='env_prefix', type=str, help='environment prefix for variables to overwrite configuration')
|
|
||||||
argparser.add_argument('-v', action='store_true', help='Be verbose')
|
|
||||||
argparser.add_argument('-vv', action='store_true', help='Be more verbose')
|
|
||||||
argparser.add_argument('tx_hash', type=str, help='Transaction hash')
|
|
||||||
args = argparser.parse_args()
|
args = argparser.parse_args()
|
||||||
|
|
||||||
|
config = cic_eth.cli.Config.from_args(args, arg_flags, local_arg_flags, extra_args=extra_args)
|
||||||
|
|
||||||
if args.vv:
|
chain_spec = ChainSpec.from_chain_str(config.get('CHAIN_SPEC'))
|
||||||
logg.setLevel(logging.DEBUG)
|
|
||||||
elif args.v:
|
|
||||||
logg.setLevel(logging.INFO)
|
|
||||||
|
|
||||||
config_dir = os.path.join(args.c)
|
celery_app = cic_eth.cli.CeleryApp.from_config(config)
|
||||||
os.makedirs(config_dir, 0o777, True)
|
|
||||||
config = confini.Config(config_dir, args.env_prefix)
|
|
||||||
config.process()
|
|
||||||
args_override = {
|
|
||||||
'ETH_PROVIDER': getattr(args, 'p'),
|
|
||||||
'CIC_CHAIN_SPEC': getattr(args, 'i'),
|
|
||||||
}
|
|
||||||
|
|
||||||
# override args
|
|
||||||
config.censor('PASSWORD', 'DATABASE')
|
|
||||||
config.censor('PASSWORD', 'SSL')
|
|
||||||
logg.debug('config loaded from {}:\n{}'.format(config_dir, config))
|
|
||||||
config.add(args.tx_hash, '_TX_HASH', True)
|
|
||||||
config.add(args.unlock, '_UNLOCK', True)
|
|
||||||
|
|
||||||
chain_spec = ChainSpec.from_chain_str(args.i)
|
|
||||||
|
|
||||||
rpc = EthHTTPConnection(config.get('ETH_PROVIDER'))
|
|
||||||
|
|
||||||
celery_app = celery.Celery(broker=config.get('CELERY_BROKER_URL'), backend=config.get('CELERY_RESULT_URL'))
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
api = AdminApi(rpc)
|
api = AdminApi(None)
|
||||||
tx_details = api.tx(chain_spec, args.tx_hash)
|
tx_details = api.tx(chain_spec, config.get('_TX_HASH'))
|
||||||
t = api.resend(args.tx_hash, chain_spec, unlock=config.get('_UNLOCK'))
|
t = api.resend(args.tx_hash, chain_spec, unlock=config.get('_UNLOCK'))
|
||||||
print(t.get_leaf())
|
print(t.get_leaf())
|
||||||
|
|
||||||
|
@ -7,12 +7,12 @@ import json
|
|||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
# external imports
|
# external imports
|
||||||
import cic_eth.cli
|
|
||||||
import redis
|
import redis
|
||||||
from xdg.BaseDirectory import xdg_config_home
|
from xdg.BaseDirectory import xdg_config_home
|
||||||
from chainlib.eth.address import to_checksum_address
|
from chainlib.eth.address import to_checksum_address
|
||||||
|
|
||||||
# local imports
|
# local imports
|
||||||
|
import cic_eth.cli
|
||||||
from cic_eth.api import Api
|
from cic_eth.api import Api
|
||||||
|
|
||||||
logging.basicConfig(level=logging.WARNING)
|
logging.basicConfig(level=logging.WARNING)
|
||||||
|
Loading…
Reference in New Issue
Block a user