2021-03-30 18:33:09 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import logging
|
|
|
|
import uuid
|
|
|
|
import json
|
|
|
|
import argparse
|
|
|
|
|
|
|
|
# external imports
|
|
|
|
import redis
|
|
|
|
from xdg.BaseDirectory import xdg_config_home
|
|
|
|
from chainlib.eth.address import to_checksum_address
|
|
|
|
|
|
|
|
# local imports
|
2021-08-17 08:46:51 +02:00
|
|
|
import cic_eth.cli
|
2021-03-30 18:33:09 +02:00
|
|
|
from cic_eth.api import Api
|
|
|
|
|
|
|
|
logging.basicConfig(level=logging.WARNING)
|
|
|
|
logg = logging.getLogger('create_account_script')
|
|
|
|
|
2021-12-22 19:24:05 +01:00
|
|
|
arg_flags = cic_eth.cli.argflag_local_base
|
2021-08-17 08:46:51 +02:00
|
|
|
local_arg_flags = cic_eth.cli.argflag_local_taskcallback
|
|
|
|
argparser = cic_eth.cli.ArgumentParser(arg_flags)
|
|
|
|
argparser.add_argument('--token-symbol', dest='token_symbol', type=str, help='Token symbol')
|
|
|
|
argparser.add_positional('sender', type=str, help='Token transaction sender')
|
|
|
|
argparser.add_positional('recipient', type=str, help='Token transaction recipient')
|
|
|
|
argparser.add_positional('value', type=int, help='Token transaction value')
|
|
|
|
argparser.process_local_flags(local_arg_flags)
|
2021-03-30 18:33:09 +02:00
|
|
|
args = argparser.parse_args()
|
|
|
|
|
2021-08-17 08:46:51 +02:00
|
|
|
extra_args = {
|
|
|
|
'token_symbol': None,
|
|
|
|
'sender': None,
|
|
|
|
'recipient': None,
|
|
|
|
'value': None,
|
2021-03-30 18:33:09 +02:00
|
|
|
}
|
2021-08-17 08:46:51 +02:00
|
|
|
config = cic_eth.cli.Config.from_args(args, arg_flags, local_arg_flags, extra_args=extra_args)
|
|
|
|
|
|
|
|
celery_app = cic_eth.cli.CeleryApp.from_config(config)
|
2021-03-30 18:33:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
redis_channel = str(uuid.uuid4())
|
2021-08-17 08:46:51 +02:00
|
|
|
r = redis.Redis(config.get('REDIS_HOST'), config.get('REDIS_PORT'), config.get('REDIS_DB'))
|
2021-03-30 18:33:09 +02:00
|
|
|
|
|
|
|
ps = r.pubsub()
|
|
|
|
ps.subscribe(redis_channel)
|
|
|
|
ps.get_message()
|
|
|
|
|
|
|
|
api = Api(
|
2021-08-17 08:46:51 +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-03-30 18:33:09 +02:00
|
|
|
callback_task='cic_eth.callbacks.redis.redis',
|
2021-08-17 08:46:51 +02:00
|
|
|
callback_queue=config.get('CELERY_QUEUE')
|
2021-03-30 18:33:09 +02:00
|
|
|
)
|
|
|
|
|
2021-08-17 08:46:51 +02:00
|
|
|
t = api.transfer(config.get('_SENDER'), config.get('_RECIPIENT'), config.get('_VALUE'), config.get('_TOKEN_SYMBOL'))
|
2021-03-30 18:33:09 +02:00
|
|
|
|
|
|
|
ps.get_message()
|
2021-08-17 08:46:51 +02:00
|
|
|
o = ps.get_message(timeout=config.get('REDIS_TIMEOUT'))
|
2021-03-30 18:33:09 +02:00
|
|
|
m = json.loads(o['data'])
|
|
|
|
print(m['result'])
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|