From 355f8d86f2083518ae191282950de41e33ac82d5 Mon Sep 17 00:00:00 2001 From: PhilipWafula Date: Thu, 7 Oct 2021 16:51:05 +0300 Subject: [PATCH] Minor wallet address related changes --- apps/cic-ussd/cic_ussd/account/balance.py | 2 +- apps/cic-ussd/cic_ussd/account/statement.py | 2 +- apps/cic-ussd/cic_ussd/processor/menu.py | 2 +- apps/cic-ussd/cic_ussd/tasks/callback_handler.py | 2 ++ apps/cic-ussd/cic_ussd/tasks/processor.py | 6 +----- apps/cic-ussd/tests/fixtures/account.py | 12 ++++++------ apps/cic-ussd/tests/fixtures/transaction.py | 14 +++++++------- 7 files changed, 19 insertions(+), 21 deletions(-) diff --git a/apps/cic-ussd/cic_ussd/account/balance.py b/apps/cic-ussd/cic_ussd/account/balance.py index e8563a9f..838f8bbb 100644 --- a/apps/cic-ussd/cic_ussd/account/balance.py +++ b/apps/cic-ussd/cic_ussd/account/balance.py @@ -101,7 +101,7 @@ def get_cached_available_balance(blockchain_address: str) -> float: :return: Operational balance of an account. :rtype: float """ - identifier = bytes.fromhex(blockchain_address[2:]) + identifier = bytes.fromhex(blockchain_address) key = cache_data_key(identifier, salt=':cic.balances') cached_balances = get_cached_data(key=key) if cached_balances: diff --git a/apps/cic-ussd/cic_ussd/account/statement.py b/apps/cic-ussd/cic_ussd/account/statement.py index 94cde296..584f526c 100644 --- a/apps/cic-ussd/cic_ussd/account/statement.py +++ b/apps/cic-ussd/cic_ussd/account/statement.py @@ -86,7 +86,7 @@ def query_statement(blockchain_address: str, limit: int = 9): :param limit: Number of transactions to be returned. :type limit: int """ - logg.debug(f'retrieving balance for address: {blockchain_address}') + logg.debug(f'retrieving statement for address: {blockchain_address}') chain_str = Chain.spec.__str__() cic_eth_api = Api( chain_str=chain_str, diff --git a/apps/cic-ussd/cic_ussd/processor/menu.py b/apps/cic-ussd/cic_ussd/processor/menu.py index 042f8680..568409c8 100644 --- a/apps/cic-ussd/cic_ussd/processor/menu.py +++ b/apps/cic-ussd/cic_ussd/processor/menu.py @@ -37,7 +37,7 @@ class MenuProcessor: def __init__(self, account: Account, display_key: str, menu_name: str, session: Session, ussd_session: dict): self.account = account self.display_key = display_key - self.identifier = bytes.fromhex(self.account.blockchain_address[2:]) + self.identifier = bytes.fromhex(self.account.blockchain_address) self.menu_name = menu_name self.session = session self.ussd_session = ussd_session diff --git a/apps/cic-ussd/cic_ussd/tasks/callback_handler.py b/apps/cic-ussd/cic_ussd/tasks/callback_handler.py index 350a4e73..30bce11f 100644 --- a/apps/cic-ussd/cic_ussd/tasks/callback_handler.py +++ b/apps/cic-ussd/cic_ussd/tasks/callback_handler.py @@ -113,8 +113,10 @@ def statement_callback(self, result, param: str, status_code: int): for transaction in statement_transactions: recipient_transaction, sender_transaction = transaction_actors(transaction) if recipient_transaction.get('blockchain_address') == param: + recipient_transaction['alt_blockchain_address'] = sender_transaction.get('blockchain_address') generate(param, queue, recipient_transaction) if sender_transaction.get('blockchain_address') == param: + sender_transaction['alt_blockchain_address'] = recipient_transaction.get('blockchain_address') generate(param, queue, sender_transaction) diff --git a/apps/cic-ussd/cic_ussd/tasks/processor.py b/apps/cic-ussd/cic_ussd/tasks/processor.py index 1b014b63..04440ee4 100644 --- a/apps/cic-ussd/cic_ussd/tasks/processor.py +++ b/apps/cic-ussd/cic_ussd/tasks/processor.py @@ -23,17 +23,13 @@ logg = logging.getLogger(__file__) def generate_statement(self, querying_party: str, transaction: dict): """""" queue = self.request.delivery_info.get('routing_key') - - s_preferences = celery.signature( - 'cic_ussd.tasks.metadata.query_preferences_metadata', [querying_party], queue=queue - ) s_parse_transaction = celery.signature( 'cic_ussd.tasks.processor.parse_transaction', [transaction], queue=queue ) s_cache_statement = celery.signature( 'cic_ussd.tasks.processor.cache_statement', [querying_party], queue=queue ) - celery.chain(s_preferences, s_parse_transaction, s_cache_statement).apply_async() + celery.chain(s_parse_transaction, s_cache_statement).apply_async() @celery_app.task diff --git a/apps/cic-ussd/tests/fixtures/account.py b/apps/cic-ussd/tests/fixtures/account.py index e2703877..48034a03 100644 --- a/apps/cic-ussd/tests/fixtures/account.py +++ b/apps/cic-ussd/tests/fixtures/account.py @@ -54,7 +54,7 @@ def cache_account_creation_data(init_cache, account_creation_data): @pytest.fixture(scope='function') def cache_balances(activated_account, balances, init_cache): - identifier = bytes.fromhex(strip_0x(activated_account.blockchain_address)) + identifier = bytes.fromhex(activated_account.blockchain_address) balances = json.dumps(balances[0]) key = cache_data_key(identifier, ':cic.balances') cache_data(key, balances) @@ -70,7 +70,7 @@ def cache_default_token_data(default_token_data, init_cache, load_chain_spec): @pytest.fixture(scope='function') def cache_person_metadata(activated_account, init_cache, person_metadata): - identifier = bytes.fromhex(strip_0x(activated_account.blockchain_address)) + identifier = bytes.fromhex(activated_account.blockchain_address) person = json.dumps(person_metadata) key = cache_data_key(identifier, ':cic.person') cache_data(key, person) @@ -78,7 +78,7 @@ def cache_person_metadata(activated_account, init_cache, person_metadata): @pytest.fixture(scope='function') def cache_preferences(activated_account, init_cache, preferences): - identifier = bytes.fromhex(strip_0x(activated_account.blockchain_address)) + identifier = bytes.fromhex(activated_account.blockchain_address) preferences = json.dumps(preferences) key = cache_data_key(identifier, ':cic.preferences') cache_data(key, preferences) @@ -86,10 +86,10 @@ def cache_preferences(activated_account, init_cache, preferences): @pytest.fixture(scope='function') def cache_statement(activated_account, init_cache, statement): - identifier = bytes.fromhex(strip_0x(activated_account.blockchain_address)) - preferences = json.dumps(statement) + identifier = bytes.fromhex(activated_account.blockchain_address) + statement = json.dumps(statement) key = cache_data_key(identifier, ':cic.statement') - cache_data(key, preferences) + cache_data(key, statement) @pytest.fixture(scope='function') diff --git a/apps/cic-ussd/tests/fixtures/transaction.py b/apps/cic-ussd/tests/fixtures/transaction.py index 78953da4..dbdfe901 100644 --- a/apps/cic-ussd/tests/fixtures/transaction.py +++ b/apps/cic-ussd/tests/fixtures/transaction.py @@ -7,6 +7,7 @@ import pytest # local import from cic_ussd.account.balance import get_cached_available_balance + # tests imports @@ -103,8 +104,8 @@ def transactions_list(activated_account, valid_recipient): 'destination_token': '0x0000000000000000000000000000000000000000', 'block_number': 80, 'tx_index': 0, - 'sender': '0x367cB0F65137b0A845c1DB4B7Ca47D3DEF32dDe8', - 'recipient': '0x103d1ed6e370dBa6267045c70d4999384c18a04A', + 'sender': '367cB0F65137b0A845c1DB4B7Ca47D3DEF32dDe8', + 'recipient': '103d1ed6e370dBa6267045c70d4999384c18a04A', 'from_value': 0, 'to_value': 0, 'date_created': '2021-07-14T14:13:46.036198', @@ -122,8 +123,8 @@ def transactions_list(activated_account, valid_recipient): 'destination_token': '0x0000000000000000000000000000000000000000', 'block_number': 78, 'tx_index': 0, - 'sender': '0xb41BfEE260693A473254D62b81aE1ADCC9E51AFb', - 'recipient': '0x367cB0F65137b0A845c1DB4B7Ca47D3DEF32dDe8', + 'sender': 'b41BfEE260693A473254D62b81aE1ADCC9E51AFb', + 'recipient': '367cB0F65137b0A845c1DB4B7Ca47D3DEF32dDe8', 'from_value': 1800000000000000, 'to_value': 1800000000000000, 'date_created': '2021-07-14T14:13:35.839638', @@ -142,8 +143,8 @@ def transactions_list(activated_account, valid_recipient): 'destination_token': '0x0000000000000000000000000000000000000000', 'block_number': 79, 'tx_index': 0, - 'sender': '0x367cB0F65137b0A845c1DB4B7Ca47D3DEF32dDe8', - 'recipient': '0x103d1ed6e370dBa6267045c70d4999384c18a04A', + 'sender': '367cB0F65137b0A845c1DB4B7Ca47D3DEF32dDe8', + 'recipient': '103d1ed6e370dBa6267045c70d4999384c18a04A', 'from_value': 0, 'to_value': 0, 'date_created': '2021-07-14T14:13:35.638355', @@ -152,4 +153,3 @@ def transactions_list(activated_account, valid_recipient): 'timestamp': 1626272015, 'hash': '0x32ca3dd3bef06463b452f4d32f5f563d083cb4759219eed90f3d2a9c1791c5fc'} ] -