Relayer Autogenerated Python Documentation
See the full Github repository for more details. These docs are autogenerated with Sphinx.
Submodules¶
TNLS-Relayers.base_interface module¶
class base_interface.BaseChainInterface¶
Bases: ABC
Base class for all chain interfaces Governs transaction retrieval and creation
abstract get_last_block()¶
Retrieves the current block height of the chain
abstract get_transactions(address, height=None)¶
Retrieves all transactions from the chain that fit interface-dependent filters
abstract sign_and_send_transaction(tx)¶
Given a raw transaction, signs it and sends it to the chain
Parameters:
tx – the raw transaction to be sent to the chain
class base_interface.BaseContractInterface¶
Bases: ABC
Base class for all contract interfaces Governs contract interaction, execution, and event parsing.
address = None¶abstract call_function(function_name, *args)¶
Given a function in a contract, and the arguments to that function, calls it on chain
Parameters:
function_name – the name of the contract function to call
*args – the (potentially many) arguments to pass to that function
abstract parse_event_from_txn(event_name, txn) → List[Task]¶
Given a transaction, outputs all the events of a particular name that were emitted in that transaction
Parameters:
event_name – the event to look for
txn – the transaction to parse
Returns: a list of Tasks corresponding to the events
class base_interface.Task(task_dict)¶
Bases: object
Task class representing an interchain message
task_destination_network is the network where the message should be routed.
base_interface.to_dict(dict_to_parse)¶
deeply converts an attribute dictionary to a json serializable dict
sourced from SO on attribute dictionaries:
Parameters:
dict_to_parse – the dict to parse
Returns: a serializable dict
base_interface.translate_dict(dict_to_translate, translation_mechanism)¶
Translates a dictionary from one format to another (for interchain translation)
Parameters:
dict_to_translate – the dictionary to translate
translation_mechanism – the mechanism to use for translation
Returns: the translated dictionary
TNLS-Relayers.eth_interface module¶
class eth_interface.EthContract(interface, address, abi, **_kwargs)¶
Bases: BaseContractInterface
Implementation of BaseContractInterface for eth.
call_function(function_name, *args)¶
See base_interface.py for documentation
get_function(function_name)¶
Gets a particular function from the contract.
Parameters:
function_name – The name of the function to get.
parse_event_from_txn(event_name, txn) → List[Task]¶
See base_interface.py for documentation
class eth_interface.EthInterface(private_key='', address='', provider=None, **_kwargs)¶
Bases: BaseChainInterface
Implementaion of BaseChainInterface for eth.
create_transaction(contract_function, *args, **kwargs)¶
See base_interface.py for documentation
get_last_block()¶
Gets the number of the most recent block
get_last_txs(block_number=None, address=None)¶
Gets the transactions from a particular block for a particular address.
Parameters:
block_number – Which block to get
address – Which address to get transactions for
Returns: a list of transaction receipts
get_transactions(address, height=None)¶
See base_interface.py for documentation
sign_and_send_transaction(tx)¶
See base_interface.py for documentation
TNLS-Relayers.relayer module¶
Overall execution:
poller:
every N seconds: poll both sides for gateway transactions parse transactions into list of objects save each object in task list spin up thread to handle routing each object to the right location
Individual thread: for each object: get destination network verify signature? stringify object as json send json string to destination network
class relayer.Relayer(dict_of_names_to_interfaces: Dict[str, Tuple[BaseChainInterface, BaseContractInterface, str, str]], num_loops=None)¶
Bases: object
poll_for_transactions()¶
Polls for transactions on all interfaces Updates task list with found events
route_transaction(task: Task)¶
Given a Task, routes it where it’s supposed to go
task: the Task to be routed
run()¶
Runs the central relayer event loop: poll for transactions, log them, handle transactions sleep
task_list_handle()¶
Spins up threads to handle each task in the task list
TNLS-Relayers.scrt_interface module¶
class scrt_interface.SCRTContract(interface, address, abi)¶
Bases: BaseContractInterface
Implements the BaseContractInterface standard for the Secret Network
call_function(function_name, *args)¶
Calls the given function with the given args
Parameters:
function_name – which function to call
*args – the args to pass
Returns: the result of the function call
construct_txn(function_schema, function_name, args)¶
Constructs a transaction for the given function_schema, function name and args
Parameters:
function_schema – Dict[str, List[str]], the schema for the function
function_name – str, the name of the function to be called
args – Union[List[str], Dict[str, str]], the args to be passed to the function
Examples shown in relayer_tests/interface_tests/test_scrt_interface.py, under the test_basic_txn_construction and test_dict_txn_construction tests
Returns:
a StdSignMsg (unsigned) transaction for the given function_schema, function name and args
get_function(function_name)¶
Returns the function schema for the given function name
Parameters:
function_name – which function to get a list of args for
Returns:
the schema for the specific function
parse_event_from_txn(event_name: str, logs: List[TxLog])¶
Parses the given event from the given logs
Parameters:
event_name – which event to parse
logs – the logs to parse from
Returns: a list of tasks corresponding to parsed events
class scrt_interface.SCRTInterface(private_key='', address=None, api_url='https://api.pulsar.scrttestnet.com', chain_id='pulsar-2', provider=None, **kwargs)¶
Bases: BaseChainInterface
Implementation of the BaseChainInterface standard for the Secret Network
get_last_block()¶
Returns the most recent block height Returns: the height of the current block
get_transactions(address, height=None)¶
Returns all txn logs from the given height for the given address
Parameters:
address – the address to get the txn logs for
height – which height to get the txn logs from, if None, get all txn logs from the current height
Returns:
a list of txn logs for the given address/height
sign_and_send_transaction(tx)¶
Signs and broadcasts a transaction to the network, returns the broadcast receipt
Parameters:
tx[StdTx] – transaction to be signed and sent
Returns:
the receipt of the broadcast transaction
TNLS-Relayers.web_app module¶
web_app.app_factory(config_filename, config_file_converter=<function generate_full_config>, num_loops=None)¶
Creates a Flask app with a relayer running on the backend
Parameters:
config_filename – Which filepath to pull config from
config_file_converter – How to convert that config file into relayer config
num_loops – How many times the relayer should run before shutting down, None=Infinity
Returns: a flask app
web_app.generate_eth_config(config_dict, provider=None)¶
Converts a config dict into a tuple of (chain_interface, contract_interface, event_name, function_name) for ethereum
Parameters:
config_dict – a dict containing contract address, contract schema, and wallet address
provider – an optional API client
Returns: the relevant tuple of chain, contract, event, and function
web_app.generate_full_config(config_file, provider_pair=None)¶
Takes in a yaml filepath and generates a config dict for eth and scrt relays
Parameters:
config_file – the path to the relevant config file
provider_pair – a pair of scrt and eth providers, optional
Returns:
a dict mapping scrt and eth to their respective configs
web_app.generate_scrt_config(config_dict, provider=None)¶
Converts a config dict into a tuple of (chain_interface, contract_interface, event_name, function_name) for secret
Parameters:
config_dict – a dict containing contract address, contract schema, and wallet address
provider – an optional API client
Returns: the relevant tuple of chain, contract, event, and function
web_app.index()¶
Returns: a string form of the relayer
web_app.keys()¶
Returns: the current encryption and verification keys
web_app.task_json()¶
Returns: The status of the relayer
Last updated