move files out of scripts folder to their own dir

This commit is contained in:
2021-05-20 14:31:08 +00:00
parent 1676addbeb
commit a31b7bc9cd
47 changed files with 67 additions and 3 deletions

View File

@@ -0,0 +1,37 @@
# standard imports
import logging
# external imports
from cic_eth.api.api_task import Api
logging.basicConfig(level=logging.WARNING)
logg = logging.getLogger()
queue = 'cic-eth'
name = 'account'
def do(token_pair, sender, recipient, sender_balance, aux, block_number, tx_index):
"""Triggers creation and registration of new account through the custodial cic-eth component.
It expects the following aux parameters to exist:
- redis_host_callback: Redis host name exposed to cic-eth, for callback
- redis_port_callback: Redis port exposed to cic-eth, for callback
- redis_db: Redis db, for callback
- redis_channel: Redis channel, for callback
- chain_spec: Chain specification for the chain to execute the transfer on
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)
return (None, t, sender_balance, )

View File

@@ -0,0 +1,37 @@
# standard imports
import logging
logging.basicConfig(level=logging.WARNING)
logg = logging.getLogger()
def do(token_pair, sender, recipient, sender_balance, aux, block_number, tx_index):
"""Defines the function signature for a traffic generator. The method itself only logs the input parameters.
If the error position in the return tuple is not None, the calling code should consider the generation as failed, and not count it towards the limit of simultaneous traffic items that can be simultaneously in flight.
If the task_id position in the return tuple is None, the calling code should interpret the traffic item to have been synchronously completed, and not count it towards the limit of simultaneous traffic items that can be simultaneously in flight.
The balance element of the result is the balance dict passed as argument, with fields updated according to the expected delta as a result of the operation. However, in the event that the generator module dispatches an asynchronous event then there is no guarantee that this balance will actually be the correct result. The caller should take care to periodically re-sync balance from the upstream.
:param token_pair: Source and destination tokens for the traffic item.
:type token_pair: 2-element tuple with cic_registry.token.Token
:param sender: Sender address
:type sender: str, 0x-hex
:param recipient: Recipient address
:type recipient: str, 0x-hex
:param sender_balance: Sender balance in full decimal resolution
:type sender_balance: complex balance dict
:param aux: Custom parameters defined by traffic generation client code
:type aux: dict
:param block_number: Syncer block number position at time of method call
:type block_number: number
:param tx_index: Syncer block transaction index position at time of method call
:type tx_index: number
:raises KeyError: Missing required aux element
:returns: Exception|None, task_id|None and adjusted_sender_balance respectively
:rtype: tuple
"""
logg.debug('running {} {} {} {} {} {} {} {}'.format(__name__, token_pair, sender, recipient, sender_balance, aux, block_number, tx_index))
return (None, None, sender_balance, )

View File

@@ -0,0 +1,51 @@
# standard imports
import logging
import random
# external imports
from cic_eth.api.api_task import Api
logging.basicConfig(level=logging.WARNING)
logg = logging.getLogger()
queue = 'cic-eth'
name = 'erc20_transfer'
def do(token_pair, sender, recipient, sender_balance, aux, block_number, tx_index):
"""Triggers an ERC20 token transfer through the custodial cic-eth component, with a randomly chosen amount in integer resolution.
It expects the following aux parameters to exist:
- redis_host_callback: Redis host name exposed to cic-eth, for callback
- redis_port_callback: Redis port exposed to cic-eth, for callback
- redis_db: Redis db, for callback
- redis_channel: Redis channel, for callback
- chain_spec: Chain specification for the chain to execute the transfer on
See local.noop.do for details on parameters and return values.
"""
logg.debug('running {} {} {} {}'.format(__name__, token_pair, sender, recipient))
decimals = token_pair[0].decimals()
sender_balance_value = sender_balance['balance_network'] - sender_balance['balance_outgoing']
balance_units = int(sender_balance_value / decimals)
if balance_units <= 0:
return (AttributeError('sender {} has zero balance'), None, 0,)
spend_units = random.randint(1, balance_units)
spend_value = spend_units * decimals
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.transfer(sender, recipient, spend_value, token_pair[0].symbol())
sender_balance['balance_outgoing'] += spend_value
return (None, t, sender_balance,)