Compare commits
3 Commits
lash/remov
...
lash/exter
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cd5305b332
|
||
|
|
2101a23ccb
|
||
|
|
af97b7799f
|
@@ -78,6 +78,8 @@ def main():
|
||||
block_current = int(r, 16)
|
||||
block_offset = block_current + 1
|
||||
|
||||
stat = init_chain_stat(rpc, block_current)
|
||||
|
||||
logg.debug('starting at block {}'.format(block_offset))
|
||||
|
||||
syncers = []
|
||||
|
||||
@@ -3,6 +3,7 @@ import logging
|
||||
import re
|
||||
|
||||
# third-party imports
|
||||
from celery.app.control import Inspect
|
||||
import celery
|
||||
|
||||
# local imports
|
||||
@@ -15,6 +16,29 @@ logg = logging.getLogger()
|
||||
sms_tasks_matcher = r"^(cic_notify.tasks.sms)(\.\w+)?"
|
||||
|
||||
|
||||
re_q = r'^cic-notify'
|
||||
def get_sms_queue_tasks(app, task_prefix='cic_notify.tasks.sms.'):
|
||||
host_queues = []
|
||||
|
||||
i = Inspect(app=app)
|
||||
qs = i.active_queues()
|
||||
for host in qs.keys():
|
||||
for q in qs[host]:
|
||||
if re.match(re_q, q['name']):
|
||||
host_queues.append((host, q['name'],))
|
||||
|
||||
task_prefix_len = len(task_prefix)
|
||||
queue_tasks = []
|
||||
for (host, queue) in host_queues:
|
||||
i = Inspect(app=app, destination=[host])
|
||||
for tasks in i.registered_tasks().values():
|
||||
for task in tasks:
|
||||
if len(task) >= task_prefix_len and task[:task_prefix_len] == task_prefix:
|
||||
queue_tasks.append((queue, task,))
|
||||
|
||||
return queue_tasks
|
||||
|
||||
|
||||
class Api:
|
||||
# TODO: Implement callback strategy
|
||||
def __init__(self, queue='cic-notify'):
|
||||
@@ -22,17 +46,9 @@ class Api:
|
||||
:param queue: The queue on which to execute notification tasks
|
||||
:type queue: str
|
||||
"""
|
||||
registered_tasks = app.tasks
|
||||
self.sms_tasks = []
|
||||
self.sms_tasks = get_sms_queue_tasks(app)
|
||||
logg.debug('sms tasks {}'.format(self.sms_tasks))
|
||||
|
||||
for task in registered_tasks.keys():
|
||||
logg.debug(f'Found: {task} {registered_tasks[task]}')
|
||||
match = re.match(sms_tasks_matcher, task)
|
||||
if match:
|
||||
self.sms_tasks.append(task)
|
||||
|
||||
self.queue = queue
|
||||
logg.info(f'api using queue: {self.queue}')
|
||||
|
||||
def sms(self, message, recipient):
|
||||
"""This function chains all sms tasks in order to send a message, log and persist said data to disk
|
||||
@@ -44,12 +60,17 @@ class Api:
|
||||
:rtype: Celery.Task
|
||||
"""
|
||||
signatures = []
|
||||
for task in self.sms_tasks:
|
||||
signature = celery.signature(task)
|
||||
for q in self.sms_tasks:
|
||||
signature = celery.signature(
|
||||
q[1],
|
||||
[
|
||||
message,
|
||||
recipient,
|
||||
],
|
||||
queue=q[0],
|
||||
)
|
||||
signatures.append(signature)
|
||||
signature_group = celery.group(signatures)
|
||||
result = signature_group.apply_async(
|
||||
args=[message, recipient],
|
||||
queue=self.queue
|
||||
)
|
||||
return result
|
||||
|
||||
t = celery.group(signatures)()
|
||||
|
||||
return t
|
||||
|
||||
76
apps/cic-notify/cic_notify/runnable/send.py
Normal file
76
apps/cic-notify/cic_notify/runnable/send.py
Normal file
@@ -0,0 +1,76 @@
|
||||
# standard imports
|
||||
import sys
|
||||
import os
|
||||
import logging
|
||||
import argparse
|
||||
import tempfile
|
||||
|
||||
# external imports
|
||||
import celery
|
||||
import confini
|
||||
|
||||
# local imports
|
||||
from cic_notify.api import Api
|
||||
|
||||
logging.basicConfig(level=logging.WARNING)
|
||||
logg = logging.getLogger()
|
||||
|
||||
config_dir = os.path.join('/usr/local/etc/cic-notify')
|
||||
|
||||
argparser = argparse.ArgumentParser()
|
||||
argparser.add_argument('-c', type=str, default=config_dir, help='config file')
|
||||
argparser.add_argument('--env-prefix', default=os.environ.get('CONFINI_ENV_PREFIX'), dest='env_prefix', type=str, help='environment prefix for variables to overwrite configuration')
|
||||
argparser.add_argument('-v', action='store_true', help='be verbose')
|
||||
argparser.add_argument('-vv', action='store_true', help='be more verbose')
|
||||
argparser.add_argument('recipient', type=str, help='notification recipient')
|
||||
argparser.add_argument('message', type=str, help='message text')
|
||||
args = argparser.parse_args()
|
||||
|
||||
if args.vv:
|
||||
logging.getLogger().setLevel(logging.DEBUG)
|
||||
elif args.v:
|
||||
logging.getLogger().setLevel(logging.INFO)
|
||||
|
||||
config = confini.Config(args.c, args.env_prefix)
|
||||
config.process()
|
||||
config.censor('PASSWORD', 'DATABASE')
|
||||
config.add(args.recipient, '_RECIPIENT', True)
|
||||
config.add(args.message, '_MESSAGE', True)
|
||||
|
||||
# set up celery
|
||||
app = celery.Celery(__name__)
|
||||
|
||||
broker = config.get('CELERY_BROKER_URL')
|
||||
if broker[:4] == 'file':
|
||||
bq = tempfile.mkdtemp()
|
||||
bp = tempfile.mkdtemp()
|
||||
app.conf.update({
|
||||
'broker_url': broker,
|
||||
'broker_transport_options': {
|
||||
'data_folder_in': bq,
|
||||
'data_folder_out': bq,
|
||||
'data_folder_processed': bp,
|
||||
},
|
||||
},
|
||||
)
|
||||
logg.warning('celery broker dirs queue i/o {} processed {}, will NOT be deleted on shutdown'.format(bq, bp))
|
||||
else:
|
||||
app.conf.update({
|
||||
'broker_url': broker,
|
||||
})
|
||||
|
||||
result = config.get('CELERY_RESULT_URL')
|
||||
if result[:4] == 'file':
|
||||
rq = tempfile.mkdtemp()
|
||||
app.conf.update({
|
||||
'result_backend': 'file://{}'.format(rq),
|
||||
})
|
||||
logg.warning('celery backend store dir {} created, will NOT be deleted on shutdown'.format(rq))
|
||||
else:
|
||||
app.conf.update({
|
||||
'result_backend': result,
|
||||
})
|
||||
|
||||
if __name__ == '__main__':
|
||||
a = Api()
|
||||
t = a.sms(config.get('_RECIPIENT'), config.get('_MESSAGE'))
|
||||
@@ -1 +1 @@
|
||||
cic_base[full_graph]~=0.1.2a46
|
||||
cic_base[full_graph]~=0.1.2a61
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
[metadata]
|
||||
name = cic-notify
|
||||
version= 0.4.0a2
|
||||
version= 0.4.0a3
|
||||
description = CIC notifications service
|
||||
author = Louis Holbrook
|
||||
author_email = dev@holbrook.no
|
||||
@@ -45,3 +45,4 @@ testing =
|
||||
[options.entry_points]
|
||||
console_scripts =
|
||||
cic-notify-tasker = cic_notify.runnable.tasker:main
|
||||
cic-notify-send = cic_notify.runnable.send:main
|
||||
|
||||
@@ -27,7 +27,7 @@ def define_account_tx_metadata(user: User):
|
||||
if account_metadata:
|
||||
account_metadata = json.loads(account_metadata)
|
||||
person = Person()
|
||||
deserialized_person = person.deserialize(person_data=account_metadata)
|
||||
deserialized_person = person.deserialize(metadata=account_metadata)
|
||||
given_name = deserialized_person.given_name
|
||||
family_name = deserialized_person.family_name
|
||||
phone_number = deserialized_person.tel
|
||||
@@ -46,4 +46,4 @@ def retrieve_account_statement(blockchain_address: str):
|
||||
callback_task='cic_ussd.tasks.callback_handler.process_statement_callback',
|
||||
callback_param=blockchain_address
|
||||
)
|
||||
cic_eth_api.list(address=blockchain_address, limit=9)
|
||||
result = cic_eth_api.list(address=blockchain_address, limit=9)
|
||||
|
||||
@@ -128,8 +128,8 @@
|
||||
},
|
||||
"22": {
|
||||
"description": "Pin entry menu.",
|
||||
"display_key": "ussd.kenya.display_metadata_pin_authorization",
|
||||
"name": "display_metadata_pin_authorization",
|
||||
"display_key": "ussd.kenya.standard_pin_authorization",
|
||||
"name": "standard_pin_authorization",
|
||||
"parent": "start"
|
||||
},
|
||||
"23": {
|
||||
@@ -230,22 +230,9 @@
|
||||
},
|
||||
"39": {
|
||||
"description": "Menu to instruct users to call the office.",
|
||||
"display_key": "ussd.kenya.help",
|
||||
"display_key": "ussd.key.help",
|
||||
"name": "help",
|
||||
"parent": null
|
||||
},
|
||||
"40": {
|
||||
"description": "Menu to display a user's entire profile",
|
||||
"display_key": "ussd.kenya.display_user_metadata",
|
||||
"name": "display_user_metadata",
|
||||
"parent": "account_management"
|
||||
},
|
||||
"41": {
|
||||
"description": "The recipient is not in the system",
|
||||
"display_key": "ussd.kenya.exit_invalid_recipient",
|
||||
"name": "exit_invalid_recipient",
|
||||
"parent": null
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -92,7 +92,7 @@ class UserMetadata:
|
||||
|
||||
# validate data
|
||||
person = Person()
|
||||
deserialized_person = person.deserialize(person_data=json.loads(data))
|
||||
deserialized_person = person.deserialize(metadata=json.loads(data))
|
||||
|
||||
cache_data(key=self.metadata_pointer, data=json.dumps(deserialized_person.serialize()))
|
||||
elif status == 404:
|
||||
|
||||
@@ -15,7 +15,6 @@ from cic_ussd.balance import BalanceManager, compute_operational_balance, get_ca
|
||||
from cic_ussd.chain import Chain
|
||||
from cic_ussd.db.models.user import AccountStatus, User
|
||||
from cic_ussd.db.models.ussd_session import UssdSession
|
||||
from cic_ussd.error import UserMetadataNotFoundError
|
||||
from cic_ussd.menu.ussd_menu import UssdMenu
|
||||
from cic_ussd.metadata import blockchain_address_to_metadata_pointer
|
||||
from cic_ussd.phone_number import get_user_by_phone_number
|
||||
@@ -23,7 +22,6 @@ from cic_ussd.redis import cache_data, create_cached_data_key, get_cached_data
|
||||
from cic_ussd.state_machine import UssdStateMachine
|
||||
from cic_ussd.conversions import to_wei, from_wei
|
||||
from cic_ussd.translation import translation_for
|
||||
from cic_types.models.person import generate_metadata_pointer, get_contact_data_from_vcard
|
||||
|
||||
logg = logging.getLogger(__name__)
|
||||
|
||||
@@ -138,7 +136,7 @@ def process_transaction_pin_authorization(user: User, display_key: str, ussd_ses
|
||||
tx_sender_information = define_account_tx_metadata(user=user)
|
||||
|
||||
token_symbol = 'SRF'
|
||||
user_input = ussd_session.get('session_data').get('transaction_amount')
|
||||
user_input = ussd_session.get('user_input').split('*')[-1]
|
||||
transaction_amount = to_wei(value=int(user_input))
|
||||
logg.debug('Requires integration to determine user tokens.')
|
||||
return process_pin_authorization(
|
||||
@@ -189,55 +187,21 @@ def format_transactions(transactions: list, preferred_language: str):
|
||||
value = transaction.get('to_value')
|
||||
timestamp = transaction.get('timestamp')
|
||||
action_tag = transaction.get('action_tag')
|
||||
direction = transaction.get('direction')
|
||||
token_symbol = 'SRF'
|
||||
|
||||
if action_tag == 'SENT' or action_tag == 'ULITUMA':
|
||||
formatted_transactions += f'{action_tag} {value} {token_symbol} {direction} {recipient_phone_number} {timestamp}.\n'
|
||||
formatted_transactions += f'{action_tag} {value} {token_symbol} {recipient_phone_number} {timestamp}.\n'
|
||||
else:
|
||||
formatted_transactions += f'{action_tag} {value} {token_symbol} {direction} {sender_phone_number} {timestamp}. \n'
|
||||
formatted_transactions += f'{action_tag} {value} {token_symbol} {sender_phone_number} {timestamp}. \n'
|
||||
return formatted_transactions
|
||||
else:
|
||||
if preferred_language == 'en':
|
||||
formatted_transactions = 'NO TRANSACTION HISTORY'
|
||||
formatted_transactions = 'Empty'
|
||||
else:
|
||||
formatted_transactions = 'HAMNA RIPOTI YA MATUMIZI'
|
||||
formatted_transactions = 'Hamna historia'
|
||||
return formatted_transactions
|
||||
|
||||
|
||||
def process_display_user_metadata(user: User, display_key: str):
|
||||
"""
|
||||
:param user:
|
||||
:type user:
|
||||
:param display_key:
|
||||
:type display_key:
|
||||
"""
|
||||
key = generate_metadata_pointer(
|
||||
identifier=blockchain_address_to_metadata_pointer(blockchain_address=user.blockchain_address),
|
||||
cic_type='cic.person'
|
||||
)
|
||||
user_metadata = get_cached_data(key)
|
||||
if user_metadata:
|
||||
user_metadata = json.loads(user_metadata)
|
||||
contact_data = get_contact_data_from_vcard(vcard=user_metadata.get('vcard'))
|
||||
logg.debug(f'{contact_data}')
|
||||
full_name = f'{contact_data.get("given")} {contact_data.get("family")}'
|
||||
gender = user_metadata.get('gender')
|
||||
products = ', '.join(user_metadata.get('products'))
|
||||
location = user_metadata.get('location').get('area_name')
|
||||
|
||||
return translation_for(
|
||||
key=display_key,
|
||||
preferred_language=user.preferred_language,
|
||||
full_name=full_name,
|
||||
gender=gender,
|
||||
location=location,
|
||||
products=products
|
||||
)
|
||||
else:
|
||||
raise UserMetadataNotFoundError(f'Expected user metadata but found none in cache for key: {user.blockchain_address}')
|
||||
|
||||
|
||||
def process_account_statement(user: User, display_key: str, ussd_session: dict):
|
||||
"""
|
||||
:param user:
|
||||
@@ -265,7 +229,7 @@ def process_account_statement(user: User, display_key: str, ussd_session: dict):
|
||||
middle_transaction_set += transactions[3:][:3]
|
||||
first_transaction_set += transactions[:3]
|
||||
# there are probably much cleaner and operational inexpensive ways to do this so find them
|
||||
elif 3 < len(transactions) < 7:
|
||||
elif 4 < len(transactions) < 7:
|
||||
middle_transaction_set += transactions[3:]
|
||||
first_transaction_set += transactions[:3]
|
||||
else:
|
||||
@@ -385,27 +349,18 @@ def process_request(user_input: str, user: User, ussd_session: Optional[dict] =
|
||||
if user.has_valid_pin():
|
||||
last_ussd_session = retrieve_most_recent_ussd_session(phone_number=user.phone_number)
|
||||
|
||||
key = generate_metadata_pointer(
|
||||
key = create_cached_data_key(
|
||||
identifier=blockchain_address_to_metadata_pointer(blockchain_address=user.blockchain_address),
|
||||
cic_type='cic.person'
|
||||
salt='cic.person'
|
||||
)
|
||||
logg.debug(f'METADATA POINTER: {key}')
|
||||
user_metadata = get_cached_data(key=key)
|
||||
logg.debug(f'METADATA: {user_metadata}')
|
||||
|
||||
if last_ussd_session:
|
||||
# get last state
|
||||
last_state = last_ussd_session.state
|
||||
logg.debug(f'LAST USSD SESSION STATE: {last_state}')
|
||||
# if last state is account_creation_prompt and metadata exists, show start menu
|
||||
if last_state in [
|
||||
'account_creation_prompt',
|
||||
'exit',
|
||||
'exit_invalid_pin',
|
||||
'exit_invalid_new_pin',
|
||||
'exit_pin_mismatch',
|
||||
'exit_invalid_request'
|
||||
] and user_metadata is not None:
|
||||
if last_state == 'account_creation_prompt' and user_metadata is not None:
|
||||
return UssdMenu.find_by_name(name='start')
|
||||
else:
|
||||
return UssdMenu.find_by_name(name=last_state)
|
||||
@@ -465,13 +420,9 @@ def custom_display_text(
|
||||
return process_start_menu(display_key=display_key, user=user)
|
||||
elif 'pin_authorization' in menu_name:
|
||||
return process_pin_authorization(display_key=display_key, user=user)
|
||||
elif 'enter_current_pin' in menu_name:
|
||||
return process_pin_authorization(display_key=display_key, user=user)
|
||||
elif menu_name == 'account_balances':
|
||||
return process_account_balances(display_key=display_key, user=user, ussd_session=ussd_session)
|
||||
elif 'transaction_set' in menu_name:
|
||||
return process_account_statement(display_key=display_key, user=user, ussd_session=ussd_session)
|
||||
elif menu_name == 'display_user_metadata':
|
||||
return process_display_user_metadata(display_key=display_key, user=user)
|
||||
else:
|
||||
return translation_for(key=display_key, preferred_language=user.preferred_language)
|
||||
|
||||
@@ -35,8 +35,7 @@ from cic_ussd.requests import (get_request_endpoint,
|
||||
process_pin_reset_requests)
|
||||
from cic_ussd.session.ussd_session import UssdSession as InMemoryUssdSession
|
||||
from cic_ussd.state_machine import UssdStateMachine
|
||||
from cic_ussd.validator import check_ip, check_request_content_length, check_service_code, validate_phone_number, \
|
||||
validate_presence
|
||||
from cic_ussd.validator import check_ip, check_request_content_length, check_service_code, validate_phone_number
|
||||
|
||||
logging.basicConfig(level=logging.WARNING)
|
||||
logg = logging.getLogger()
|
||||
@@ -102,15 +101,9 @@ InMemoryUssdSession.redis_cache = InMemoryStore.cache
|
||||
UserMetadata.base_url = config.get('CIC_META_URL')
|
||||
|
||||
# define signer values
|
||||
export_dir = config.get('PGP_EXPORT_DIR')
|
||||
if export_dir:
|
||||
validate_presence(path=export_dir)
|
||||
Signer.gpg_path = export_dir
|
||||
Signer.gpg_path = config.get('PGP_EXPORT_DIR')
|
||||
Signer.gpg_passphrase = config.get('PGP_PASSPHRASE')
|
||||
key_file_path = f"{config.get('PGP_KEYS_PATH')}{config.get('PGP_PRIVATE_KEYS')}"
|
||||
if key_file_path:
|
||||
validate_presence(path=key_file_path)
|
||||
Signer.key_file_path = key_file_path
|
||||
Signer.key_file_path = f"{config.get('PGP_KEYS_PATH')}{config.get('PGP_PRIVATE_KEYS')}"
|
||||
|
||||
# initialize celery app
|
||||
celery.Celery(backend=config.get('CELERY_RESULT_URL'), broker=config.get('CELERY_BROKER_URL'))
|
||||
|
||||
@@ -16,7 +16,6 @@ from cic_ussd.metadata.signer import Signer
|
||||
from cic_ussd.metadata.user import UserMetadata
|
||||
from cic_ussd.redis import InMemoryStore
|
||||
from cic_ussd.session.ussd_session import UssdSession as InMemoryUssdSession
|
||||
from cic_ussd.validator import validate_presence
|
||||
|
||||
logging.basicConfig(level=logging.WARNING)
|
||||
logg = logging.getLogger()
|
||||
@@ -66,15 +65,9 @@ InMemoryUssdSession.redis_cache = InMemoryStore.cache
|
||||
UserMetadata.base_url = config.get('CIC_META_URL')
|
||||
|
||||
# define signer values
|
||||
export_dir = config.get('PGP_EXPORT_DIR')
|
||||
if export_dir:
|
||||
validate_presence(path=export_dir)
|
||||
Signer.gpg_path = export_dir
|
||||
Signer.gpg_path = config.get('PGP_EXPORT_DIR')
|
||||
Signer.gpg_passphrase = config.get('PGP_PASSPHRASE')
|
||||
key_file_path = f"{config.get('PGP_KEYS_PATH')}{config.get('PGP_PRIVATE_KEYS')}"
|
||||
if key_file_path:
|
||||
validate_presence(path=key_file_path)
|
||||
Signer.key_file_path = key_file_path
|
||||
Signer.key_file_path = f"{config.get('PGP_KEYS_PATH')}{config.get('PGP_PRIVATE_KEYS')}"
|
||||
|
||||
# set up celery
|
||||
current_app = celery.Celery(__name__)
|
||||
|
||||
@@ -78,10 +78,9 @@ def save_recipient_phone_to_session_data(state_machine_data: Tuple[str, dict, Us
|
||||
:type state_machine_data: str
|
||||
"""
|
||||
user_input, ussd_session, user = state_machine_data
|
||||
|
||||
session_data = ussd_session.get('session_data') or {}
|
||||
session_data['recipient_phone_number'] = user_input
|
||||
|
||||
session_data = {
|
||||
'recipient_phone_number': user_input
|
||||
}
|
||||
save_to_in_memory_ussd_session_data(queue='cic-ussd', session_data=session_data, ussd_session=ussd_session)
|
||||
|
||||
|
||||
@@ -110,10 +109,9 @@ def save_transaction_amount_to_session_data(state_machine_data: Tuple[str, dict,
|
||||
:type state_machine_data: str
|
||||
"""
|
||||
user_input, ussd_session, user = state_machine_data
|
||||
|
||||
session_data = ussd_session.get('session_data') or {}
|
||||
session_data['transaction_amount'] = user_input
|
||||
|
||||
session_data = {
|
||||
'transaction_amount': user_input
|
||||
}
|
||||
save_to_in_memory_ussd_session_data(queue='cic-ussd', session_data=session_data, ussd_session=ussd_session)
|
||||
|
||||
|
||||
|
||||
@@ -192,7 +192,7 @@ def edit_user_metadata_attribute(state_machine_data: Tuple[str, dict, User]):
|
||||
# validate user metadata
|
||||
person = Person()
|
||||
user_metadata = json.loads(user_metadata)
|
||||
deserialized_person = person.deserialize(person_data=user_metadata)
|
||||
deserialized_person = person.deserialize(metadata=user_metadata)
|
||||
|
||||
# edit specific metadata attribute
|
||||
if given_name:
|
||||
|
||||
@@ -143,18 +143,14 @@ def define_transaction_action_tag(
|
||||
# check preferred language
|
||||
if preferred_language == 'en':
|
||||
action_tag = 'SENT'
|
||||
direction = 'TO'
|
||||
else:
|
||||
action_tag = 'ULITUMA'
|
||||
direction = 'KWA'
|
||||
else:
|
||||
if preferred_language == 'en':
|
||||
action_tag = 'RECEIVED'
|
||||
direction = 'FROM'
|
||||
else:
|
||||
action_tag = 'ULIPOKEA'
|
||||
direction = 'KUTOKA'
|
||||
return action_tag, direction
|
||||
return action_tag
|
||||
|
||||
|
||||
@celery_app.task
|
||||
@@ -179,17 +175,15 @@ def process_statement_callback(result, param: str, status_code: int):
|
||||
|
||||
# check if sender is in the system
|
||||
sender: User = session.query(User).filter_by(blockchain_address=sender_blockchain_address).first()
|
||||
owner: User = session.query(User).filter_by(blockchain_address=param).first()
|
||||
if sender:
|
||||
processed_transaction['sender_phone_number'] = sender.phone_number
|
||||
|
||||
action_tag, direction = define_transaction_action_tag(
|
||||
preferred_language=owner.preferred_language,
|
||||
action_tag = define_transaction_action_tag(
|
||||
preferred_language=sender.preferred_language,
|
||||
sender_blockchain_address=sender_blockchain_address,
|
||||
param=param
|
||||
)
|
||||
processed_transaction['action_tag'] = action_tag
|
||||
processed_transaction['direction'] = direction
|
||||
|
||||
else:
|
||||
processed_transaction['sender_phone_number'] = 'GRASSROOTS ECONOMICS'
|
||||
@@ -203,8 +197,8 @@ def process_statement_callback(result, param: str, status_code: int):
|
||||
logg.warning(f'Tx with recipient not found in cic-ussd')
|
||||
|
||||
# add transaction values
|
||||
processed_transaction['to_value'] = from_wei(value=transaction.get('to_value')).__str__()
|
||||
processed_transaction['from_value'] = from_wei(value=transaction.get('from_value')).__str__()
|
||||
processed_transaction['to_value'] = from_wei(value=transaction.get('to_value'))
|
||||
processed_transaction['from_value'] = from_wei(value=transaction.get('from_value'))
|
||||
|
||||
raw_timestamp = transaction.get('timestamp')
|
||||
timestamp = datetime.utcfromtimestamp(raw_timestamp).strftime('%d/%m/%y, %H:%M')
|
||||
|
||||
@@ -47,7 +47,7 @@ def to_wei(value: int) -> int:
|
||||
:return: Wei equivalent of value in SRF
|
||||
:rtype: int
|
||||
"""
|
||||
return int(value * 1e+6)
|
||||
return int(value * 1e+18)
|
||||
|
||||
|
||||
class IncomingTransactionProcessor:
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
# standard imports
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
|
||||
# third-party imports
|
||||
@@ -111,7 +110,7 @@ def validate_phone_number(phone: str):
|
||||
|
||||
|
||||
def validate_response_type(processor_response: str) -> bool:
|
||||
"""
|
||||
"""1*3443*3443*Philip*Wanga*1*Juja*Software Developer*2*3
|
||||
This function checks the prefix for a corresponding menu's text from the response offered by the Ussd Processor and
|
||||
determines whether the response should prompt the end of a ussd session or the
|
||||
:param processor_response: A ussd menu's text value.
|
||||
@@ -127,14 +126,3 @@ def validate_response_type(processor_response: str) -> bool:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def validate_presence(path: str):
|
||||
"""
|
||||
|
||||
"""
|
||||
is_present = os.path.exists(path=path)
|
||||
|
||||
if not is_present:
|
||||
raise ValueError(f'Directory/File in path: {path} not found.')
|
||||
else:
|
||||
logg.debug(f'Loading data from: {path}')
|
||||
|
||||
@@ -4,6 +4,5 @@
|
||||
"enter_gender",
|
||||
"enter_age",
|
||||
"enter_location",
|
||||
"enter_products",
|
||||
"display_metadata_pin_authorization"
|
||||
"enter_products"
|
||||
]
|
||||
@@ -82,7 +82,7 @@ def test_format_user_metadata(create_activated_user,
|
||||
from cic_types.models.person import Person
|
||||
formatted_user_metadata = format_user_metadata(metadata=complete_user_metadata, user=create_activated_user)
|
||||
person = Person()
|
||||
user_metadata = person.deserialize(person_data=formatted_user_metadata)
|
||||
user_metadata = person.deserialize(metadata=formatted_user_metadata)
|
||||
assert formatted_user_metadata == user_metadata.serialize()
|
||||
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@
|
||||
{
|
||||
"trigger": "scan_data",
|
||||
"source": "exit_invalid_recipient",
|
||||
"dest": "enter_transaction_recipient",
|
||||
"dest": "send_enter_recipient",
|
||||
"conditions": "cic_ussd.state_machine.logic.menu.menu_zero_zero_selected"
|
||||
},
|
||||
{
|
||||
@@ -49,13 +49,13 @@
|
||||
"after": "cic_ussd.state_machine.logic.sms.upsell_unregistered_recipient"
|
||||
},
|
||||
{
|
||||
"trigger": "scan_data",
|
||||
"trigger": "feed_char",
|
||||
"source": "exit_successful_transaction",
|
||||
"dest": "start",
|
||||
"conditions": "cic_ussd.state_machine.logic.menu.menu_zero_zero_selected"
|
||||
},
|
||||
{
|
||||
"trigger": "scan_data",
|
||||
"trigger": "feed_char",
|
||||
"source": "exit_successful_transaction",
|
||||
"dest": "exit",
|
||||
"conditions": "cic_ussd.state_machine.logic.menu.menu_ninety_nine_selected"
|
||||
|
||||
@@ -26,18 +26,18 @@
|
||||
{
|
||||
"trigger": "scan_data",
|
||||
"source": "metadata_management",
|
||||
"dest": "display_metadata_pin_authorization",
|
||||
"dest": "standard_pin_authorization",
|
||||
"conditions": "cic_ussd.state_machine.logic.menu.menu_five_selected"
|
||||
},
|
||||
{
|
||||
"trigger": "scan_data",
|
||||
"source": "display_metadata_pin_authorization",
|
||||
"source": "standard_pin_authorization",
|
||||
"dest": "display_user_metadata",
|
||||
"conditions": "cic_ussd.state_machine.logic.pin.is_authorized_pin"
|
||||
},
|
||||
{
|
||||
"trigger": "scan_data",
|
||||
"source": "display_metadata_pin_authorization",
|
||||
"source": "standard_pin_authorization",
|
||||
"dest": "exit_pin_blocked",
|
||||
"conditions": "cic_ussd.state_machine.logic.pin.is_locked_account"
|
||||
},
|
||||
|
||||
@@ -55,8 +55,8 @@ en:
|
||||
4. Edit products
|
||||
5. View my profile
|
||||
0. Back
|
||||
display_user_metadata: |-
|
||||
CON Your details are:
|
||||
display_user_profile_data: |-
|
||||
END Your details are:
|
||||
Name: %{full_name}
|
||||
Gender: %{gender}
|
||||
Location: %{location}
|
||||
@@ -85,7 +85,7 @@ en:
|
||||
retry: |-
|
||||
CON Please enter your PIN. You have %{remaining_attempts} attempts remaining.
|
||||
0. Back
|
||||
display_metadata_pin_authorization:
|
||||
standard_pin_authorization:
|
||||
first: |-
|
||||
CON Please enter your PIN.
|
||||
0. Back
|
||||
|
||||
@@ -56,7 +56,7 @@ sw:
|
||||
5. Angalia wasifu wako
|
||||
0. Nyuma
|
||||
display_user_metadata: |-
|
||||
CON Wasifu wako una maelezo yafuatayo:
|
||||
END Wasifu wako una maelezo yafuatayo:
|
||||
Jina: %{full_name}
|
||||
Jinsia: %{gender}
|
||||
Eneo: %{location}
|
||||
|
||||
@@ -6,7 +6,6 @@ DEV_ETH_ACCOUNT_CONTRACT_DEPLOYER=0xEb3907eCad74a0013c259D5874AE7f22DcBcC95C
|
||||
DEV_ETH_ACCOUNT_RESERVE_MINTER=${DEV_ETH_ACCOUNT_RESERVE_MINTER:-$DEV_ETH_ACCOUNT_CONTRACT_DEPLOYER}
|
||||
DEV_ETH_ACCOUNT_ACCOUNTS_INDEX_WRITER=${DEV_ETH_ACCOUNT_RESERVE_MINTER:-$DEV_ETH_ACCOUNT_CONTRACT_DEPLOYER}
|
||||
DEV_RESERVE_AMOUNT=${DEV_ETH_RESERVE_AMOUNT:-""10000000000000000000000000000000000}
|
||||
faucet_amount=${DEV_FAUCET_AMOUNT:-0}
|
||||
keystore_file=$(realpath ./keystore/UTC--2021-01-08T17-18-44.521011372Z--eb3907ecad74a0013c259d5874ae7f22dcbcc95c)
|
||||
|
||||
echo "environment:"
|
||||
@@ -72,8 +71,6 @@ if [[ -n "${ETH_PROVIDER}" ]]; then
|
||||
# Sarafu faucet contract
|
||||
>&2 echo "deploy token faucet contract"
|
||||
DEV_FAUCET_ADDRESS=`sarafu-faucet-deploy -y $keystore_file -i $CIC_CHAIN_SPEC -p $ETH_PROVIDER -w -v --account-index-address $DEV_ACCOUNT_INDEX_ADDRESS $DEV_RESERVE_ADDRESS`
|
||||
>&2 echo "set token faucet amount"
|
||||
sarafu-faucet-set -y $keystore_file -i $CIC_CHAIN_SPEC -p $ETH_PROVIDER -a $DEV_FAUCET_ADDRESS $faucet_amount
|
||||
eth-contract-registry-set -w -y $keystore_file -r $CIC_REGISTRY_ADDRESS -i $CIC_CHAIN_SPEC -p $ETH_PROVIDER -vv Faucet $DEV_FAUCET_ADDRESS
|
||||
>&2 echo "set faucet as token minter"
|
||||
giftable-token-minter -w -y $keystore_file -a $DEV_RESERVE_ADDRESS -i $CIC_CHAIN_SPEC -p $ETH_PROVIDER -vv $DEV_FAUCET_ADDRESS
|
||||
|
||||
@@ -21,6 +21,8 @@ debug='-vv'
|
||||
abi_dir=${ETH_ABI_DIR:-/usr/local/share/cic/solidity/abi}
|
||||
gas_amount=100000000000000000000000
|
||||
token_amount=${gas_amount}
|
||||
#faucet_amount=1000000000
|
||||
faucet_amount=${DEV_FAUCET_AMOUNT:-0}
|
||||
env_out_file=${CIC_DATA_DIR}/.env_seed
|
||||
init_level_file=${CIC_DATA_DIR}/.init
|
||||
truncate $env_out_file -s 0
|
||||
|
||||
Reference in New Issue
Block a user