feat: Split and improve contract migration steps

This commit is contained in:
Louis Holbrook
2021-10-20 15:02:36 +00:00
committed by Philip Wafula
parent 8f1afa094d
commit 13fb67d2d8
96 changed files with 2147 additions and 1327 deletions

View File

@@ -3,6 +3,10 @@ from chainlib.jsonrpc import JSONRPCException
from eth_erc20 import ERC20
from eth_accounts_index import AccountsIndex
from eth_token_index import TokenUniqueSymbolIndex
import logging
logg = logging.getLogger(__name__)
class ERC20Token:
@@ -46,7 +50,8 @@ class IndexCache:
try:
r = conn.do(o)
entries.append(self.parse(r, conn))
except JSONRPCException:
except JSONRPCException as e:
logg.debug('foo {}'.format(e))
return entries
i += 1

View File

@@ -11,6 +11,18 @@ queue = 'cic-eth'
name = 'account'
def create_user(chain_spec, redis_host_callback, redis_port_callback, redis_db, redis_channel):
api = Api(
str(chain_spec),
queue=queue,
callback_param='{}:{}:{}:{}'.format(redis_host_callback, redis_port_callback, redis_db, redis_channel),
callback_task='cic_eth.callbacks.redis.redis',
callback_queue=queue,
)
return api.create_account(register=True)
def do(token_pair, sender, recipient, sender_balance, aux, block_number):
"""Triggers creation and registration of new account through the custodial cic-eth component.
@@ -24,14 +36,6 @@ def do(token_pair, sender, recipient, sender_balance, aux, block_number):
See local.noop.do for details on parameters and return values.
"""
logg.debug('running {} {} {}'.format(__name__, token_pair, sender, recipient))
api = Api(
str(aux['chain_spec']),
queue=queue,
callback_param='{}:{}:{}:{}'.format(aux['redis_host_callback'], aux['redis_port_callback'], aux['redis_db'], aux['redis_channel']),
callback_task='cic_eth.callbacks.redis.redis',
callback_queue=queue,
)
t = api.create_account(register=True)
t = create_user(aux['chain_spec'], aux['redis_host_callback'], aux['redis_port_callback'], aux['redis_db'], aux['redis_channel'])
return (None, t, sender_balance, )

View File

@@ -21,6 +21,9 @@ import chainlib.eth.cli
import cic_eth.cli
from cic_eth.cli.chain import chain_interface
from chainlib.eth.constant import ZERO_ADDRESS
from eth_accounts_index import AccountsIndex
from erc20_faucet import Faucet
from cic_eth.api import Api
# local imports
#import common
@@ -108,6 +111,12 @@ def main():
raise NetworkError('AccountRegistry value missing from contract registry {}'.format(config.get('CIC_REGISTRY_ADDRESS')))
logg.info('using account registry {}'.format(account_registry))
account_cache = AccountRegistryCache(chain_spec, account_registry)
faucet = registry.lookup('Faucet')
if faucet == ZERO_ADDRESS:
logg.warning('Faucet entry missing from value missing from contract registry {}. New account registrations will need external mechanism for initial token balances.'.format(config.get('CIC_REGISTRY_ADDRESS')))
else:
logg.info('using faucet {}'.format(faucet))
# Set up provisioner for common task input data
TrafficProvisioner.oracles['token'] = token_cache
@@ -124,6 +133,27 @@ def main():
syncer = HeadSyncer(syncer_backend, chain_interface, block_callback=handler.refresh)
syncer.add_filter(handler)
# bootstrap two accounts if starting from scratch
c = AccountsIndex(chain_spec)
o = c.entry_count(account_registry)
r = conn.do(o)
logg.debug('entry count {}'.format(c.parse_entry_count(r)))
if c.parse_entry_count(r) == 0:
if faucet == ZERO_ADDRESS:
raise ValueError('No accounts exist in network and no faucet exists. It will be impossible for any created accounts to trade.')
c = Faucet(chain_spec)
o = c.token_amount(faucet)
r = conn.do(o)
if c.parse_token_amount(r) == 0:
raise ValueError('No accounts exist in network and faucet amount is set to 0. It will be impossible for any created accounts to trade.')
api = Api(str(chain_spec), queue=config.get('CELERY_QUEUE'))
api.create_account(register=True)
api.create_account(register=True)
syncer.loop(1, conn)