Compare commits

...

5 Commits

11 changed files with 132 additions and 104 deletions

View File

@ -26,6 +26,7 @@ from chainlib.chain import ChainSpec
from chainqueue.db.models.otx import Otx from chainqueue.db.models.otx import Otx
from cic_eth_registry.error import UnknownContractError from cic_eth_registry.error import UnknownContractError
from cic_eth_registry.erc20 import ERC20Token from cic_eth_registry.erc20 import ERC20Token
from cic_eth.eth.util import MAXIMUM_FEE_UNITS
from hexathon import add_0x from hexathon import add_0x
import liveness.linux import liveness.linux
@ -232,6 +233,7 @@ def main():
if config.get('ETH_MIN_FEE_PRICE'): if config.get('ETH_MIN_FEE_PRICE'):
BaseTask.min_fee_price = int(config.get('ETH_MIN_FEE_PRICE')) BaseTask.min_fee_price = int(config.get('ETH_MIN_FEE_PRICE'))
CriticalWeb3Task.safe_gas_threshold_amount *= BaseTask.min_fee_price CriticalWeb3Task.safe_gas_threshold_amount *= BaseTask.min_fee_price
CriticalWeb3Task.safe_gas_refill_amount = CriticalWeb3Task.safe_gas_refill_amount + MAXIMUM_FEE_UNITS
CriticalWeb3Task.safe_gas_refill_amount *= BaseTask.min_fee_price CriticalWeb3Task.safe_gas_refill_amount *= BaseTask.min_fee_price
CriticalWeb3Task.safe_gas_gifter_balance *= BaseTask.min_fee_price CriticalWeb3Task.safe_gas_gifter_balance *= BaseTask.min_fee_price

View File

@ -12,4 +12,4 @@ erc20-faucet~=0.3.2
erc20-transfer-authorization~=0.3.6 erc20-transfer-authorization~=0.3.6
sarafu-faucet~=0.0.7 sarafu-faucet~=0.0.7
moolb~=0.2.0 moolb~=0.2.0
okota~=0.2.5 okota~=0.2.6

View File

@ -66,14 +66,15 @@ def parse_statement_transactions(statement: list):
:rtype: :rtype:
""" """
parsed_transactions = [] parsed_transactions = []
statement.sort(key=lambda d: d['timestamp'], reverse=True)
for transaction in statement: for transaction in statement:
action_tag = transaction.get('action_tag') action_tag = transaction.get('action_tag')
decimals = transaction.get('token_decimals') decimals = transaction.get('token_decimals')
amount = from_wei(decimals, transaction.get('token_value')) amount = from_wei(decimals, transaction.get('token_value'))
direction_tag = transaction.get('direction_tag') direction_tag = transaction.get('direction_tag')
token_symbol = transaction.get('token_symbol') token_symbol = transaction.get('token_symbol')
metadata_id = transaction.get('metadata_id') metadata_id = transaction.get('alt_metadata_id')
timestamp = datetime.datetime.now().strftime('%d/%m/%y, %H:%M') timestamp = transaction.get('timestamp')
transaction_repr = f'{action_tag} {amount} {token_symbol} {direction_tag} {metadata_id} {timestamp}' transaction_repr = f'{action_tag} {amount} {token_symbol} {direction_tag} {metadata_id} {timestamp}'
parsed_transactions.append(transaction_repr) parsed_transactions.append(transaction_repr)
return parsed_transactions return parsed_transactions

View File

@ -265,8 +265,9 @@ def process_token_data(blockchain_address: str, token_symbol: str):
query_token_metadata(identifier=identifier) query_token_metadata(identifier=identifier)
token_info = query_token_info(identifier=identifier) token_info = query_token_info(identifier=identifier)
hashed_token_info = hashed_token_proof(token_proof=token_info) hashed_token_info = hashed_token_proof(token_proof=token_info)
hashed_token_symbol = hashed_token_proof(token_symbol)
query_token_data(blockchain_address=blockchain_address, query_token_data(blockchain_address=blockchain_address,
hashed_proofs=[hashed_token_info], hashed_proofs=[[hashed_token_info, hashed_token_symbol]],
token_symbols=[token_symbol]) token_symbols=[token_symbol])

View File

@ -2,7 +2,7 @@
import json import json
import logging import logging
from datetime import timedelta from datetime import datetime, timedelta
# external imports # external imports
import celery import celery
@ -143,9 +143,11 @@ def statement_callback(self, result, param: str, status_code: int):
recipient_transaction, sender_transaction = transaction_actors(transaction) recipient_transaction, sender_transaction = transaction_actors(transaction)
if recipient_transaction.get('blockchain_address') == param: if recipient_transaction.get('blockchain_address') == param:
recipient_transaction['alt_blockchain_address'] = sender_transaction.get('blockchain_address') recipient_transaction['alt_blockchain_address'] = sender_transaction.get('blockchain_address')
recipient_transaction['timestamp'] = datetime.utcfromtimestamp(transaction.get('timestamp')).strftime('%d/%m/%y, %H:%M')
generate(param, queue, recipient_transaction) generate(param, queue, recipient_transaction)
if sender_transaction.get('blockchain_address') == param: if sender_transaction.get('blockchain_address') == param:
sender_transaction['alt_blockchain_address'] = recipient_transaction.get('blockchain_address') sender_transaction['alt_blockchain_address'] = recipient_transaction.get('blockchain_address')
sender_transaction['timestamp'] = datetime.utcfromtimestamp(transaction.get('timestamp')).strftime('%d/%m/%y, %H:%M')
generate(param, queue, sender_transaction) generate(param, queue, sender_transaction)
@ -231,6 +233,10 @@ def transaction_callback(result: dict, param: str, status_code: int):
if status_code != 0: if status_code != 0:
raise ValueError(f'Unexpected status code: {status_code}.') raise ValueError(f'Unexpected status code: {status_code}.')
print(f'THE RETURNING TRANSACTION IS: {result}')
print(f'STATUS CODE: {status_code}')
print(f'WITH PARAM: {param}')
chain_str = Chain.spec.__str__() chain_str = Chain.spec.__str__()
destination_token_symbol = result.get('destination_token_symbol') destination_token_symbol = result.get('destination_token_symbol')
destination_token_value = result.get('destination_token_value') destination_token_value = result.get('destination_token_value')

View File

@ -1,4 +1,5 @@
# standard imports # standard imports
import datetime
import json import json
# external imports # external imports
@ -119,8 +120,11 @@ def test_statement_callback(activated_account, mocker, transactions_list):
[transactions_list, activated_account.blockchain_address, status_code]) [transactions_list, activated_account.blockchain_address, status_code])
s_statement_callback.apply_async().get() s_statement_callback.apply_async().get()
statement_transactions = filter_statement_transactions(transactions_list) statement_transactions = filter_statement_transactions(transactions_list)
timestamp = transactions_list[0].get('timestamp')
timestamp = datetime.datetime.utcfromtimestamp(timestamp).strftime('%d/%m/%y, %H:%M')
recipient_transaction, sender_transaction = transaction_actors(statement_transactions[0]) recipient_transaction, sender_transaction = transaction_actors(statement_transactions[0])
sender_transaction['alt_blockchain_address'] = recipient_transaction.get('blockchain_address') sender_transaction['alt_blockchain_address'] = recipient_transaction.get('blockchain_address')
sender_transaction['timestamp'] = timestamp
mock_statement_generate.assert_called_with( mock_statement_generate.assert_called_with(
(activated_account.blockchain_address, sender_transaction), {}, queue='cic-ussd') (activated_account.blockchain_address, sender_transaction), {}, queue='cic-ussd')

View File

@ -1,6 +1,5 @@
# standard import # standard import
import random from datetime import datetime
# external import # external import
import pytest import pytest
@ -46,6 +45,7 @@ def statement(activated_account):
'direction_tag': 'To', 'direction_tag': 'To',
'metadata_id': activated_account.standard_metadata_id(), 'metadata_id': activated_account.standard_metadata_id(),
'phone_number': activated_account.phone_number, 'phone_number': activated_account.phone_number,
'timestamp': datetime.now().strftime('%d/%m/%y, %H:%M')
} }
] ]

View File

@ -3,7 +3,7 @@
"trigger": "scan_data", "trigger": "scan_data",
"source": "first_transaction_set", "source": "first_transaction_set",
"dest": "middle_transaction_set", "dest": "middle_transaction_set",
"conditions": "cic_ussd.state_machine.logic.menu.menu_one_selected" "conditions": "cic_ussd.state_machine.logic.menu.menu_eleven_selected"
}, },
{ {
"trigger": "scan_data", "trigger": "scan_data",
@ -20,13 +20,13 @@
"trigger": "scan_data", "trigger": "scan_data",
"source": "middle_transaction_set", "source": "middle_transaction_set",
"dest": "last_transaction_set", "dest": "last_transaction_set",
"conditions": "cic_ussd.state_machine.logic.menu.menu_one_selected" "conditions": "cic_ussd.state_machine.logic.menu.menu_eleven_selected"
}, },
{ {
"trigger": "scan_data", "trigger": "scan_data",
"source": "middle_transaction_set", "source": "middle_transaction_set",
"dest": "first_transaction_set", "dest": "first_transaction_set",
"conditions": "cic_ussd.state_machine.logic.menu.menu_two_selected" "conditions": "cic_ussd.state_machine.logic.menu.menu_twenty_two_selected"
}, },
{ {
"trigger": "scan_data", "trigger": "scan_data",
@ -43,7 +43,7 @@
"trigger": "scan_data", "trigger": "scan_data",
"source": "last_transaction_set", "source": "last_transaction_set",
"dest": "middle_transaction_set", "dest": "middle_transaction_set",
"conditions": "cic_ussd.state_machine.logic.menu.menu_two_selected" "conditions": "cic_ussd.state_machine.logic.menu.menu_twenty_two_selected"
}, },
{ {
"trigger": "scan_data", "trigger": "scan_data",

View File

@ -6,6 +6,13 @@
"after": "cic_ussd.state_machine.logic.account.process_account_creation", "after": "cic_ussd.state_machine.logic.account.process_account_creation",
"conditions": "cic_ussd.state_machine.logic.language.is_valid_language_selection" "conditions": "cic_ussd.state_machine.logic.language.is_valid_language_selection"
}, },
{
"trigger": "scan_data",
"source": "initial_language_selection",
"dest": "exit",
"conditions": "cic_ussd.state_machine.logic.menu.menu_zero_zero_selected",
"unless":"cic_ussd.state_machine.logic.language.is_valid_language_selection"
},
{ {
"trigger": "scan_data", "trigger": "scan_data",
"source": "initial_language_selection", "source": "initial_language_selection",
@ -16,15 +23,20 @@
{ {
"trigger": "scan_data", "trigger": "scan_data",
"source": "initial_language_selection", "source": "initial_language_selection",
"dest": "exit", "dest": "exit_invalid_menu_option"
"conditions": "cic_ussd.state_machine.logic.menu.menu_zero_zero_selected",
"unless":"cic_ussd.state_machine.logic.language.is_valid_language_selection"
}, },
{ {
"trigger": "scan_data", "trigger": "scan_data",
"source": "initial_middle_language_set", "source": "initial_middle_language_set",
"dest": "initial_language_selection", "dest": "account_creation_prompt",
"conditions": "cic_ussd.state_machine.logic.menu.menu_twenty_two_selected", "after": "cic_ussd.state_machine.logic.account.process_account_creation",
"conditions": "cic_ussd.state_machine.logic.language.is_valid_language_selection"
},
{
"trigger": "scan_data",
"source": "initial_middle_language_set",
"dest": "exit",
"conditions": "cic_ussd.state_machine.logic.menu.menu_zero_zero_selected",
"unless": "cic_ussd.state_machine.logic.language.is_valid_language_selection" "unless": "cic_ussd.state_machine.logic.language.is_valid_language_selection"
}, },
{ {
@ -37,6 +49,25 @@
{ {
"trigger": "scan_data", "trigger": "scan_data",
"source": "initial_middle_language_set", "source": "initial_middle_language_set",
"dest": "initial_language_selection",
"conditions": "cic_ussd.state_machine.logic.menu.menu_twenty_two_selected",
"unless": "cic_ussd.state_machine.logic.language.is_valid_language_selection"
},
{
"trigger": "scan_data",
"source": "initial_middle_language_set",
"dest": "exit_invalid_menu_option"
},
{
"trigger": "scan_data",
"source": "initial_last_language_set",
"dest": "account_creation_prompt",
"after": "cic_ussd.state_machine.logic.account.process_account_creation",
"conditions": "cic_ussd.state_machine.logic.language.is_valid_language_selection"
},
{
"trigger": "scan_data",
"source": "initial_last_language_set",
"dest": "exit", "dest": "exit",
"conditions": "cic_ussd.state_machine.logic.menu.menu_zero_zero_selected", "conditions": "cic_ussd.state_machine.logic.menu.menu_zero_zero_selected",
"unless": "cic_ussd.state_machine.logic.language.is_valid_language_selection" "unless": "cic_ussd.state_machine.logic.language.is_valid_language_selection"
@ -51,58 +82,46 @@
{ {
"trigger": "scan_data", "trigger": "scan_data",
"source": "initial_last_language_set", "source": "initial_last_language_set",
"dest": "exit",
"conditions": "cic_ussd.state_machine.logic.menu.menu_zero_zero_selected",
"unless": "cic_ussd.state_machine.logic.language.is_valid_language_selection"
},
{
"trigger": "scan_data",
"source": "initial_middle_language_set",
"dest": "exit",
"conditions": "cic_ussd.state_machine.logic.menu.menu_zero_zero_selected",
"unless": "cic_ussd.state_machine.logic.language.is_valid_language_selection"
},
{
"trigger": "scan_data",
"source": "initial_language_selection",
"dest": "exit_invalid_menu_option"
},
{
"trigger": "scan_data",
"source": "middle_language_set",
"dest": "exit_invalid_menu_option"
},
{
"trigger": "scan_data",
"source": "last_language_set",
"dest": "exit_invalid_menu_option" "dest": "exit_invalid_menu_option"
}, },
{ {
"trigger": "scan_data", "trigger": "scan_data",
"source": "select_preferred_language", "source": "select_preferred_language",
"dest": "exit", "dest": "account_creation_prompt",
"after": "cic_ussd.state_machine.logic.language.change_preferred_language", "after": "cic_ussd.state_machine.logic.account.process_account_creation",
"conditions": "cic_ussd.state_machine.logic.language.is_valid_language_selection" "conditions": "cic_ussd.state_machine.logic.language.is_valid_language_selection"
}, },
{ {
"trigger": "scan_data", "trigger": "scan_data",
"source": "select_preferred_language", "source": "select_preferred_language",
"dest": "middle_language_set", "dest": "exit",
"conditions": "cic_ussd.state_machine.logic.menu.menu_zero_zero_selected",
"unless":"cic_ussd.state_machine.logic.language.is_valid_language_selection"
},
{
"trigger": "scan_data",
"source": "select_preferred_language",
"dest": "initial_middle_language_set",
"conditions": "cic_ussd.state_machine.logic.menu.menu_eleven_selected", "conditions": "cic_ussd.state_machine.logic.menu.menu_eleven_selected",
"unless": "cic_ussd.state_machine.logic.language.is_valid_language_selection" "unless": "cic_ussd.state_machine.logic.language.is_valid_language_selection"
}, },
{ {
"trigger": "scan_data", "trigger": "scan_data",
"source": "select_preferred_language", "source": "select_preferred_language",
"dest": "exit", "dest": "exit_invalid_menu_option"
"conditions": "cic_ussd.state_machine.logic.menu.menu_zero_zero_selected",
"unless": "cic_ussd.state_machine.logic.language.is_valid_language_selection"
}, },
{ {
"trigger": "scan_data", "trigger": "scan_data",
"source": "middle_language_set", "source": "middle_language_set",
"dest": "select_preferred_language", "dest": "account_creation_prompt",
"conditions": "cic_ussd.state_machine.logic.menu.menu_twenty_two_selected", "after": "cic_ussd.state_machine.logic.account.process_account_creation",
"conditions": "cic_ussd.state_machine.logic.language.is_valid_language_selection"
},
{
"trigger": "scan_data",
"source": "middle_language_set",
"dest": "exit",
"conditions": "cic_ussd.state_machine.logic.menu.menu_zero_zero_selected",
"unless": "cic_ussd.state_machine.logic.language.is_valid_language_selection" "unless": "cic_ussd.state_machine.logic.language.is_valid_language_selection"
}, },
{ {
@ -115,6 +134,25 @@
{ {
"trigger": "scan_data", "trigger": "scan_data",
"source": "middle_language_set", "source": "middle_language_set",
"dest": "select_preferred_langauge",
"conditions": "cic_ussd.state_machine.logic.menu.menu_twenty_two_selected",
"unless": "cic_ussd.state_machine.logic.language.is_valid_language_selection"
},
{
"trigger": "scan_data",
"source": "middle_language_set",
"dest": "exit_invalid_menu_option"
},
{
"trigger": "scan_data",
"source": "last_language_set",
"dest": "account_creation_prompt",
"after": "cic_ussd.state_machine.logic.account.process_account_creation",
"conditions": "cic_ussd.state_machine.logic.language.is_valid_language_selection"
},
{
"trigger": "scan_data",
"source": "last_language_set",
"dest": "exit", "dest": "exit",
"conditions": "cic_ussd.state_machine.logic.menu.menu_zero_zero_selected", "conditions": "cic_ussd.state_machine.logic.menu.menu_zero_zero_selected",
"unless": "cic_ussd.state_machine.logic.language.is_valid_language_selection" "unless": "cic_ussd.state_machine.logic.language.is_valid_language_selection"
@ -126,30 +164,6 @@
"conditions": "cic_ussd.state_machine.logic.menu.menu_twenty_two_selected", "conditions": "cic_ussd.state_machine.logic.menu.menu_twenty_two_selected",
"unless": "cic_ussd.state_machine.logic.language.is_valid_language_selection" "unless": "cic_ussd.state_machine.logic.language.is_valid_language_selection"
}, },
{
"trigger": "scan_data",
"source": "last_language_set",
"dest": "exit",
"conditions": "cic_ussd.state_machine.logic.menu.menu_zero_zero_selected",
"unless": "cic_ussd.state_machine.logic.language.is_valid_language_selection"
},
{
"trigger": "scan_data",
"source": "middle_language_set",
"dest": "exit",
"conditions": "cic_ussd.state_machine.logic.menu.menu_zero_zero_selected",
"unless": "cic_ussd.state_machine.logic.language.is_valid_language_selection"
},
{
"trigger": "scan_data",
"source": "select_preferred_language",
"dest": "exit_invalid_menu_option"
},
{
"trigger": "scan_data",
"source": "middle_language_set",
"dest": "exit_invalid_menu_option"
},
{ {
"trigger": "scan_data", "trigger": "scan_data",
"source": "last_language_set", "source": "last_language_set",

View File

@ -1,16 +1,4 @@
[ [
{
"trigger": "scan_data",
"source": "first_account_tokens_set",
"dest": "middle_account_tokens_set",
"conditions": "cic_ussd.state_machine.logic.menu.menu_eleven_selected"
},
{
"trigger": "scan_data",
"source": "first_account_tokens_set",
"dest": "exit",
"conditions": "cic_ussd.state_machine.logic.menu.menu_zero_zero_selected"
},
{ {
"trigger": "scan_data", "trigger": "scan_data",
"source": "first_account_tokens_set", "source": "first_account_tokens_set",
@ -18,11 +6,36 @@
"conditions": "cic_ussd.state_machine.logic.tokens.is_valid_token_selection", "conditions": "cic_ussd.state_machine.logic.tokens.is_valid_token_selection",
"after": "cic_ussd.state_machine.logic.tokens.process_token_selection" "after": "cic_ussd.state_machine.logic.tokens.process_token_selection"
}, },
{
"trigger": "scan_data",
"source": "first_account_tokens_set",
"dest": "exit",
"conditions": "cic_ussd.state_machine.logic.menu.menu_zero_zero_selected"
},
{
"trigger": "scan_data",
"source": "first_account_tokens_set",
"dest": "middle_account_tokens_set",
"conditions": "cic_ussd.state_machine.logic.menu.menu_eleven_selected"
},
{ {
"trigger": "scan_data", "trigger": "scan_data",
"source": "first_account_tokens_set", "source": "first_account_tokens_set",
"dest": "exit_invalid_menu_option" "dest": "exit_invalid_menu_option"
}, },
{
"trigger": "scan_data",
"source": "middle_account_tokens_set",
"dest": "token_selection_pin_authorization",
"conditions": "cic_ussd.state_machine.logic.tokens.is_valid_token_selection",
"after": "cic_ussd.state_machine.logic.tokens.process_token_selection"
},
{
"trigger": "scan_data",
"source": "middle_account_tokens_set",
"dest": "exit",
"conditions": "cic_ussd.state_machine.logic.menu.menu_zero_zero_selected"
},
{ {
"trigger": "scan_data", "trigger": "scan_data",
"source": "middle_account_tokens_set", "source": "middle_account_tokens_set",
@ -38,20 +51,20 @@
{ {
"trigger": "scan_data", "trigger": "scan_data",
"source": "middle_account_tokens_set", "source": "middle_account_tokens_set",
"dest": "exit", "dest": "exit_invalid_menu_option"
"conditions": "cic_ussd.state_machine.logic.menu.menu_zero_zero_selected"
}, },
{ {
"trigger": "scan_data", "trigger": "scan_data",
"source": "middle_account_tokens_set", "source": "last_account_tokens_set",
"dest": "token_selection_pin_authorization", "dest": "token_selection_pin_authorization",
"conditions": "cic_ussd.state_machine.logic.tokens.is_valid_token_selection", "conditions": "cic_ussd.state_machine.logic.tokens.is_valid_token_selection",
"after": "cic_ussd.state_machine.logic.tokens.process_token_selection" "after": "cic_ussd.state_machine.logic.tokens.process_token_selection"
}, },
{ {
"trigger": "scan_data", "trigger": "scan_data",
"source": "middle_account_tokens_set", "source": "last_account_tokens_set",
"dest": "exit_invalid_menu_option" "dest": "exit",
"conditions": "cic_ussd.state_machine.logic.menu.menu_zero_zero_selected"
}, },
{ {
"trigger": "scan_data", "trigger": "scan_data",
@ -59,19 +72,6 @@
"dest": "middle_account_tokens_set", "dest": "middle_account_tokens_set",
"conditions": "cic_ussd.state_machine.logic.menu.menu_twenty_two_selected" "conditions": "cic_ussd.state_machine.logic.menu.menu_twenty_two_selected"
}, },
{
"trigger": "scan_data",
"source": "last_account_tokens_set",
"dest": "exit",
"conditions": "cic_ussd.state_machine.logic.menu.menu_zero_zero_selected"
},
{
"trigger": "scan_data",
"source": "last_account_tokens_set",
"dest": "token_selection_pin_authorization",
"conditions": "cic_ussd.state_machine.logic.tokens.is_valid_token_selection",
"after": "cic_ussd.state_machine.logic.tokens.process_token_selection"
},
{ {
"trigger": "scan_data", "trigger": "scan_data",
"source": "last_account_tokens_set", "source": "last_account_tokens_set",

View File

@ -9,4 +9,4 @@ erc20-faucet==0.3.2
sarafu-faucet==0.0.7 sarafu-faucet==0.0.7
confini~=0.5.3 confini~=0.5.3
eth-token-index==0.2.4 eth-token-index==0.2.4
okota==0.2.5a1 okota==0.2.6