Compare commits
3 Commits
lash/celer
...
lash/cic-c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b55208ce7
|
||
|
|
9e8dd216b9
|
||
|
|
8d5a787165
|
@@ -2,6 +2,7 @@
|
||||
import logging
|
||||
|
||||
# external imports
|
||||
from chainlib.eth.erc20 import ERC20
|
||||
from chainlib.eth.address import (
|
||||
to_checksum_address,
|
||||
)
|
||||
@@ -12,7 +13,6 @@ from cic_eth_registry.error import (
|
||||
NotAContractError,
|
||||
ContractMismatchError,
|
||||
)
|
||||
from eth_erc20 import ERC20
|
||||
|
||||
# local imports
|
||||
from .base import TagSyncFilter
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
cic-base~=0.1.2b8
|
||||
cic-base~=0.1.2b6
|
||||
alembic==1.4.2
|
||||
confini~=0.3.6rc3
|
||||
uwsgi==2.0.19.1
|
||||
moolb~=0.1.0
|
||||
cic-eth-registry~=0.5.5a4
|
||||
cic-eth-registry~=0.5.5a1
|
||||
SQLAlchemy==1.3.20
|
||||
semver==2.13.0
|
||||
psycopg2==2.8.6
|
||||
celery==4.4.7
|
||||
redis==3.5.3
|
||||
chainsyncer[sql]~=0.0.2a4
|
||||
chainsyncer[sql]~=0.0.2a2
|
||||
|
||||
@@ -8,4 +8,6 @@ eth_tester==0.5.0b3
|
||||
py-evm==0.3.0a20
|
||||
web3==5.12.2
|
||||
cic-eth-registry~=0.5.5a3
|
||||
cic-base[full]==0.1.2b8
|
||||
giftable-erc20-token~=0.0.8a10
|
||||
eth-address-index~=0.1.1a10
|
||||
sarafu-faucet~=0.0.3a1
|
||||
|
||||
@@ -3,7 +3,7 @@ import logging
|
||||
|
||||
# external imports
|
||||
import celery
|
||||
from erc20_faucet import Faucet
|
||||
from erc20_single_shot_faucet import SingleShotFaucet as Faucet
|
||||
from hexathon import (
|
||||
strip_0x,
|
||||
)
|
||||
@@ -20,8 +20,8 @@ from chainlib.eth.tx import (
|
||||
)
|
||||
from chainlib.chain import ChainSpec
|
||||
from chainlib.error import JSONRPCException
|
||||
from eth_accounts_index.registry import AccountRegistry # TODO, use interface module instead (needs gas limit method)
|
||||
from sarafu_faucet import MinterFaucet
|
||||
from eth_accounts_index import AccountRegistry
|
||||
from sarafu_faucet import MinterFaucet as Faucet
|
||||
from chainqueue.db.models.tx import TxCache
|
||||
|
||||
# local import
|
||||
@@ -127,13 +127,13 @@ def register(self, account_address, chain_spec_dict, writer_address=None):
|
||||
if writer_address == ZERO_ADDRESS:
|
||||
session.close()
|
||||
raise RoleMissingError('call address for resgistering {}'.format(account_address))
|
||||
account_registry_address = registry.by_name('AccountsIndex', sender_address=call_address)
|
||||
account_registry_address = registry.by_name('AccountRegistry', sender_address=call_address)
|
||||
|
||||
# Generate and sign transaction
|
||||
rpc_signer = RPCConnection.connect(chain_spec, 'signer')
|
||||
nonce_oracle = CustodialTaskNonceOracle(writer_address, self.request.root_id, session=session) #, default_nonce)
|
||||
gas_oracle = self.create_gas_oracle(rpc, AccountsIndex.gas)
|
||||
account_registry = AccountsIndex(chain_spec, signer=rpc_signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle)
|
||||
gas_oracle = self.create_gas_oracle(rpc, AccountRegistry.gas)
|
||||
account_registry = AccountRegistry(chain_spec, signer=rpc_signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle)
|
||||
(tx_hash_hex, tx_signed_raw_hex) = account_registry.add(account_registry_address, writer_address, account_address, tx_format=TxFormat.RLP_SIGNED)
|
||||
rpc_signer.disconnect()
|
||||
|
||||
@@ -185,7 +185,7 @@ def gift(self, account_address, chain_spec_dict):
|
||||
# Generate and sign transaction
|
||||
rpc_signer = RPCConnection.connect(chain_spec, 'signer')
|
||||
nonce_oracle = CustodialTaskNonceOracle(account_address, self.request.root_id, session=session) #, default_nonce)
|
||||
gas_oracle = self.create_gas_oracle(rpc, MinterFaucet.gas)
|
||||
gas_oracle = self.create_gas_oracle(rpc, Faucet.gas)
|
||||
faucet = Faucet(chain_spec, signer=rpc_signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle)
|
||||
(tx_hash_hex, tx_signed_raw_hex) = faucet.give_to(faucet_address, account_address, account_address, tx_format=TxFormat.RLP_SIGNED)
|
||||
rpc_signer.disconnect()
|
||||
@@ -338,7 +338,7 @@ def cache_account_data(
|
||||
chain_spec = ChainSpec.from_dict(chain_spec_dict)
|
||||
tx_signed_raw_bytes = bytes.fromhex(tx_signed_raw_hex[2:])
|
||||
tx = unpack(tx_signed_raw_bytes, chain_spec)
|
||||
tx_data = AccountsIndex.parse_add_request(tx['data'])
|
||||
tx_data = AccountRegistry.parse_add_request(tx['data'])
|
||||
|
||||
session = SessionBase.create_session()
|
||||
tx_cache = TxCache(
|
||||
|
||||
@@ -6,6 +6,7 @@ import celery
|
||||
from chainlib.eth.constant import ZERO_ADDRESS
|
||||
from chainlib.chain import ChainSpec
|
||||
from chainlib.connection import RPCConnection
|
||||
from chainlib.eth.erc20 import ERC20
|
||||
from chainlib.eth.tx import (
|
||||
TxFormat,
|
||||
unpack,
|
||||
@@ -15,7 +16,6 @@ from cic_eth_registry.erc20 import ERC20Token
|
||||
from hexathon import strip_0x
|
||||
from chainqueue.db.models.tx import TxCache
|
||||
from chainqueue.error import NotLocalTxError
|
||||
from eth_erc20 import ERC20
|
||||
|
||||
# local imports
|
||||
from cic_eth.db.models.base import SessionBase
|
||||
|
||||
@@ -7,7 +7,7 @@ from chainlib.chain import ChainSpec
|
||||
from chainlib.connection import RPCConnection
|
||||
from chainlib.eth.constant import ZERO_ADDRESS
|
||||
from cic_eth_registry import CICRegistry
|
||||
from eth_address_declarator import Declarator
|
||||
from eth_address_declarator import AddressDeclarator
|
||||
|
||||
# local imports
|
||||
from cic_eth.task import BaseTask
|
||||
@@ -23,12 +23,12 @@ def translate_address(address, trusted_addresses, chain_spec, sender_address=ZER
|
||||
registry = CICRegistry(chain_spec, rpc)
|
||||
|
||||
declarator_address = registry.by_name('AddressDeclarator', sender_address=sender_address)
|
||||
c = Declarator(chain_spec)
|
||||
c = AddressDeclarator(chain_spec)
|
||||
|
||||
for trusted_address in trusted_addresses:
|
||||
o = c.declaration(declarator_address, trusted_address, address, sender_address=sender_address)
|
||||
r = rpc.do(o)
|
||||
declaration_hex = Declarator.parse_declaration(r)
|
||||
declaration_hex = AddressDeclarator.parse_declaration(r)
|
||||
declaration_hex = declaration_hex[0].rstrip('0')
|
||||
declaration_bytes = bytes.fromhex(declaration_hex)
|
||||
declaration = None
|
||||
|
||||
@@ -14,13 +14,13 @@ from chainlib.eth.tx import (
|
||||
)
|
||||
from chainlib.eth.block import block_by_number
|
||||
from chainlib.eth.contract import abi_decode_single
|
||||
from chainlib.eth.erc20 import ERC20
|
||||
from hexathon import strip_0x
|
||||
from cic_eth_registry import CICRegistry
|
||||
from cic_eth_registry.erc20 import ERC20Token
|
||||
from chainqueue.db.models.otx import Otx
|
||||
from chainqueue.db.enum import StatusEnum
|
||||
from chainqueue.query import get_tx_cache
|
||||
from eth_erc20 import ERC20
|
||||
|
||||
# local imports
|
||||
from cic_eth.queue.time import tx_times
|
||||
|
||||
@@ -13,7 +13,9 @@ from hexathon import (
|
||||
strip_0x,
|
||||
add_0x,
|
||||
)
|
||||
from erc20_faucet import Faucet
|
||||
# TODO: use sarafu_Faucet for both when inheritance has been implemented
|
||||
from erc20_single_shot_faucet import SingleShotFaucet
|
||||
from sarafu_faucet import MinterFaucet as Faucet
|
||||
|
||||
# local imports
|
||||
from .base import SyncFilter
|
||||
@@ -69,13 +71,14 @@ class CallbackFilter(SyncFilter):
|
||||
#transfer_data['token_address'] = tx.inputs[0]
|
||||
faucet_contract = tx.inputs[0]
|
||||
|
||||
o = Faucet.token(faucet_contract, sender_address=self.caller_address)
|
||||
c = SingleShotFaucet(self.chain_spec)
|
||||
o = c.token(faucet_contract, sender_address=self.caller_address)
|
||||
r = conn.do(o)
|
||||
transfer_data['token_address'] = add_0x(c.parse_token(r))
|
||||
|
||||
o = c.token_amount(faucet_contract, sender_address=self.caller_address)
|
||||
o = c.amount(faucet_contract, sender_address=self.caller_address)
|
||||
r = conn.do(o)
|
||||
transfer_data['value'] = c.parse_token_amount(r)
|
||||
transfer_data['value'] = c.parse_amount(r)
|
||||
|
||||
return ('tokengift', transfer_data)
|
||||
|
||||
|
||||
@@ -36,7 +36,6 @@ from cic_eth.eth import (
|
||||
from cic_eth.admin import (
|
||||
debug,
|
||||
ctrl,
|
||||
token
|
||||
)
|
||||
from cic_eth.queue import (
|
||||
query,
|
||||
@@ -121,25 +120,20 @@ broker = config.get('CELERY_BROKER_URL')
|
||||
if broker[:4] == 'file':
|
||||
bq = tempfile.mkdtemp()
|
||||
bp = tempfile.mkdtemp()
|
||||
conf_update = {
|
||||
current_app.conf.update({
|
||||
'broker_url': broker,
|
||||
'broker_transport_options': {
|
||||
'data_folder_in': bq,
|
||||
'data_folder_out': bq,
|
||||
'data_folder_processed': bp,
|
||||
},
|
||||
}
|
||||
if config.true('CELERY_DEBUG'):
|
||||
conf_update['result_extended'] = True
|
||||
current_app.conf.update(conf_update)
|
||||
},
|
||||
)
|
||||
logg.warning('celery broker dirs queue i/o {} processed {}, will NOT be deleted on shutdown'.format(bq, bp))
|
||||
else:
|
||||
conf_update = {
|
||||
'broker_url': broker,
|
||||
}
|
||||
if config.true('CELERY_DEBUG'):
|
||||
conf_update['result_extended'] = True
|
||||
current_app.conf.update(conf_update)
|
||||
current_app.conf.update({
|
||||
'broker_url': broker,
|
||||
})
|
||||
|
||||
result = config.get('CELERY_RESULT_URL')
|
||||
if result[:4] == 'file':
|
||||
|
||||
@@ -10,7 +10,7 @@ version = (
|
||||
0,
|
||||
11,
|
||||
0,
|
||||
'beta.12',
|
||||
'beta.11',
|
||||
)
|
||||
|
||||
version_object = semver.VersionInfo(
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
[celery]
|
||||
broker_url = redis://
|
||||
result_url = redis://
|
||||
debug = 0
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
[celery]
|
||||
broker_url = redis://localhost:63379
|
||||
result_url = redis://localhost:63379
|
||||
debug = 0
|
||||
|
||||
@@ -29,7 +29,7 @@ RUN /usr/local/bin/python -m pip install --upgrade pip
|
||||
# python merge_requirements.py | tee merged_requirements.txt
|
||||
#RUN cd cic-base && \
|
||||
# pip install $pip_extra_index_url_flag -r ./merged_requirements.txt
|
||||
RUN pip install $pip_extra_index_url_flag cic-base[full_graph]==0.1.2b8
|
||||
RUN pip install $pip_extra_index_url_flag cic-base[full_graph]==0.1.2a77
|
||||
|
||||
COPY cic-eth/scripts/ scripts/
|
||||
COPY cic-eth/setup.cfg cic-eth/setup.py ./
|
||||
|
||||
@@ -1,24 +1,25 @@
|
||||
cic-base==0.1.2b8
|
||||
cic-base==0.1.2b5
|
||||
celery==4.4.7
|
||||
crypto-dev-signer~=0.4.14b3
|
||||
confini~=0.3.6rc3
|
||||
cic-eth-registry~=0.5.5a4
|
||||
cic-eth-registry~=0.5.4a16
|
||||
#cic-bancor~=0.0.6
|
||||
redis==3.5.3
|
||||
alembic==1.4.2
|
||||
websockets==8.1
|
||||
requests~=2.24.0
|
||||
eth_accounts_index~=0.0.11a11
|
||||
erc20-transfer-authorization~=0.3.1a6
|
||||
eth_accounts_index~=0.0.11a9
|
||||
erc20-transfer-authorization~=0.3.1a5
|
||||
uWSGI==2.0.19.1
|
||||
semver==2.13.0
|
||||
websocket-client==0.57.0
|
||||
moolb~=0.1.1b2
|
||||
eth-address-index~=0.1.1a11
|
||||
chainlib~=0.0.3a1
|
||||
eth-address-index~=0.1.1a9
|
||||
chainlib~=0.0.2a20
|
||||
hexathon~=0.0.1a7
|
||||
chainsyncer[sql]~=0.0.2a4
|
||||
chainsyncer[sql]~=0.0.2a2
|
||||
chainqueue~=0.0.2a2
|
||||
sarafu-faucet==0.0.3a1
|
||||
pysha3==1.0.2
|
||||
coincurve==15.0.0
|
||||
sarafu-faucet==0.0.3a2
|
||||
sarafu-faucet==0.0.2a28
|
||||
potaahto~=0.0.1a1
|
||||
|
||||
@@ -2,7 +2,7 @@ FROM node:15.3.0-alpine3.10
|
||||
|
||||
WORKDIR /tmp/src/cic-meta
|
||||
|
||||
RUN apk add --no-cache postgresql bash
|
||||
RUN apk add --no-cache postgresql
|
||||
|
||||
COPY cic-meta/package.json \
|
||||
./
|
||||
|
||||
@@ -1,6 +1,3 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
PGPASSWORD=$DATABASE_PASSWORD psql -v ON_ERROR_STOP=1 -U $DATABASE_USER -h $DATABASE_HOST -p $DATABASE_PORT -d $DATABASE_NAME -f $SCHEMA_SQL_PATH
|
||||
|
||||
|
||||
PGPASSWORD=$DATABASE_PASSWORD psql -U $DATABASE_USER -h $DATABASE_HOST -p $DATABASE_PORT -d $DATABASE_NAME -f $SCHEMA_SQL_PATH
|
||||
|
||||
@@ -1,7 +1,3 @@
|
||||
#!/bin/bash
|
||||
set -euo pipefail
|
||||
|
||||
# db migration
|
||||
sh ./db.sh
|
||||
|
||||
# /usr/local/bin/node /usr/local/bin/cic-meta-server $@
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
create table if not exists store (
|
||||
create table if not exists cic_meta.store (
|
||||
id serial primary key not null,
|
||||
owner_fingerprint text not null,
|
||||
hash char(64) not null unique,
|
||||
|
||||
@@ -20,7 +20,7 @@ def define_account_tx_metadata(user: Account):
|
||||
)
|
||||
key = generate_metadata_pointer(
|
||||
identifier=identifier,
|
||||
cic_type=':cic.person'
|
||||
cic_type='cic.person'
|
||||
)
|
||||
account_metadata = get_cached_data(key=key)
|
||||
|
||||
|
||||
@@ -80,7 +80,7 @@ def get_cached_operational_balance(blockchain_address: str):
|
||||
"""
|
||||
key = create_cached_data_key(
|
||||
identifier=bytes.fromhex(blockchain_address[2:]),
|
||||
salt=':cic.balances_data'
|
||||
salt='cic.balances_data'
|
||||
)
|
||||
cached_balance = get_cached_data(key=key)
|
||||
if cached_balance:
|
||||
|
||||
@@ -38,13 +38,3 @@ class MetadataStoreError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class SeppukuError(Exception):
|
||||
"""Exception base class for all errors that should cause system shutdown"""
|
||||
pass
|
||||
|
||||
|
||||
class InitializationError(Exception):
|
||||
"""Exception raised when initialization state is insufficient to run component"""
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@@ -118,7 +118,7 @@ class MetadataRequestsHandler(Metadata):
|
||||
metadata_http_error_handler(result=result)
|
||||
response_data = result.content
|
||||
data = json.loads(response_data.decode('utf-8'))
|
||||
if result.status_code == 200 and self.cic_type == ':cic.person':
|
||||
if result.status_code == 200 and self.cic_type == 'cic.person':
|
||||
person = Person()
|
||||
deserialized_person = person.deserialize(person_data=json.loads(data))
|
||||
data = json.dumps(deserialized_person.serialize())
|
||||
|
||||
@@ -9,4 +9,4 @@ from .base import MetadataRequestsHandler
|
||||
class PersonMetadata(MetadataRequestsHandler):
|
||||
|
||||
def __init__(self, identifier: bytes):
|
||||
super().__init__(cic_type=':cic.person', identifier=identifier)
|
||||
super().__init__(cic_type='cic.person', identifier=identifier)
|
||||
|
||||
@@ -10,4 +10,4 @@ from .base import MetadataRequestsHandler
|
||||
class PhonePointerMetadata(MetadataRequestsHandler):
|
||||
|
||||
def __init__(self, identifier: bytes):
|
||||
super().__init__(cic_type=':cic.phone', identifier=identifier)
|
||||
super().__init__(cic_type='cic.msisdn', identifier=identifier)
|
||||
|
||||
@@ -7,7 +7,6 @@ from typing import Optional
|
||||
# third party imports
|
||||
import celery
|
||||
from sqlalchemy import desc
|
||||
from cic_eth.api import Api
|
||||
from tinydb.table import Document
|
||||
|
||||
# local imports
|
||||
@@ -16,7 +15,7 @@ from cic_ussd.balance import BalanceManager, compute_operational_balance, get_ca
|
||||
from cic_ussd.chain import Chain
|
||||
from cic_ussd.db.models.account import AccountStatus, Account
|
||||
from cic_ussd.db.models.ussd_session import UssdSession
|
||||
from cic_ussd.error import MetadataNotFoundError, SeppukuError
|
||||
from cic_ussd.error import MetadataNotFoundError
|
||||
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
|
||||
@@ -29,38 +28,6 @@ from cic_types.models.person import generate_metadata_pointer, get_contact_data_
|
||||
logg = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def get_default_token_data():
|
||||
chain_str = Chain.spec.__str__()
|
||||
cic_eth_api = Api(chain_str=chain_str)
|
||||
default_token_request_task = cic_eth_api.default_token()
|
||||
default_token_data = default_token_request_task.get()
|
||||
return default_token_data
|
||||
|
||||
|
||||
def retrieve_token_symbol(chain_str: str = Chain.spec.__str__()):
|
||||
"""
|
||||
:param chain_str:
|
||||
:type chain_str:
|
||||
:return:
|
||||
:rtype:
|
||||
"""
|
||||
cache_key = create_cached_data_key(
|
||||
identifier=chain_str.encode('utf-8'),
|
||||
salt=':cic.default_token_data'
|
||||
)
|
||||
cached_data = get_cached_data(key=cache_key)
|
||||
if cached_data:
|
||||
default_token_data = json.loads(cached_data)
|
||||
return default_token_data.get('symbol')
|
||||
else:
|
||||
logg.warning('Cached default token data not found. Attempting retrieval from default token API')
|
||||
default_token_data = get_default_token_data()
|
||||
if default_token_data:
|
||||
return default_token_data.get('symbol')
|
||||
else:
|
||||
raise SeppukuError(f'Could not retrieve default token for: {chain_str}')
|
||||
|
||||
|
||||
def process_pin_authorization(display_key: str, user: Account, **kwargs) -> str:
|
||||
"""
|
||||
This method provides translation for all ussd menu entries that follow the pin authorization pattern.
|
||||
@@ -106,9 +73,7 @@ def process_exit_insufficient_balance(display_key: str, user: Account, ussd_sess
|
||||
# compile response data
|
||||
user_input = ussd_session.get('user_input').split('*')[-1]
|
||||
transaction_amount = to_wei(value=int(user_input))
|
||||
|
||||
# get default data
|
||||
token_symbol = retrieve_token_symbol()
|
||||
token_symbol = 'GFT'
|
||||
|
||||
recipient_phone_number = ussd_session.get('session_data').get('recipient_phone_number')
|
||||
recipient = get_user_by_phone_number(phone_number=recipient_phone_number)
|
||||
@@ -137,7 +102,7 @@ def process_exit_successful_transaction(display_key: str, user: Account, ussd_se
|
||||
:rtype: str
|
||||
"""
|
||||
transaction_amount = to_wei(int(ussd_session.get('session_data').get('transaction_amount')))
|
||||
token_symbol = retrieve_token_symbol()
|
||||
token_symbol = 'GFT'
|
||||
recipient_phone_number = ussd_session.get('session_data').get('recipient_phone_number')
|
||||
recipient = get_user_by_phone_number(phone_number=recipient_phone_number)
|
||||
tx_recipient_information = define_account_tx_metadata(user=recipient)
|
||||
@@ -172,7 +137,7 @@ def process_transaction_pin_authorization(user: Account, display_key: str, ussd_
|
||||
tx_recipient_information = define_account_tx_metadata(user=recipient)
|
||||
tx_sender_information = define_account_tx_metadata(user=user)
|
||||
|
||||
token_symbol = retrieve_token_symbol()
|
||||
token_symbol = 'GFT'
|
||||
user_input = ussd_session.get('session_data').get('transaction_amount')
|
||||
transaction_amount = to_wei(value=int(user_input))
|
||||
logg.debug('Requires integration to determine user tokens.')
|
||||
@@ -203,18 +168,18 @@ def process_account_balances(user: Account, display_key: str, ussd_session: dict
|
||||
logg.debug('Requires call to retrieve tax and bonus amounts')
|
||||
tax = ''
|
||||
bonus = ''
|
||||
token_symbol = retrieve_token_symbol()
|
||||
|
||||
return translation_for(
|
||||
key=display_key,
|
||||
preferred_language=user.preferred_language,
|
||||
operational_balance=operational_balance,
|
||||
tax=tax,
|
||||
bonus=bonus,
|
||||
token_symbol=token_symbol
|
||||
token_symbol='GFT'
|
||||
)
|
||||
|
||||
|
||||
def format_transactions(transactions: list, preferred_language: str, token_symbol: str):
|
||||
def format_transactions(transactions: list, preferred_language: str):
|
||||
|
||||
formatted_transactions = ''
|
||||
if len(transactions) > 0:
|
||||
@@ -225,7 +190,7 @@ def format_transactions(transactions: list, preferred_language: str, token_symbo
|
||||
timestamp = transaction.get('timestamp')
|
||||
action_tag = transaction.get('action_tag')
|
||||
direction = transaction.get('direction')
|
||||
token_symbol = token_symbol
|
||||
token_symbol = 'GFT'
|
||||
|
||||
if action_tag == 'SENT' or action_tag == 'ULITUMA':
|
||||
formatted_transactions += f'{action_tag} {value} {token_symbol} {direction} {recipient_phone_number} {timestamp}.\n'
|
||||
@@ -249,7 +214,7 @@ def process_display_user_metadata(user: Account, display_key: str):
|
||||
"""
|
||||
key = generate_metadata_pointer(
|
||||
identifier=blockchain_address_to_metadata_pointer(blockchain_address=user.blockchain_address),
|
||||
cic_type=':cic.person'
|
||||
cic_type='cic.person'
|
||||
)
|
||||
user_metadata = get_cached_data(key)
|
||||
if user_metadata:
|
||||
@@ -286,11 +251,9 @@ def process_account_statement(user: Account, display_key: str, ussd_session: dic
|
||||
"""
|
||||
# retrieve cached statement
|
||||
identifier = blockchain_address_to_metadata_pointer(blockchain_address=user.blockchain_address)
|
||||
key = create_cached_data_key(identifier=identifier, salt=':cic.statement')
|
||||
key = create_cached_data_key(identifier=identifier, salt='cic.statement')
|
||||
transactions = get_cached_data(key=key)
|
||||
|
||||
token_symbol = retrieve_token_symbol()
|
||||
|
||||
first_transaction_set = []
|
||||
middle_transaction_set = []
|
||||
last_transaction_set = []
|
||||
@@ -314,8 +277,7 @@ def process_account_statement(user: Account, display_key: str, ussd_session: dic
|
||||
preferred_language=user.preferred_language,
|
||||
first_transaction_set=format_transactions(
|
||||
transactions=first_transaction_set,
|
||||
preferred_language=user.preferred_language,
|
||||
token_symbol=token_symbol
|
||||
preferred_language=user.preferred_language
|
||||
)
|
||||
)
|
||||
elif display_key == 'ussd.kenya.middle_transaction_set':
|
||||
@@ -324,8 +286,7 @@ def process_account_statement(user: Account, display_key: str, ussd_session: dic
|
||||
preferred_language=user.preferred_language,
|
||||
middle_transaction_set=format_transactions(
|
||||
transactions=middle_transaction_set,
|
||||
preferred_language=user.preferred_language,
|
||||
token_symbol=token_symbol
|
||||
preferred_language=user.preferred_language
|
||||
)
|
||||
)
|
||||
|
||||
@@ -335,8 +296,7 @@ def process_account_statement(user: Account, display_key: str, ussd_session: dic
|
||||
preferred_language=user.preferred_language,
|
||||
last_transaction_set=format_transactions(
|
||||
transactions=last_transaction_set,
|
||||
preferred_language=user.preferred_language,
|
||||
token_symbol=token_symbol
|
||||
preferred_language=user.preferred_language
|
||||
)
|
||||
)
|
||||
|
||||
@@ -352,19 +312,18 @@ def process_start_menu(display_key: str, user: Account):
|
||||
:return: Corresponding translation text response
|
||||
:rtype: str
|
||||
"""
|
||||
token_symbol = retrieve_token_symbol()
|
||||
chain_str = Chain.spec.__str__()
|
||||
blockchain_address = user.blockchain_address
|
||||
balance_manager = BalanceManager(address=blockchain_address,
|
||||
chain_str=chain_str,
|
||||
token_symbol=token_symbol)
|
||||
token_symbol='GFT')
|
||||
|
||||
# get balances synchronously for display on start menu
|
||||
balances_data = balance_manager.get_balances()
|
||||
|
||||
key = create_cached_data_key(
|
||||
identifier=bytes.fromhex(blockchain_address[2:]),
|
||||
salt=':cic.balances_data'
|
||||
salt='cic.balances_data'
|
||||
)
|
||||
cache_data(key=key, data=json.dumps(balances_data))
|
||||
|
||||
@@ -381,6 +340,9 @@ def process_start_menu(display_key: str, user: Account):
|
||||
# retrieve and cache account's statement
|
||||
retrieve_account_statement(blockchain_address=blockchain_address)
|
||||
|
||||
# TODO [Philip]: figure out how to get token symbol from a metadata layer of sorts.
|
||||
token_symbol = 'GFT'
|
||||
|
||||
return translation_for(
|
||||
key=display_key,
|
||||
preferred_language=user.preferred_language,
|
||||
@@ -413,13 +375,6 @@ def process_request(user_input: str, user: Account, ussd_session: Optional[dict]
|
||||
:return: A ussd menu's corresponding text value.
|
||||
:rtype: Document
|
||||
"""
|
||||
# retrieve metadata before any transition
|
||||
key = generate_metadata_pointer(
|
||||
identifier=blockchain_address_to_metadata_pointer(blockchain_address=user.blockchain_address),
|
||||
cic_type=':cic.person'
|
||||
)
|
||||
person_metadata = get_cached_data(key=key)
|
||||
|
||||
if ussd_session:
|
||||
if user_input == "0":
|
||||
return UssdMenu.parent_menu(menu_name=ussd_session.get('state'))
|
||||
@@ -427,12 +382,29 @@ def process_request(user_input: str, user: Account, ussd_session: Optional[dict]
|
||||
successive_state = next_state(ussd_session=ussd_session, user=user, user_input=user_input)
|
||||
return UssdMenu.find_by_name(name=successive_state)
|
||||
else:
|
||||
|
||||
key = generate_metadata_pointer(
|
||||
identifier=blockchain_address_to_metadata_pointer(blockchain_address=user.blockchain_address),
|
||||
cic_type='cic.person'
|
||||
)
|
||||
|
||||
# retrieve and cache account's metadata
|
||||
s_query_person_metadata = celery.signature(
|
||||
'cic_ussd.tasks.metadata.query_person_metadata',
|
||||
[user.blockchain_address]
|
||||
)
|
||||
s_query_person_metadata.apply_async(queue='cic-ussd')
|
||||
|
||||
if user.has_valid_pin():
|
||||
last_ussd_session = retrieve_most_recent_ussd_session(phone_number=user.phone_number)
|
||||
|
||||
if last_ussd_session:
|
||||
# get metadata
|
||||
person_metadata = get_cached_data(key=key)
|
||||
|
||||
# get last state
|
||||
last_state = last_ussd_session.state
|
||||
|
||||
# if last state is account_creation_prompt and metadata exists, show start menu
|
||||
if last_state in [
|
||||
'account_creation_prompt',
|
||||
|
||||
@@ -17,7 +17,6 @@ from cic_ussd.chain import Chain
|
||||
from cic_ussd.db import dsn_from_config
|
||||
from cic_ussd.db.models.base import SessionBase
|
||||
from cic_ussd.encoder import PasswordEncoder
|
||||
from cic_ussd.error import InitializationError
|
||||
from cic_ussd.files.local_files import create_local_file_data_stores, json_file_parser
|
||||
from cic_ussd.menu.ussd_menu import UssdMenu
|
||||
from cic_ussd.metadata.signer import Signer
|
||||
@@ -26,8 +25,7 @@ from cic_ussd.operations import (define_response_with_content,
|
||||
process_menu_interaction_requests,
|
||||
define_multilingual_responses)
|
||||
from cic_ussd.phone_number import process_phone_number
|
||||
from cic_ussd.processor import get_default_token_data
|
||||
from cic_ussd.redis import cache_data, create_cached_data_key, InMemoryStore
|
||||
from cic_ussd.redis import InMemoryStore
|
||||
from cic_ussd.requests import (get_request_endpoint,
|
||||
get_request_method)
|
||||
from cic_ussd.runnable.server_base import exportable_parser, logg
|
||||
@@ -109,20 +107,6 @@ Chain.spec = chain_spec
|
||||
UssdStateMachine.states = states
|
||||
UssdStateMachine.transitions = transitions
|
||||
|
||||
# retrieve default token data
|
||||
default_token_data = get_default_token_data()
|
||||
chain_str = Chain.spec.__str__()
|
||||
|
||||
# cache default token for re-usability
|
||||
if default_token_data:
|
||||
cache_key = create_cached_data_key(
|
||||
identifier=chain_str.encode('utf-8'),
|
||||
salt=':cic.default_token_data'
|
||||
)
|
||||
cache_data(key=cache_key, data=json.dumps(default_token_data))
|
||||
else:
|
||||
raise InitializationError(f'Default token data for: {chain_str} not found.')
|
||||
|
||||
|
||||
def application(env, start_response):
|
||||
"""Loads python code for application to be accessible over web server
|
||||
|
||||
@@ -64,7 +64,7 @@ def has_sufficient_balance(state_machine_data: Tuple[str, dict, Account]) -> boo
|
||||
# get cached balance
|
||||
key = create_cached_data_key(
|
||||
identifier=bytes.fromhex(user.blockchain_address[2:]),
|
||||
salt=':cic.balances_data'
|
||||
salt='cic.balances_data'
|
||||
)
|
||||
cached_balance = get_cached_data(key=key)
|
||||
operational_balance = compute_operational_balance(balances=json.loads(cached_balance))
|
||||
|
||||
@@ -176,7 +176,7 @@ def edit_user_metadata_attribute(state_machine_data: Tuple[str, dict, Account]):
|
||||
blockchain_address = user.blockchain_address
|
||||
key = generate_metadata_pointer(
|
||||
identifier=blockchain_address_to_metadata_pointer(blockchain_address=user.blockchain_address),
|
||||
cic_type=':cic.person'
|
||||
cic_type='cic.person'
|
||||
)
|
||||
user_metadata = get_cached_data(key=key)
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ def has_cached_user_metadata(state_machine_data: Tuple[str, dict, Account]):
|
||||
# check for user metadata in cache
|
||||
key = generate_metadata_pointer(
|
||||
identifier=blockchain_address_to_metadata_pointer(blockchain_address=user.blockchain_address),
|
||||
cic_type=':cic.person'
|
||||
cic_type='cic.person'
|
||||
)
|
||||
user_metadata = get_cached_data(key=key)
|
||||
return user_metadata is not None
|
||||
|
||||
@@ -136,7 +136,7 @@ def process_balances_callback(result: list, param: str, status_code: int):
|
||||
blockchain_address = balances_data.get('address')
|
||||
key = create_cached_data_key(
|
||||
identifier=bytes.fromhex(blockchain_address[2:]),
|
||||
salt=':cic.balances_data'
|
||||
salt='cic.balances_data'
|
||||
)
|
||||
cache_data(key=key, data=json.dumps(balances_data))
|
||||
else:
|
||||
@@ -226,7 +226,7 @@ def process_statement_callback(result, param: str, status_code: int):
|
||||
|
||||
# cache account statement
|
||||
identifier = bytes.fromhex(param[2:])
|
||||
key = create_cached_data_key(identifier=identifier, salt=':cic.statement')
|
||||
key = create_cached_data_key(identifier=identifier, salt='cic.statement')
|
||||
data = json.dumps(processed_transactions)
|
||||
|
||||
# cache statement data
|
||||
|
||||
@@ -105,7 +105,7 @@ def test_get_user_metadata(caplog,
|
||||
assert 'Get latest data status: 200' in caplog.text
|
||||
key = generate_metadata_pointer(
|
||||
identifier=identifier,
|
||||
cic_type=':cic.person'
|
||||
cic_type='cic.person'
|
||||
)
|
||||
cached_user_metadata = get_cached_data(key=key)
|
||||
assert cached_user_metadata
|
||||
|
||||
@@ -36,7 +36,7 @@ def test_has_cached_user_metadata(create_in_db_ussd_session,
|
||||
user = create_activated_user
|
||||
key = generate_metadata_pointer(
|
||||
identifier=blockchain_address_to_metadata_pointer(blockchain_address=user.blockchain_address),
|
||||
cic_type=':cic.person'
|
||||
cic_type='cic.person'
|
||||
)
|
||||
cache_data(key=key, data=json.dumps(person_metadata))
|
||||
result = has_cached_user_metadata(state_machine_data=state_machine_data)
|
||||
|
||||
2
apps/cic-ussd/tests/fixtures/user.py
vendored
2
apps/cic-ussd/tests/fixtures/user.py
vendored
@@ -115,6 +115,6 @@ def cached_user_metadata(create_activated_user, init_redis_cache, person_metadat
|
||||
user_metadata = json.dumps(person_metadata)
|
||||
key = generate_metadata_pointer(
|
||||
identifier=blockchain_address_to_metadata_pointer(blockchain_address=create_activated_user.blockchain_address),
|
||||
cic_type=':cic.person'
|
||||
cic_type='cic.person'
|
||||
)
|
||||
cache_data(key=key, data=user_metadata)
|
||||
|
||||
@@ -47,61 +47,54 @@ RUN wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh |
|
||||
ENV NODE_PATH $NVM_DIR/versions/node//v$NODE_VERSION/lib/node_modules
|
||||
ENV PATH $NVM_DIR/versions/node//v$NODE_VERSION/bin:$PATH
|
||||
|
||||
#RUN useradd --create-home grassroots
|
||||
# WORKDIR /home/grassroots
|
||||
# USER grassroots
|
||||
RUN useradd --create-home grassroots
|
||||
WORKDIR /home/grassroots
|
||||
USER grassroots
|
||||
|
||||
ARG pip_extra_args=""
|
||||
ARG pip_index_url=https://pypi.org/simple
|
||||
ARG pip_extra_index_url=https://pip.grassrootseconomics.net:8433
|
||||
ARG cic_base_version=0.1.2b8
|
||||
ARG cic_eth_version=0.11.0b12
|
||||
ARG sarafu_token_version=0.0.1a8
|
||||
ARG sarafu_faucet_version=0.0.3a2
|
||||
RUN pip install --user --index-url https://pypi.org/simple --extra-index-url $pip_extra_index_url \
|
||||
cic-base[full_graph]==$cic_base_version \
|
||||
ARG cic_base_version=0.1.2a79
|
||||
ARG cic_eth_version=0.11.0b8+build.c2286e5c
|
||||
ARG sarafu_faucet_version=0.0.2a28
|
||||
ARG sarafu_token_version=0.0.1a6
|
||||
ARG cic_contracts_version=0.0.2a2
|
||||
RUN pip install --user --index-url https://pypi.org/simple --extra-index-url $pip_extra_index_url cic-base[full_graph]==$cic_base_version \
|
||||
cic-eth==$cic_eth_version \
|
||||
cic-contracts==$cic_contracts_version \
|
||||
sarafu-faucet==$sarafu_faucet_version \
|
||||
sarafu-token==$sarafu_token_version \
|
||||
cic-eth==$cic_eth_version
|
||||
sarafu-token==$sarafu_token_version
|
||||
|
||||
# -------------- begin runtime container ----------------
|
||||
FROM python:3.8.6-slim-buster as runtime-image
|
||||
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y --no-install-recommends gnupg libpq-dev
|
||||
RUN apt-get install -y jq bash iputils-ping socat
|
||||
RUN apt-get install -y --no-install-recommends jq
|
||||
|
||||
COPY --from=compile-image /usr/local/bin/ /usr/local/bin/
|
||||
COPY --from=compile-image /usr/local/etc/cic/ /usr/local/etc/cic/
|
||||
COPY --from=compile-image /usr/local/lib/python3.8/site-packages/ \
|
||||
/usr/local/lib/python3.8/site-packages/
|
||||
|
||||
ENV EXTRA_INDEX_URL https://pip.grassrootseconomics.net:8433
|
||||
# RUN useradd -u 1001 --create-home grassroots
|
||||
# RUN adduser grassroots sudo && \
|
||||
# echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
|
||||
# WORKDIR /home/grassroots
|
||||
RUN useradd --create-home grassroots
|
||||
WORKDIR /home/grassroots
|
||||
# COPY python dependencies to user dir
|
||||
COPY --from=compile-image /home/grassroots/.local .local
|
||||
ENV PATH=/home/grassroots/.local/bin:$PATH
|
||||
|
||||
COPY contract-migration/testdata/pgp testdata/pgp
|
||||
COPY contract-migration/sarafu_declaration.json sarafu_declaration.json
|
||||
COPY contract-migration/keystore keystore
|
||||
COPY contract-migration/envlist .
|
||||
COPY contract-migration/scripts scripts/
|
||||
|
||||
# A shared output dir for environment configs
|
||||
# RUN chown grassroots:grassroots .local/
|
||||
|
||||
RUN mkdir -p /tmp/cic/config
|
||||
# RUN chown grassroots:grassroots /tmp/cic/config
|
||||
RUN chown grassroots:grassroots /tmp/cic/config
|
||||
# A shared output dir for environment configs
|
||||
RUN chmod a+rwx /tmp/cic/config
|
||||
|
||||
COPY contract-migration/*.sh ./
|
||||
# RUN chown grassroots:grassroots -R .
|
||||
RUN chown grassroots:grassroots -R .
|
||||
RUN chmod gu+x *.sh
|
||||
|
||||
# we copied these from the root build container.
|
||||
# this is dumb though...I guess the compile image should have the same user
|
||||
# RUN chown grassroots:grassroots -R /usr/local/lib/python3.8/site-packages/
|
||||
|
||||
# USER grassroots
|
||||
USER grassroots
|
||||
|
||||
ENTRYPOINT [ ]
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
# standard imports
|
||||
import sys
|
||||
import os
|
||||
import logging
|
||||
import json
|
||||
|
||||
# external imports
|
||||
import celery
|
||||
import confini
|
||||
|
||||
# local imports
|
||||
from cic_eth.api import Api
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
logg = logging.getLogger()
|
||||
|
||||
|
||||
script_dir = os.path.realpath(os.path.dirname(__file__))
|
||||
config_dir = os.path.join(script_dir, '..', 'config')
|
||||
config = confini.Config(config_dir, os.environ.get('CONFINI_ENV_PREFIX'))
|
||||
config.process()
|
||||
|
||||
celery_app = celery.Celery(broker=config.get('CELERY_BROKER_URL'), backend=config.get('CELERY_RESULT_URL'), result_extended=True)
|
||||
|
||||
|
||||
class Fmtr(celery.utils.graph.GraphFormatter):
|
||||
|
||||
def label(self, obj):
|
||||
super(Fmtr, self).label(obj)
|
||||
if obj != None:
|
||||
if obj.name == None:
|
||||
raise RuntimeError('task name is not defined. Did you run celery with result_extended=True?')
|
||||
return obj.name
|
||||
|
||||
|
||||
def main():
|
||||
api = Api(
|
||||
config.get('CIC_CHAIN_SPEC'),
|
||||
queue='cic-eth',
|
||||
#callback_param='{}:{}:{}:{}'.format(args.redis_host_callback, args.redis_port_callback, redis_db, redis_channel),
|
||||
#callback_task='cic_eth.callbacks.redis.redis',
|
||||
#callback_queue=args.q,
|
||||
)
|
||||
t = api.create_account(register=False)
|
||||
t.get_leaf()
|
||||
t.build_graph(intermediate=True, formatter=Fmtr()).to_dot(sys.stdout)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -1,5 +1,5 @@
|
||||
cic-base[full_graph]==0.1.2b8
|
||||
sarafu-faucet==0.0.3a2
|
||||
cic-eth==0.11.0b12
|
||||
cic-base[full_graph]==0.1.2b2
|
||||
sarafu-faucet==0.0.2a28
|
||||
cic-eth==0.11.0b10
|
||||
cic-types==0.1.0a10
|
||||
crypto-dev-signer==0.4.14b3
|
||||
|
||||
@@ -99,7 +99,7 @@ export DEV_ETH_SARAFU_TOKEN_ADDRESS=$DEV_ETH_RESERVE_ADDRESS
|
||||
|
||||
# Transfer tokens to gifter address
|
||||
>&2 echo "transfer sarafu tokens to token gifter address"
|
||||
>&2 erc20-transfer -y $keystore_file -i $CIC_CHAIN_SPEC -p $ETH_PROVIDER --token-address $DEV_RESERVE_ADDRESS -w $debug $DEV_ETH_ACCOUNT_SARAFU_GIFTER ${token_amount:0:-1}
|
||||
>&2 eth-transfer -y $keystore_file -i $CIC_CHAIN_SPEC -p $ETH_PROVIDER --token-address $DEV_RESERVE_ADDRESS -w $debug $DEV_ETH_ACCOUNT_SARAFU_GIFTER ${token_amount:0:-1}
|
||||
|
||||
#echo -n 0 > $init_level_file
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ image:
|
||||
entrypoint: [""]
|
||||
|
||||
variables:
|
||||
KANIKO_CACHE_ARGS: "--cache=false --cache-copy-layers=true --cache-ttl=24h"
|
||||
KANIKO_CACHE_ARGS: "--cache=true --cache-copy-layers=true --cache-ttl=24h"
|
||||
CONTEXT: $CI_PROJECT_DIR/apps/
|
||||
|
||||
.py_build_merge_request:
|
||||
|
||||
@@ -76,9 +76,6 @@ services:
|
||||
|
||||
contract-migration:
|
||||
build:
|
||||
args:
|
||||
pip_index_url: ${PIP_DEFAULT_INDEX_URL:-https://pypi.org/simple}
|
||||
pip_extra_args: $PIP_EXTRA_ARGS
|
||||
context: apps/
|
||||
dockerfile: contract-migration/docker/Dockerfile
|
||||
# image: registry.gitlab.com/grassrootseconomics/cic-internal-integration/contract-migration:latest
|
||||
@@ -248,7 +245,6 @@ services:
|
||||
BANCOR_DIR: ${BANCOR_DIR:-/usr/local/share/cic/bancor}
|
||||
CELERY_BROKER_URL: ${CELERY_BROKER_URL:-redis://redis}
|
||||
CELERY_RESULT_URL: ${CELERY_RESULT_URL:-redis://redis}
|
||||
CELERY_DEBUG: ${CELERY_DEBUG:-1}
|
||||
SIGNER_SOCKET_PATH: ${SIGNER_SOCKET_PATH:-ipc:///run/crypto-dev-signer/jsonrpc.ipc}
|
||||
SIGNER_SECRET: ${SIGNER_SECRET:-deadbeef}
|
||||
ETH_ACCOUNT_ACCOUNTS_INDEX_WRITER: ${DEV_ETH_ACCOUNT_ACCOUNTS_INDEX_WRITER:-0xACB0BC74E1686D62dE7DC6414C999EA60C09F0eA}
|
||||
|
||||
Reference in New Issue
Block a user