Handles token related callback handling.

This commit is contained in:
PhilipWafula 2021-10-25 21:03:46 +03:00
parent 97b80aaf38
commit 103b7885b1
Signed by untrusted user: mango-habanero
GPG Key ID: B00CE9034DA19FB7
1 changed files with 32 additions and 1 deletions

View File

@ -7,7 +7,6 @@ from datetime import timedelta
import celery
from cic_types.condiments import MetadataPointer
# local imports
from cic_ussd.account.balance import get_balances, calculate_available_balance
from cic_ussd.account.statement import generate
@ -17,6 +16,7 @@ from cic_ussd.db.models.base import SessionBase
from cic_ussd.db.models.account import Account
from cic_ussd.account.statement import filter_statement_transactions
from cic_ussd.account.transaction import transaction_actors
from cic_ussd.account.tokens import collate_token_metadata, process_token_data
from cic_ussd.error import AccountCreationDataNotFound
from cic_ussd.tasks.base import CriticalSQLAlchemyTask
@ -122,6 +122,35 @@ def statement_callback(self, result, param: str, status_code: int):
generate(param, queue, sender_transaction)
@celery_app.task
def token_data_callback(result: dict, param: str, status_code: int):
"""
:param result:
:type result:
:param param:
:type param:
:param status_code:
:type status_code:
:return:
:rtype:
"""
if status_code != 0:
raise ValueError(f'Unexpected status code: {status_code}.')
for key, value in result.items():
token_symbol = result[key].get('symbol')
identifier = token_symbol.encode('utf-8')
token_meta_key = cache_data_key(identifier, MetadataPointer.TOKEN_META_SYMBOL)
token_info_key = cache_data_key(identifier, MetadataPointer.TOKEN_PROOF_SYMBOL)
token_meta = get_cached_data(token_meta_key)
token_info = get_cached_data(token_info_key)
token_data = collate_token_metadata(token_info=token_info, token_metadata=token_meta)
token_data = {**token_data, **result[key]}
token_data_key = cache_data_key(identifier, MetadataPointer.TOKEN_DATA)
cache_data(token_data_key, json.dumps(token_data))
@celery_app.task(bind=True)
def transaction_balances_callback(self, result: list, param: dict, status_code: int):
"""
@ -175,6 +204,8 @@ def transaction_callback(result: dict, param: str, status_code: int):
source_token_symbol = result.get('source_token_symbol')
source_token_value = result.get('source_token_value')
process_token_data(token_symbol=destination_token_symbol)
recipient_metadata = {
"alt_blockchain_address": sender_blockchain_address,
"blockchain_address": recipient_blockchain_address,