Compare commits
3 Commits
philip/har
...
contract-m
| Author | SHA1 | Date | |
|---|---|---|---|
| 3ba04d5d6f | |||
| d1e3ada926 | |||
| ce6633d61c |
@@ -1,2 +1 @@
|
||||
from .erc20 import *
|
||||
from .faucet import *
|
||||
|
||||
@@ -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,73 +0,0 @@
|
||||
# standard imports
|
||||
import logging
|
||||
|
||||
# external imports
|
||||
from erc20_faucet import Faucet
|
||||
from chainlib.eth.address import to_checksum_address
|
||||
from chainlib.eth.constant import ZERO_ADDRESS
|
||||
from chainlib.status import Status
|
||||
from hexathon import strip_0x
|
||||
|
||||
# local imports
|
||||
import cic_cache.db as cic_cache_db
|
||||
from .base import TagSyncFilter
|
||||
|
||||
#logg = logging.getLogger().getChild(__name__)
|
||||
logg = logging.getLogger()
|
||||
|
||||
|
||||
class FaucetFilter(TagSyncFilter):
|
||||
|
||||
def __init__(self, chain_spec, sender_address=ZERO_ADDRESS):
|
||||
super(FaucetFilter, self).__init__('give_to', domain='faucet')
|
||||
self.chain_spec = chain_spec
|
||||
self.sender_address = sender_address
|
||||
|
||||
|
||||
def filter(self, conn, block, tx, db_session=None):
|
||||
try:
|
||||
data = strip_0x(tx.payload)
|
||||
except ValueError:
|
||||
return False
|
||||
logg.debug('data {}'.format(data))
|
||||
if Faucet.method_for(data[:8]) == None:
|
||||
return False
|
||||
|
||||
token_sender = tx.inputs[0]
|
||||
token_recipient = data[64+8-40:]
|
||||
logg.debug('token recipient {}'.format(token_recipient))
|
||||
|
||||
f = Faucet(self.chain_spec)
|
||||
o = f.token(token_sender, sender_address=self.sender_address)
|
||||
r = conn.do(o)
|
||||
token = f.parse_token(r)
|
||||
|
||||
f = Faucet(self.chain_spec)
|
||||
o = f.token_amount(token_sender, sender_address=self.sender_address)
|
||||
r = conn.do(o)
|
||||
token_value = f.parse_token_amount(r)
|
||||
|
||||
cic_cache_db.add_transaction(
|
||||
db_session,
|
||||
tx.hash,
|
||||
block.number,
|
||||
tx.index,
|
||||
to_checksum_address(token_sender),
|
||||
to_checksum_address(token_recipient),
|
||||
token,
|
||||
token,
|
||||
token_value,
|
||||
token_value,
|
||||
tx.status == Status.SUCCESS,
|
||||
block.timestamp,
|
||||
)
|
||||
db_session.flush()
|
||||
cic_cache_db.tag_transaction(
|
||||
db_session,
|
||||
tx.hash,
|
||||
self.tag_name,
|
||||
domain=self.tag_domain,
|
||||
)
|
||||
db_session.commit()
|
||||
|
||||
return True
|
||||
@@ -41,7 +41,6 @@ from cic_cache.db import (
|
||||
)
|
||||
from cic_cache.runnable.daemons.filters import (
|
||||
ERC20TransferFilter,
|
||||
FaucetFilter,
|
||||
)
|
||||
|
||||
script_dir = os.path.realpath(os.path.dirname(__file__))
|
||||
@@ -72,7 +71,6 @@ def register_filter_tags(filters, session):
|
||||
session.commit()
|
||||
logg.info('added tag name "{}" domain "{}"'.format(tag[0], tag[1]))
|
||||
except sqlalchemy.exc.IntegrityError:
|
||||
session.rollback()
|
||||
logg.debug('already have tag name "{}" domain "{}"'.format(tag[0], tag[1]))
|
||||
|
||||
|
||||
@@ -114,11 +112,9 @@ def main():
|
||||
logg.info('using trusted address {}'.format(address))
|
||||
|
||||
erc20_transfer_filter = ERC20TransferFilter(chain_spec)
|
||||
faucet_filter = FaucetFilter(chain_spec)
|
||||
|
||||
filters = [
|
||||
erc20_transfer_filter,
|
||||
faucet_filter,
|
||||
]
|
||||
|
||||
session = SessionBase.create_session()
|
||||
|
||||
@@ -17,7 +17,7 @@ RUN apt-get update && \
|
||||
|
||||
# Copy shared requirements from top of mono-repo
|
||||
RUN echo "copying root req file ${root_requirement_file}"
|
||||
RUN pip install $pip_extra_index_url_flag cic-base[full_graph]==0.1.2b9
|
||||
RUN pip install $pip_extra_index_url_flag cic-base[full_graph]==0.1.2a76
|
||||
|
||||
COPY cic-cache/requirements.txt ./
|
||||
COPY cic-cache/setup.cfg \
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
cic-base~=0.1.2b9
|
||||
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
|
||||
|
||||
@@ -22,7 +22,7 @@ from cic_cache.runnable.daemons.filters.erc20 import ERC20TransferFilter
|
||||
logg = logging.getLogger()
|
||||
|
||||
|
||||
def test_erc20_filter(
|
||||
def test_cache(
|
||||
eth_rpc,
|
||||
foo_token,
|
||||
init_database,
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
# standard imports
|
||||
import logging
|
||||
|
||||
# external imports
|
||||
from chainlib.chain import ChainSpec
|
||||
from chainlib.eth.nonce import RPCNonceOracle
|
||||
from chainlib.eth.block import (
|
||||
block_by_hash,
|
||||
Block,
|
||||
)
|
||||
from chainlib.eth.tx import (
|
||||
receipt,
|
||||
unpack,
|
||||
transaction,
|
||||
Tx,
|
||||
)
|
||||
from hexathon import strip_0x
|
||||
from erc20_faucet.faucet import SingleShotFaucet
|
||||
from sqlalchemy import text
|
||||
|
||||
# local imports
|
||||
from cic_cache.db import add_tag
|
||||
from cic_cache.runnable.daemons.filters.faucet import FaucetFilter
|
||||
|
||||
logg = logging.getLogger()
|
||||
|
||||
|
||||
def test_filter_faucet(
|
||||
eth_rpc,
|
||||
eth_signer,
|
||||
foo_token,
|
||||
faucet_noregistry,
|
||||
init_database,
|
||||
list_defaults,
|
||||
contract_roles,
|
||||
agent_roles,
|
||||
tags,
|
||||
):
|
||||
|
||||
chain_spec = ChainSpec('foo', 'bar', 42, 'baz')
|
||||
|
||||
fltr = FaucetFilter(chain_spec, contract_roles['CONTRACT_DEPLOYER'])
|
||||
|
||||
add_tag(init_database, fltr.tag_name, domain=fltr.tag_domain)
|
||||
|
||||
nonce_oracle = RPCNonceOracle(agent_roles['ALICE'], eth_rpc)
|
||||
c = SingleShotFaucet(chain_spec, signer=eth_signer, nonce_oracle=nonce_oracle)
|
||||
(tx_hash_hex, o) = c.give_to(faucet_noregistry, agent_roles['ALICE'], agent_roles['ALICE'])
|
||||
r = eth_rpc.do(o)
|
||||
|
||||
tx_src = unpack(bytes.fromhex(strip_0x(o['params'][0])), chain_spec)
|
||||
|
||||
o = receipt(r)
|
||||
r = eth_rpc.do(o)
|
||||
rcpt = Tx.src_normalize(r)
|
||||
|
||||
assert r['status'] == 1
|
||||
|
||||
o = block_by_hash(r['block_hash'])
|
||||
r = eth_rpc.do(o)
|
||||
block_object = Block(r)
|
||||
|
||||
tx = Tx(tx_src, block_object)
|
||||
tx.apply_receipt(rcpt)
|
||||
|
||||
r = fltr.filter(eth_rpc, block_object, tx, init_database)
|
||||
assert r
|
||||
|
||||
s = text("SELECT x.tx_hash FROM tag a INNER JOIN tag_tx_link l ON l.tag_id = a.id INNER JOIN tx x ON x.id = l.tx_id WHERE a.domain = :a AND a.value = :b")
|
||||
r = init_database.execute(s, {'a': fltr.tag_domain, 'b': fltr.tag_name}).fetchone()
|
||||
assert r[0] == tx.hash
|
||||
@@ -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,9 +20,8 @@ from chainlib.eth.tx import (
|
||||
)
|
||||
from chainlib.chain import ChainSpec
|
||||
from chainlib.error import JSONRPCException
|
||||
from eth_accounts_index.registry import AccountRegistry
|
||||
from eth_accounts_index import AccountsIndex
|
||||
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
|
||||
@@ -134,7 +133,7 @@ def register(self, account_address, chain_spec_dict, writer_address=None):
|
||||
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, AccountRegistry.gas)
|
||||
account_registry = AccountsIndex(chain_spec, signer=rpc_signer, nonce_oracle=nonce_oracle, gas_oracle=gas_oracle)
|
||||
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()
|
||||
|
||||
@@ -186,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()
|
||||
@@ -339,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
|
||||
|
||||
@@ -8,12 +8,14 @@ from chainlib.status import Status as TxStatus
|
||||
from chainlib.eth.address import to_checksum_address
|
||||
from chainlib.eth.error import RequestMismatchException
|
||||
from chainlib.eth.constant import ZERO_ADDRESS
|
||||
from chainlib.eth.erc20 import ERC20
|
||||
from hexathon import (
|
||||
strip_0x,
|
||||
add_0x,
|
||||
)
|
||||
from eth_erc20 import ERC20
|
||||
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)
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ from .base import SyncFilter
|
||||
|
||||
logg = logging.getLogger().getChild(__name__)
|
||||
|
||||
account_registry_add_log_hash = '0x9cc987676e7d63379f176ea50df0ae8d2d9d1141d1231d4ce15b5965f73c9430'
|
||||
account_registry_add_log_hash = '0x5ed3bdd47b9af629827a8d129aa39c870b10c03f0153fe9ddb8e84b665061acd'
|
||||
|
||||
|
||||
class RegistrationFilter(SyncFilter):
|
||||
|
||||
@@ -30,7 +30,7 @@ class TxFilter(SyncFilter):
|
||||
if otx == None:
|
||||
logg.debug('tx {} not found locally, skipping'.format(tx_hash_hex))
|
||||
return None
|
||||
logg.debug('otx filter match on {}'.format(otx.tx_hash))
|
||||
logg.info('tx filter match on {}'.format(otx.tx_hash))
|
||||
db_session.flush()
|
||||
SessionBase.release_session(db_session)
|
||||
s_final_state = celery.signature(
|
||||
|
||||
@@ -12,10 +12,7 @@ import confini
|
||||
import celery
|
||||
|
||||
# local imports
|
||||
from cic_eth.api import (
|
||||
Api,
|
||||
AdminApi,
|
||||
)
|
||||
from cic_eth.api import Api
|
||||
|
||||
logging.basicConfig(level=logging.WARNING)
|
||||
logg = logging.getLogger()
|
||||
@@ -56,13 +53,8 @@ celery_app = celery.Celery(broker=config.get('CELERY_BROKER_URL'), backend=confi
|
||||
queue = args.q
|
||||
|
||||
api = Api(config.get('CIC_CHAIN_SPEC'), queue=queue)
|
||||
admin_api = AdminApi(None)
|
||||
|
||||
def main():
|
||||
t = admin_api.registry()
|
||||
registry = t.get()
|
||||
print('Registry address: {}'.format(registry))
|
||||
|
||||
t = api.default_token()
|
||||
token_info = t.get()
|
||||
print('Default token symbol: {}'.format(token_info['symbol']))
|
||||
|
||||
@@ -10,7 +10,7 @@ version = (
|
||||
0,
|
||||
11,
|
||||
0,
|
||||
'beta.13',
|
||||
'beta.11',
|
||||
)
|
||||
|
||||
version_object = semver.VersionInfo(
|
||||
|
||||
@@ -19,7 +19,7 @@ RUN apt-get update && \
|
||||
apt install -y gcc gnupg libpq-dev wget make g++ gnupg bash procps git
|
||||
|
||||
# Copy shared requirements from top of mono-repo
|
||||
RUN echo "copying root req file: ${root_requirement_file}"
|
||||
RUN echo "copying root req file ${root_requirement_file}"
|
||||
#COPY $root_requirement_file .
|
||||
#RUN pip install -r $root_requirement_file $pip_extra_index_url_flag
|
||||
RUN /usr/local/bin/python -m pip install --upgrade pip
|
||||
@@ -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.2b9
|
||||
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.2b9
|
||||
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.3a3
|
||||
erc20-faucet==0.2.1a4
|
||||
pysha3==1.0.2
|
||||
coincurve==15.0.0
|
||||
potaahto~=0.0.1a2
|
||||
sarafu-faucet==0.0.2a28
|
||||
potaahto~=0.0.1a1
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
"""This package handles account operations."""
|
||||
|
||||
# external imports
|
||||
from cic_eth.api import Api
|
||||
|
||||
# local imports
|
||||
from cic_ussd.operations import (add_tasks_to_tracker,
|
||||
cache_account_creation_task_id,
|
||||
create_or_update_session,
|
||||
define_multilingual_responses)
|
||||
from cic_ussd.menu.ussd_menu import UssdMenu
|
||||
|
||||
|
||||
def create(chain_str: str,
|
||||
external_session_id: str,
|
||||
phone_number: str,
|
||||
service_code: str,
|
||||
user_input: str) -> str:
|
||||
"""This function issues a task to create a blockchain account on cic-eth. It then creates a record of the ussd
|
||||
session corresponding to the creation of the account and returns a response denoting that the user's account is
|
||||
being created.
|
||||
:param chain_str: The chain name and network id.
|
||||
:type chain_str: str
|
||||
:param external_session_id: A unique ID from africastalking.
|
||||
:type external_session_id: str
|
||||
:param phone_number: The phone number for the account to be created.
|
||||
:type phone_number: str
|
||||
:param service_code: The service code dialed.
|
||||
:type service_code: str
|
||||
:param user_input: The input entered by the user.
|
||||
:type user_input: str
|
||||
:return: A response denoting that the account is being created.
|
||||
:rtype: str
|
||||
"""
|
||||
# attempt to create a user
|
||||
cic_eth_api = Api(callback_task='cic_ussd.tasks.callback_handler.process_account_creation_callback',
|
||||
callback_queue='cic-ussd',
|
||||
callback_param='',
|
||||
chain_str=chain_str)
|
||||
creation_task_id = cic_eth_api.create_account().id
|
||||
|
||||
# record task initiation time
|
||||
add_tasks_to_tracker(task_uuid=creation_task_id)
|
||||
|
||||
# cache account creation data
|
||||
cache_account_creation_task_id(phone_number=phone_number, task_id=creation_task_id)
|
||||
|
||||
# find menu to notify user account is being created
|
||||
current_menu = UssdMenu.find_by_name(name='account_creation_prompt')
|
||||
|
||||
# create a ussd session session
|
||||
create_or_update_session(
|
||||
external_session_id=external_session_id,
|
||||
phone=phone_number,
|
||||
service_code=service_code,
|
||||
current_menu=current_menu.get('name'),
|
||||
user_input=user_input)
|
||||
|
||||
# define response to relay to user
|
||||
response = define_multilingual_responses(
|
||||
key='ussd.kenya.account_creation_prompt', locales=['en', 'sw'], prefix='END')
|
||||
return response
|
||||
@@ -1,50 +0,0 @@
|
||||
"""This module defines functions required to query external components of the cic platform for data relevant to
|
||||
accounts on the cic-ussd component.
|
||||
"""
|
||||
|
||||
# external imports
|
||||
import celery
|
||||
from cic_eth.api import Api
|
||||
|
||||
# local imports
|
||||
from cic_ussd.chain import Chain
|
||||
|
||||
|
||||
def person_metadata(blockchain_address: str):
|
||||
"""This function asynchronously queries the metadata server for metadata associated with the person data type and
|
||||
a given blockchain address.
|
||||
:param blockchain_address: Ethereum address of account whose metadata is being queried.
|
||||
:type blockchain_address: str, 0x-hex
|
||||
"""
|
||||
s_query_person_metadata = celery.signature(
|
||||
'cic_ussd.tasks.metadata.query_person_metadata',
|
||||
[blockchain_address]
|
||||
)
|
||||
s_query_person_metadata.apply_async(queue='cic-ussd')
|
||||
|
||||
|
||||
def default_token_data() -> dict:
|
||||
"""This function queries for the default token's data from the cic_eth tasks exposed over its Api class.
|
||||
:return: A dict containing the default token address and it's corresponding symbol.
|
||||
:rtype: dict
|
||||
"""
|
||||
chain_str = Chain.spec.__str__()
|
||||
cic_eth_api = Api(chain_str=chain_str)
|
||||
default_token_request_task = cic_eth_api.default_token()
|
||||
return default_token_request_task.get()
|
||||
|
||||
|
||||
def transactions_statement(blockchain_address: str):
|
||||
"""This function asynchronously queries the cic-eth server to retrieve a chronologically reversed list of
|
||||
transactions for an account.
|
||||
:param blockchain_address: Ethereum address of account whose transactions is being queried.
|
||||
:type blockchain_address:
|
||||
"""
|
||||
chain_str = Chain.spec.__str__()
|
||||
cic_eth_api = Api(
|
||||
chain_str=chain_str,
|
||||
callback_queue='cic-ussd',
|
||||
callback_task='cic_ussd.tasks.callback_handler.process_statement_callback',
|
||||
callback_param=blockchain_address
|
||||
)
|
||||
cic_eth_api.list(address=blockchain_address, limit=9)
|
||||
@@ -33,12 +33,12 @@ class BalanceManager:
|
||||
def get_balances(self, asynchronous: bool = False) -> Union[celery.Task, dict]:
|
||||
"""
|
||||
This function queries cic-eth for an account's balances, It provides a means to receive the balance either
|
||||
asynchronously or synchronously depending on the provided asynchronous value from the function's caller. It
|
||||
returns a dictionary containing network, outgoing and incoming balances when synchronously called.
|
||||
asynchronously or synchronously depending on the provided value for teh asynchronous parameter. It returns a
|
||||
dictionary containing network, outgoing and incoming balances.
|
||||
:param asynchronous: Boolean value checking whether to return balances asynchronously
|
||||
:type asynchronous: bool
|
||||
:return: dict containing network, outgoing and incoming balances | an async result object from celery.
|
||||
:rtype: dict|celery.Task
|
||||
:return:
|
||||
:rtype:
|
||||
"""
|
||||
if asynchronous:
|
||||
cic_eth_api = Api(
|
||||
@@ -47,7 +47,7 @@ class BalanceManager:
|
||||
callback_task='cic_ussd.tasks.callback_handler.process_balances_callback',
|
||||
callback_param=''
|
||||
)
|
||||
return cic_eth_api.balance(address=self.address, token_symbol=self.token_symbol)
|
||||
cic_eth_api.balance(address=self.address, token_symbol=self.token_symbol)
|
||||
else:
|
||||
cic_eth_api = Api(chain_str=self.chain_str)
|
||||
balance_request_task = cic_eth_api.balance(
|
||||
@@ -56,30 +56,27 @@ class BalanceManager:
|
||||
return balance_request_task.get()[0]
|
||||
|
||||
|
||||
def operational_balance(balances: dict) -> float:
|
||||
"""This function computes the operational balance at an instance in the system by providing the difference of the
|
||||
outgoing balance from the sum of incoming and network balances.
|
||||
:param balances: A dictionary containing incoming, outgoing and network balances.
|
||||
:type balances: dict
|
||||
:return: The operational balance of the account at the instance of querying.
|
||||
:rtype: float
|
||||
def compute_operational_balance(balances: dict) -> float:
|
||||
"""This function calculates the right balance given incoming and outgoing
|
||||
:param balances:
|
||||
:type balances:
|
||||
:return:
|
||||
:rtype:
|
||||
"""
|
||||
incoming_balance = balances.get('balance_incoming')
|
||||
outgoing_balance = balances.get('balance_outgoing')
|
||||
network_balance = balances.get('balance_network')
|
||||
|
||||
balance = (network_balance + incoming_balance) - outgoing_balance
|
||||
return from_wei(value=balance)
|
||||
operational_balance = (network_balance + incoming_balance) - outgoing_balance
|
||||
return from_wei(value=operational_balance)
|
||||
|
||||
|
||||
def cached_operational_balance(blockchain_address: str) -> float:
|
||||
"""This function retrieves the cached balances data from redis cache and computes the operational balance from
|
||||
the cached data.
|
||||
:param blockchain_address: Ethereum address of the account whose balance data is being retrieved.
|
||||
:type blockchain_address: str, 0x-hex
|
||||
:return: The operational balance of the account as per cached balance data.
|
||||
:rtype: float
|
||||
:raises CachedDataNotFoundError
|
||||
def get_cached_operational_balance(blockchain_address: str):
|
||||
"""
|
||||
:param blockchain_address:
|
||||
:type blockchain_address:
|
||||
:return:
|
||||
:rtype:
|
||||
"""
|
||||
key = create_cached_data_key(
|
||||
identifier=bytes.fromhex(blockchain_address[2:]),
|
||||
@@ -87,7 +84,7 @@ def cached_operational_balance(blockchain_address: str) -> float:
|
||||
)
|
||||
cached_balance = get_cached_data(key=key)
|
||||
if cached_balance:
|
||||
balance = operational_balance(balances=json.loads(cached_balance))
|
||||
return balance
|
||||
operational_balance = compute_operational_balance(balances=json.loads(cached_balance))
|
||||
return operational_balance
|
||||
else:
|
||||
raise CachedDataNotFoundError('Cached operational balance not found.')
|
||||
@@ -51,19 +51,17 @@ ENV PATH $NVM_DIR/versions/node//v$NODE_VERSION/bin:$PATH
|
||||
# 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 --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 --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
|
||||
|
||||
@@ -27,6 +27,7 @@ from chainlib.eth.block import (
|
||||
)
|
||||
from chainlib.hash import keccak256_string_to_hex
|
||||
from chainlib.eth.address import to_checksum_address
|
||||
from chainlib.eth.erc20 import ERC20
|
||||
from chainlib.eth.gas import OverrideGasOracle
|
||||
from chainlib.eth.nonce import RPCNonceOracle
|
||||
from chainlib.eth.tx import TxFactory
|
||||
@@ -36,7 +37,6 @@ from chainlib.chain import ChainSpec
|
||||
from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer
|
||||
from crypto_dev_signer.keystore.dict import DictKeystore
|
||||
from cic_types.models.person import Person
|
||||
from eth_erc20 import ERC20
|
||||
|
||||
|
||||
logging.basicConfig(level=logging.WARNING)
|
||||
|
||||
@@ -27,6 +27,7 @@ from chainlib.eth.block import (
|
||||
)
|
||||
from chainlib.hash import keccak256_string_to_hex
|
||||
from chainlib.eth.address import to_checksum_address
|
||||
from chainlib.eth.erc20 import ERC20
|
||||
from chainlib.eth.gas import OverrideGasOracle
|
||||
from chainlib.eth.nonce import RPCNonceOracle
|
||||
from chainlib.eth.tx import TxFactory
|
||||
@@ -36,7 +37,6 @@ from chainlib.chain import ChainSpec
|
||||
from crypto_dev_signer.eth.signer import ReferenceSigner as EIP155Signer
|
||||
from crypto_dev_signer.keystore.dict import DictKeystore
|
||||
from cic_types.models.person import Person
|
||||
from eth_erc20 import ERC20
|
||||
|
||||
|
||||
logging.basicConfig(level=logging.WARNING)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
cic-base[full_graph]==0.1.2b9
|
||||
sarafu-faucet==0.0.3a3
|
||||
cic-eth==0.11.0b13
|
||||
cic-types==0.1.0a11
|
||||
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
|
||||
|
||||
@@ -34,6 +34,7 @@ from chainlib.eth.block import (
|
||||
)
|
||||
from chainlib.hash import keccak256_string_to_hex
|
||||
from chainlib.eth.address import to_checksum_address
|
||||
from chainlib.eth.erc20 import ERC20
|
||||
from chainlib.eth.gas import (
|
||||
OverrideGasOracle,
|
||||
balance,
|
||||
@@ -45,8 +46,7 @@ from cic_types.models.person import (
|
||||
Person,
|
||||
generate_metadata_pointer,
|
||||
)
|
||||
from erc20_faucet import Faucet
|
||||
from eth_erc20 import ERC20
|
||||
from erc20_single_shot_faucet import SingleShotFaucet
|
||||
|
||||
logging.basicConfig(level=logging.WARNING)
|
||||
logg = logging.getLogger()
|
||||
@@ -224,7 +224,7 @@ class Verifier:
|
||||
self.api = cic_eth_api
|
||||
self.data_dir = data_dir
|
||||
self.exit_on_error = exit_on_error
|
||||
self.faucet_tx_factory = Faucet(chain_spec, gas_oracle=gas_oracle)
|
||||
self.faucet_tx_factory = SingleShotFaucet(chain_spec, gas_oracle=gas_oracle)
|
||||
|
||||
verifymethods = []
|
||||
for k in dir(self):
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user