From dceae4e5d85c77e03b5e1d07d665fc477e3fb2ab Mon Sep 17 00:00:00 2001 From: Louis Holbrook Date: Wed, 22 Dec 2021 18:25:29 +0000 Subject: [PATCH] bug: Normalize token addresses in db for erc20 operations --- apps/cic-eth/cic_eth/api/api_task.py | 2 +- apps/cic-eth/cic_eth/eth/erc20.py | 18 ++++++++++++------ apps/cic-eth/cic_eth/queue/balance.py | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/apps/cic-eth/cic_eth/api/api_task.py b/apps/cic-eth/cic_eth/api/api_task.py index bee04223..346ab03b 100644 --- a/apps/cic-eth/cic_eth/api/api_task.py +++ b/apps/cic-eth/cic_eth/api/api_task.py @@ -515,7 +515,7 @@ class Api(ApiBase): :param password: Password to encode the password with in the backend (careful, you will have to remember it) :type password: str :param register: Register the new account in accounts index backend - :type password: bool + :type register: bool :returns: uuid of root task :rtype: celery.Task """ diff --git a/apps/cic-eth/cic_eth/eth/erc20.py b/apps/cic-eth/cic_eth/eth/erc20.py index 4fbe2e57..40e2e0e8 100644 --- a/apps/cic-eth/cic_eth/eth/erc20.py +++ b/apps/cic-eth/cic_eth/eth/erc20.py @@ -382,6 +382,8 @@ def cache_transfer_data( sender_address = tx_normalize.wallet_address(tx['from']) recipient_address = tx_normalize.wallet_address(tx_data[0]) token_value = tx_data[1] + source_token_address = tx_normalize.executable_address(tx['to']) + destination_token_address = source_token_address session = SessionBase.create_session() @@ -389,8 +391,8 @@ def cache_transfer_data( 'hash': tx_hash_hex, 'from': sender_address, 'to': recipient_address, - 'source_token': tx['to'], - 'destination_token': tx['to'], + 'source_token': source_token_address, + 'destination_token': destination_token_address, 'from_value': token_value, 'to_value': token_value, } @@ -422,14 +424,16 @@ def cache_transfer_from_data( spender_address = tx_data[0] recipient_address = tx_data[1] token_value = tx_data[2] + source_token_address = tx_normalize.executable_address(tx['to']) + destination_token_address = source_token_address session = SessionBase.create_session() tx_dict = { 'hash': tx_hash_hex, 'from': tx['from'], 'to': recipient_address, - 'source_token': tx['to'], - 'destination_token': tx['to'], + 'source_token': source_token_address, + 'destination_token': destination_token_address, 'from_value': token_value, 'to_value': token_value, } @@ -461,14 +465,16 @@ def cache_approve_data( sender_address = tx_normalize.wallet_address(tx['from']) recipient_address = tx_normalize.wallet_address(tx_data[0]) token_value = tx_data[1] + source_token_address = tx_normalize.executable_address(tx['to']) + destination_token_address = source_token_address session = SessionBase.create_session() tx_dict = { 'hash': tx_hash_hex, 'from': sender_address, 'to': recipient_address, - 'source_token': tx['to'], - 'destination_token': tx['to'], + 'source_token': source_token_address, + 'destination_token': destination_token_address, 'from_value': token_value, 'to_value': token_value, } diff --git a/apps/cic-eth/cic_eth/queue/balance.py b/apps/cic-eth/cic_eth/queue/balance.py index f2f87fb5..8c48ab91 100644 --- a/apps/cic-eth/cic_eth/queue/balance.py +++ b/apps/cic-eth/cic_eth/queue/balance.py @@ -72,7 +72,7 @@ def __balance_incoming_compatible(token_address, receiver_address): status_compare = dead() q = q.filter(Otx.status.op('&')(status_compare)==0) # TODO: this can change the result for the recipient if tx is later obsoleted and resubmission is delayed. - q = q.filter(Otx.status.op('&')(StatusBits.IN_NETWORK)==StatusBits.IN_NETWORK) + #q = q.filter(Otx.status.op('&')(StatusBits.IN_NETWORK)==StatusBits.IN_NETWORK) q = q.filter(TxCache.destination_token_address==token_address) delta = 0 for r in q.all():