2021-02-08 22:39:50 +01:00
|
|
|
#!/usr/bin/python
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import logging
|
|
|
|
import uuid
|
|
|
|
import json
|
2021-03-29 15:27:53 +02:00
|
|
|
import argparse
|
2021-02-08 22:39:50 +01:00
|
|
|
|
2021-03-29 15:27:53 +02:00
|
|
|
# external imports
|
2021-02-08 22:39:50 +01:00
|
|
|
import redis
|
2021-03-29 15:27:53 +02:00
|
|
|
from xdg.BaseDirectory import xdg_config_home
|
2021-07-23 05:35:24 +02:00
|
|
|
from chainlib.chain import ChainSpec
|
2021-03-29 15:27:53 +02:00
|
|
|
|
|
|
|
# local imports
|
2021-07-23 05:35:24 +02:00
|
|
|
import cic_eth.cli
|
2021-03-29 15:27:53 +02:00
|
|
|
from cic_eth.api import Api
|
2021-02-08 22:39:50 +01:00
|
|
|
|
|
|
|
logging.basicConfig(level=logging.WARNING)
|
2021-07-23 06:34:18 +02:00
|
|
|
logg = logging.getLogger()
|
2021-02-08 22:39:50 +01:00
|
|
|
|
2021-07-23 05:35:24 +02:00
|
|
|
arg_flags = cic_eth.cli.argflag_std_base
|
|
|
|
local_arg_flags = cic_eth.cli.argflag_local_taskcallback
|
|
|
|
argparser = cic_eth.cli.ArgumentParser(arg_flags)
|
2021-02-08 22:39:50 +01:00
|
|
|
argparser.add_argument('--no-register', dest='no_register', action='store_true', help='Do not register new account in on-chain accounts index')
|
2021-07-23 05:35:24 +02:00
|
|
|
argparser.process_local_flags(local_arg_flags)
|
2021-02-08 22:39:50 +01:00
|
|
|
args = argparser.parse_args()
|
|
|
|
|
2021-07-23 05:35:24 +02:00
|
|
|
extra_args = {
|
|
|
|
'no_register': None,
|
2021-02-08 22:39:50 +01:00
|
|
|
}
|
2021-07-23 05:35:24 +02:00
|
|
|
config = cic_eth.cli.Config.from_args(args, arg_flags, local_arg_flags, extra_args=extra_args)
|
2021-02-08 22:39:50 +01:00
|
|
|
|
2021-07-23 05:35:24 +02:00
|
|
|
celery_app = cic_eth.cli.CeleryApp.from_config(config)
|
2021-02-08 22:39:50 +01:00
|
|
|
|
2021-02-10 08:03:11 +01:00
|
|
|
def main():
|
|
|
|
redis_host = config.get('REDIS_HOST')
|
|
|
|
redis_port = config.get('REDIS_PORT')
|
|
|
|
redis_db = config.get('REDIS_DB')
|
|
|
|
redis_channel = str(uuid.uuid4())
|
|
|
|
r = redis.Redis(redis_host, redis_port, redis_db)
|
2021-02-08 22:39:50 +01:00
|
|
|
|
2021-02-10 08:03:11 +01:00
|
|
|
ps = r.pubsub()
|
|
|
|
ps.subscribe(redis_channel)
|
|
|
|
ps.get_message()
|
2021-02-08 22:39:50 +01:00
|
|
|
|
2021-02-10 08:03:11 +01:00
|
|
|
api = Api(
|
2021-07-23 05:35:24 +02:00
|
|
|
config.get('CHAIN_SPEC'),
|
|
|
|
queue=config.get('CELERY_QUEUE'),
|
|
|
|
callback_param='{}:{}:{}:{}'.format(config.get('_REDIS_HOST_CALLBACK'), config.get('_REDIS_PORT_CALLBACK'), config.get('REDIS_DB'), redis_channel),
|
2021-02-10 08:03:11 +01:00
|
|
|
callback_task='cic_eth.callbacks.redis.redis',
|
2021-07-23 05:35:24 +02:00
|
|
|
callback_queue=config.get('CELERY_QUEUE'),
|
2021-02-10 08:03:11 +01:00
|
|
|
)
|
|
|
|
|
2021-07-23 05:35:24 +02:00
|
|
|
register = not config.get('_NO_REGISTER')
|
2021-02-10 08:03:11 +01:00
|
|
|
logg.debug('register {}'.format(register))
|
|
|
|
t = api.create_account(register=register)
|
|
|
|
|
|
|
|
ps.get_message()
|
2021-07-16 15:21:07 +02:00
|
|
|
try:
|
2021-07-23 05:35:24 +02:00
|
|
|
o = ps.get_message(timeout=config.get('REDIS_TIMEOUT'))
|
2021-07-16 15:21:07 +02:00
|
|
|
except TimeoutError as e:
|
|
|
|
sys.stderr.write('got no new address from cic-eth before timeout: {}\n'.format(e))
|
|
|
|
sys.exit(1)
|
|
|
|
ps.unsubscribe()
|
2021-02-21 16:41:37 +01:00
|
|
|
m = json.loads(o['data'])
|
|
|
|
print(m['result'])
|
2021-02-10 08:03:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|