Esempio n. 1
0
    def _scan_swap(self):
        """ Scans secret network contract for swap events """
        self.logger.info(
            f'Starting for account {self.signer.address} with tokens: {self.token_map=}'
        )
        while not self.stop_event.is_set():
            for token in self.token_map:
                try:
                    swap_tracker = SwapTrackerObject.get_or_create(src=token)
                    next_nonce = swap_tracker.nonce + 1

                    self.logger.debug(
                        f'Scanning token {token} for query #{next_nonce}')

                    swap_data = query_scrt_swap(
                        next_nonce, self.config["scrt_swap_address"], token)

                    self._handle_swap(swap_data, token,
                                      self.token_map[token].address)
                    swap_tracker.nonce = next_nonce
                    swap_tracker.save()
                    next_nonce += 1

                except CalledProcessError as e:
                    if b'ERROR: query result: encrypted: Failed to get swap for token' not in e.stderr:
                        self.logger.error(
                            f"Failed to query swap: stdout: {e.stdout} stderr: {e.stderr}"
                        )
                        # if b'ERROR: query result: encrypted: Failed to get swap for key' not in e.stderr:

            self.stop_event.wait(self.config['sleep_interval'])
Esempio n. 2
0
    def choose_starting_block(self) -> int:
        """Returns the block from which we start scanning Ethereum for new tx"""
        obj = SwapTrackerObject.get_or_create(src=signer_id(self.account))
        if obj.nonce == -1:
            obj.update(nonce=self.config.eth_start_block)

        return obj.nonce
Esempio n. 3
0
    def run(self):
        self.logger.info("Starting")

        # todo: fix so tracker doesn't start from 0
        from_block = SwapTrackerObject.get_or_create(src="Ethereum").nonce

        self.event_listener.register(self.confirmer.submit, ['Submission'], from_block=from_block)
        self.event_listener.register(self.confirmer.withdraw, ['Withdraw'], from_block=from_block)
        self.event_listener.register(self.confirmer.failed_withdraw, ['WithdrawFailure'], from_block=from_block)
        self.event_listener.start()

        self._scan_swap()
    def _set_tx_result(self, nonce, token, success=True):
        try:
            swap = self.get_swap(nonce, token)
        except Exception as e:
            self.logger.error(f'Error handling swap {build_hash(nonce, token)}: {e}')
            return

        if swap.status != Status.SWAP_SUBMITTED:
            return
        if success:
            swap.update(status=Status.SWAP_CONFIRMED)
        else:
            swap.update(status=Status.SWAP_FAILED)

        obj = SwapTrackerObject.get_or_create(self._confirmer_id(token))
        obj.update(nonce=nonce)
Esempio n. 5
0
    def _scan_swap(self):
        """ Scans secret network contract for swap events """
        self.logger.info(f'Starting for account {self.signer.address} with tokens: {self.token_map=}')
        while not self.stop_event.is_set():

            num_of_tokens = TokenPairing.objects(src_network=self.network).count()
            if num_of_tokens != len(self.token_map.keys()):
                self._refresh_token_map()
                self.logger.info(f'Refreshed tracked tokens. Now tracking {len(self.token_map.keys())} tokens')

            for transaction in Swap.objects(status=Status.SWAP_RETRY, src_network="Secret"):
                # self._handle_swap(swap_data, token, self.token_map[token].address)
                try:
                    token, nonce = _parse_db_tx(transaction)
                    swap_data = query_scrt_swap(nonce, self.config.scrt_swap_address, token)
                    # self._retry(transaction)
                    self._handle_swap(swap_data, token, self.token_map[token].address, True)
                except Exception as e:  # pylint: disable=broad-except
                    self.logger.error(f'Failed to retry swap: {e}')
                    transaction.update(status=Status.SWAP_FAILED)

            for token in self.token_map:
                try:
                    swap_tracker = SwapTrackerObject.get_or_create(src=token)
                    next_nonce = swap_tracker.nonce + 1

                    self.logger.debug(f'Scanning token {token} for query #{next_nonce}')

                    swap_data = query_scrt_swap(next_nonce, self.config.scrt_swap_address, token)

                    self._handle_swap(swap_data, token, self.token_map[token].address)
                    swap_tracker.nonce = next_nonce
                    swap_tracker.save()
                    next_nonce += 1

                except CalledProcessError as e:
                    if b'ERROR: query result: encrypted: Failed to get swap for token' not in e.stderr:
                        self.logger.error(f"Failed to query swap: stdout: {e.stdout} stderr: {e.stderr}")
                        # if b'ERROR: query result: encrypted: Failed to get swap for key' not in e.stderr:

            self.stop_event.wait(self.config.sleep_interval)