Example #1
0
File: relay.py Project: JTpku/relay
    def get_trustline_events(
        self,
        network_address: str,
        user_address: str,
        counterparty_address: str,
        type: str = None,
        from_block: int = 0,
    ):
        if type is None:
            event_types = None
        else:
            event_types = [type]

        ethindex = ethindex_db.CurrencyNetworkEthindexDB(
            ethindex_db.connect(""),
            address=network_address,
            standard_event_types=currency_network_events.trustline_event_types,
            event_builders=currency_network_events.event_builders,
            from_to_types=currency_network_events.from_to_types,
        )

        events = ethindex.get_trustline_events(
            network_address,
            user_address,
            counterparty_address,
            event_types,
            from_block=from_block,
        )
        return events
Example #2
0
File: relay.py Project: JTpku/relay
 def get_ethindex_db_for_exchange(self, address: Optional[str] = None):
     """return an EthindexDB instance
     This is being used from relay.api to query for events.
     """
     return ethindex_db.ExchangeEthindexDB(
         ethindex_db.connect(""),
         address=address,
         standard_event_types=exchange_events.standard_event_types,
         event_builders=exchange_events.event_builders,
         from_to_types=exchange_events.from_to_types,
     )
Example #3
0
File: relay.py Project: JTpku/relay
 def get_ethindex_db_for_unw_eth(self, address: str):
     """return an EthindexDB instance
     This is being used from relay.api to query for events.
     """
     return ethindex_db.EthindexDB(
         ethindex_db.connect(""),
         address=address,
         standard_event_types=unw_eth_events.standard_event_types,
         event_builders=unw_eth_events.event_builders,
         from_to_types=unw_eth_events.from_to_types,
     )
Example #4
0
    def _start_sync_graphs_via_feed(self):
        conn = ethindex_db.connect("")
        updates_getter = graph_update_getter()

        def sync():
            while True:
                graph_updates = updates_getter(conn)
                self._apply_feed_update_on_graph(graph_updates)
                self._publish_feed_update_events(graph_updates)
                gevent.sleep(self.config["trustline_index"]["sync_interval"])

        greenlet = gevent.Greenlet.spawn(sync)
        greenlet.link_exception(lambda *args: sys.exit("Graph sync greenlet died"))
Example #5
0
File: relay.py Project: JTpku/relay
 def get_ethindex_db_for_currency_network(
     self,
     network_address: Optional[str] = None
 ) -> ethindex_db.CurrencyNetworkEthindexDB:
     """return an EthindexDB instance.
     This is being used from relay.api to query for events.
     """
     return ethindex_db.CurrencyNetworkEthindexDB(
         ethindex_db.connect(""),
         address=network_address,
         standard_event_types=currency_network_events.standard_event_types,
         event_builders=currency_network_events.event_builders,
         from_to_types=currency_network_events.from_to_types,
     )
Example #6
0
File: relay.py Project: JTpku/relay
    def get_user_events(
        self,
        user_address: str,
        event_type: str = None,
        from_block: int = 0,
        contract_type: ContractTypes = None,
    ) -> List[BlockchainEvent]:
        """
        Get all events of users for user_address.
        Filter with from_block, event_type and contract_type
        """
        assert is_checksum_address(user_address)
        event_types: Optional[List[str]]
        if event_type:
            event_types = [event_type]
        else:
            event_types = None

        address_to_contract_types: Dict[str, str] = {}

        if contract_type == ContractTypes.CURRENCY_NETWORK or contract_type is None:
            for address in self.network_addresses:
                address_to_contract_types[
                    address] = ContractTypes.CURRENCY_NETWORK.value
        if contract_type == ContractTypes.EXCHANGE or contract_type is None:
            for address in self.exchange_addresses:
                address_to_contract_types[
                    address] = ContractTypes.EXCHANGE.value
        if contract_type == ContractTypes.TOKEN or contract_type is None:
            for address in self.token_addresses:
                address_to_contract_types[address] = ContractTypes.TOKEN.value
        if contract_type == ContractTypes.UNWETH or contract_type is None:
            for address in self.unw_eth_addresses:
                address_to_contract_types[address] = ContractTypes.UNWETH.value

        ethindex = ethindex_db.EthindexDB(
            ethindex_db.connect(""),
            standard_event_types=all_standard_event_types,
            event_builders=all_event_builders,
            from_to_types=all_from_to_types,
            address_to_contract_types=address_to_contract_types,
        )
        return ethindex.get_all_contract_events(
            event_types,
            user_address=user_address,
            from_block=from_block,
        )
Example #7
0
    def get_ethindex_db_for_currency_network(
        self, network_address: Optional[str] = None
    ) -> ethindex_db.CurrencyNetworkEthindexDB:
        """return an EthindexDB instance.
        This is being used from relay.api to query for events.
        """
        address_to_contract_types: Dict[str, str] = {}
        for address in self.network_addresses:
            address_to_contract_types[address] = ContractTypes.CURRENCY_NETWORK.value

        return ethindex_db.CurrencyNetworkEthindexDB(
            ethindex_db.connect(""),
            address=network_address,
            standard_event_types=currency_network_events.standard_event_types,
            event_builders=all_event_builders,
            from_to_types=currency_network_events.from_to_types,
            address_to_contract_types=address_to_contract_types,
        )