Rehabilitate traffic script

This commit is contained in:
nolash 2021-10-17 14:30:42 +02:00
parent 0b2f22c416
commit ea3c75e755
Signed by untrusted user who does not match committer: lash
GPG Key ID: 21D2E7BB88C2A746
9 changed files with 91 additions and 32 deletions

View File

@ -59,12 +59,23 @@ function deploy_token_erc20_demurrage_token() {
TOKEN_ADDRESS=`erc20-demurrage-token-deploy $fee_price_arg -p $RPC_PROVIDER -y $WALLET_KEY_FILE -i $CHAIN_SPEC --name "$TOKEN_NAME" --symbol $TOKEN_SYMBOL $DEV_DEBUG_FLAG -ww -s`
}
function deploy_accounts_index() {
# Deploy accounts index contact
>&2 echo -e "\033[;96mDeploy accounts index contract for token $TOKEN_SYMBOL\033[;39m"
DEV_ACCOUNTS_INDEX_ADDRESS=`okota-accounts-index-deploy $gas_price_arg -u -s -w -y $WALLET_KEY_FILE -i $CHAIN_SPEC -p $RPC_PROVIDER $DEV_DEBUG_FLAG --address-declarator $DEV_ADDRESS_DECLARATOR --token-address $1`
if [ -z "$have_default_token" ]; then
>&2 echo -e "\033[;96mAdd acccounts index record for default token to contract registry\033[;39m"
r=`eth-contract-registry-set $fee_price_arg -s -u -w -y $WALLET_KEY_FILE -e $CIC_REGISTRY_ADDRESS -i $CHAIN_SPEC -p $RPC_PROVIDER $DEV_DEBUG_FLAG --identifier AccountRegistry $DEV_ACCOUNTS_INDEX_ADDRESS`
add_pending_tx_hash $r
fi
}
function deploy_minter_faucet() {
FAUCET_AMOUNT=${FAUCET_AMOUNT:-0}
# Token faucet contract
>&2 echo -e "\033[;96mDeploy token faucet contract\033[;39m"
>&2 echo -e "\033[;96mDeploy token faucet contract for token $TOKEN_SYMBOL\033[;39m"
accounts_index_address=`eth-contract-registry-list -u -i $CHAIN_SPEC -p $RPC_PROVIDER -e $CIC_REGISTRY_ADDRESS $DEV_DEBUG_FLAG --raw AccountRegistry`
faucet_address=`sarafu-faucet-deploy $fee_price_arg -s -y $WALLET_KEY_FILE -i $CHAIN_SPEC -p $RPC_PROVIDER -w $DEV_DEBUG_FLAG --account-index-address $accounts_index_address $1`
@ -78,7 +89,6 @@ function deploy_minter_faucet() {
add_pending_tx_hash $r
fi
>&2 echo -e "\033[;96mSet faucet as token minter\033[;39m"
r=`giftable-token-minter -s -u $fee_price_arg -w -y $WALLET_KEY_FILE -e $TOKEN_ADDRESS -i $CHAIN_SPEC -p $RPC_PROVIDER $DEV_DEBUG_FLAG $faucet_address`
add_pending_tx_hash $r
@ -95,17 +105,21 @@ if [ -z "$have_default_token" ]; then
fi
>&2 echo -e "\033[;96mAdd token to token index\033[;39m"
>&2 echo -e "\033[;96mAdd token symbol $TOKEN_SYMBOL to token address $TOKEN_ADDRESS mapping to token index\033[;39m"
token_index_address=`eth-contract-registry-list -u -i $CHAIN_SPEC -p $RPC_PROVIDER -e $CIC_REGISTRY_ADDRESS $DEV_DEBUG_FLAG --raw TokenRegistry`
r=`eth-token-index-add $fee_price_arg -s -u -w -y $WALLET_KEY_FILE -i $CHAIN_SPEC -p $RPC_PROVIDER $DEV_DEBUG_FLAG -e $token_index_address $TOKEN_ADDRESS`
add_pending_tx_hash $r
>&2 echo -e "\033[;96mMinting $DEV_TOKEN_MINT_AMOUNT tokens\033[;39m"
TOKEN_MINT_AMOUNT=${TOKEN_MINT_AMOUNT:-${DEV_TOKEN_MINT_AMOUNT}}
>&2 echo -e "\033[;96mMinting $TOKEN_MINT_AMOUNT tokens\033[;39m"
r=`giftable-token-gift $fee_price_arg -p $RPC_PROVIDER -y $WALLET_KEY_FILE -i $CHAIN_SPEC -u $DEV_DEBUG_FLAG -s -w -e $TOKEN_ADDRESS "$DEV_TOKEN_MINT_AMOUNT"`
add_pending_tx_hash $r
# Create accounts index for default token
deploy_accounts_index $TOKEN_ADDRESS
# Connect a minter component if defined
TOKEN_MINTER_MODE=${TOKEN_MINTER_MODE:-"faucet"}
if [ -z "$TOKEN_MINTER_MODE" ]; then

View File

@ -18,33 +18,39 @@ fi
must_address "$CIC_REGISTRY_ADDRESS" "registry"
must_eth_rpc
# get required addresses from registries
token_index_address=`eth-contract-registry-list -u -i $CHAIN_SPEC -p $RPC_PROVIDER -e $CIC_REGISTRY_ADDRESS $DEV_DEBUG_FLAG --raw TokenRegistry`
account_index_address=`eth-contract-registry-list -u -i $CHAIN_SPEC -p $RPC_PROVIDER -e $CIC_REGISTRY_ADDRESS $DEV_DEBUG_FLAG --raw AccountRegistry`
accounts_index_address=`eth-contract-registry-list -u -i $CHAIN_SPEC -p $RPC_PROVIDER -e $CIC_REGISTRY_ADDRESS $DEV_DEBUG_FLAG --raw AccountRegistry`
reserve_address=`eth-token-index-list -i $CHAIN_SPEC -u -p $RPC_PROVIDER -e $token_index_address $DEV_DEBUG_FLAG --raw $CIC_DEFAULT_TOKEN_SYMBOL`
REDIS_HOST_CALLBACK=${REDIS_HOST_CALLBACK:-localhost}
REDIS_PORT_CALLBACK=${REDIS_PORT_CALLBACK:-6379}
#REDIS_HOST=${REDIS_HOST:-$REDIS_HOST_CALLBACK}
#REDIS_PORT=${REDIS_PORT:-$REDIS_PORT_CALLBACK}
REDIS_HOST_CALLBACK=${REDIS_HOST_CALLBACK:-$REDIS_HOST}
REDIS_PORT_CALLBACK=${REDIS_PORT_CALLBACK:-$REDIS_PORT}
>&2 echo -e "\033[;96mcreate account for gas gifter\033[;39m"
gas_gifter=`cic-eth-create --redis-timeout 120 $DEV_DEBUG_FLAG --redis-host-callback $REDIS_HOST_CALLBACK --redis-port-callback $REDIS_PORT_CALLBACK --no-register`
cic-eth-tag -i $CHAIN_SPEC GAS_GIFTER $gas_gifter
>&2 echo -e "\033[;96mcreate account for accounts index writer\033[;39m"
accounts_index_writer=`cic-eth-create --redis-timeout 120 $DEV_DEBUG_FLAG --redis-host-callback $REDIS_HOST_CALLBACK --redis-port-callback $REDIS_PORT_CALLBACK --no-register`
cic-eth-tag -i $CHAIN_SPEC ACCOUNT_REGISTRY_WRITER $accounts_index_writer
# Assign system writer for accounts index
>&2 echo -e "\033[;96mEnable accounts index writer $accounts_index_writer to writer to accounts index contract at $accounts_index_address\033[;39m"
r=`eth-accounts-index-writer -s -w -u -i $CHAIN_SPEC -p $RPC_PROVIDER -e $accounts_index_address $DEV_DEBUG_FLAG $accounts_index_writer`
add_pending_tx_hash $r
# Transfer gas to custodial gas provider adddress
>&2 echo -e "\033[;96mGift gas to gas gifter\033[;39m"
>&2 echo -e "\033[;96mGift gas to gas gifter $gas_gifter\033[;39m"
echo "eth-gas -s -u -y $WALLET_KEY_FILE -i $CHAIN_SPEC -p $RPC_PROVIDER -w $DEV_DEBUG_FLAG -a $gas_gifter $DEV_GAS_AMOUNT"
r=`eth-gas -s -u -y $WALLET_KEY_FILE -i $CHAIN_SPEC -p $RPC_PROVIDER -w $DEV_DEBUG_FLAG -a $gas_gifter $DEV_GAS_AMOUNT`
add_pending_tx_hash $r
>&2 echo -e "\033[;96mgift gas to accounts index owner\033[;39m"
>&2 echo -e "\033[;96mgift gas to accounts index owner $accounts_index_writer\033[;39m"
# for now we are using the same key for both
DEV_ETH_ACCOUNT_ACCOUNT_REGISTRY_WRITER=$DEV_ETH_ACCOUNT_CONTRACT_DEPLOYER
r=`eth-gas -s -u -y $WALLET_KEY_FILE -i $CHAIN_SPEC -p $RPC_PROVIDER -w $DEV_DEBUG_FLAG -a $DEV_ETH_ACCOUNT_ACCOUNT_REGISTRY_WRITER $DEV_GAS_AMOUNT`
r=`eth-gas -s -u -y $WALLET_KEY_FILE -i $CHAIN_SPEC -p $RPC_PROVIDER -w $DEV_DEBUG_FLAG -a $accounts_index_writer $DEV_GAS_AMOUNT`
add_pending_tx_hash $r

View File

@ -1,7 +1,6 @@
[dev]
eth_account_contract_deployer =
token_mint_amount = 10000000000000000000000000000000000
faucet_amount = 0
gas_amount = 100000000000000000000000
eth_gas_price =
data_dir =
@ -21,8 +20,6 @@ result_url =
[redis]
host =
port =
host_callback =
port_callback =
[cic]
registry_address =

View File

@ -11,4 +11,4 @@ sarafu-faucet>=0.0.7a2,<0.1.0
confini>=0.4.2rc3,<1.0.0
crypto-dev-signer>=0.4.15rc2,<=0.4.15
eth-token-index>=0.2.4a1,<=0.3.0
okota>=0.2.4a5,<0.3.0
okota>=0.2.4a13,<0.3.0

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)

View File

@ -1,11 +1,11 @@
sarafu-faucet~=0.0.7a2
cic-eth[tools]~=0.12.4a8
cic-types~=0.1.0a15
crypto-dev-signer~=0.4.15a7
cic-eth[tools]~=0.12.4a12
cic-types~=0.2.0a1
funga>=0.5.1a1,<=0.5.15
faker==4.17.1
chainsyncer~=0.0.6a3
chainlib-eth~=0.0.9a14
eth-address-index~=0.2.3a4
chainlib-eth~=0.0.9rc4
eth-address-index~=0.2.4a1
eth-contract-registry~=0.6.3a3
eth-accounts-index~=0.1.2a3
eth-erc20~=0.1.2a3

View File

@ -69,6 +69,9 @@ services:
TOKEN_SUPPLY_LIMIT: $TOKEN_SUPPLY_LIMIT
TOKEN_DEMURRAGE_LEVEL: $TOKEN_DEMURRAGE_LEVEL
TOKEN_SINK_ADDRESS: $TOKEN_SINK_ADDRESS
REDIS_HOST_CALLBACK: ${REDIS_HOST_CALLBACK:-redis}
REDIS_PORT_CALLBACK: ${REDIS_PORT_CALLBACK:-6379}
FAUCET_AMOUNT: ${FAUCET_AMOUNT:-0}
command: ["./run_job.sh"]
depends_on:
- evm