Example #1
0
    def _is_valid(self, submission_data: Dict[str, any]) -> bool:
        # lookup the tx hash in secret20, and validate it.
        self.logger.info(f"Testing validity of {submission_data}")
        nonce = submission_data['nonce']
        token = submission_data['token']

        # todo: validate fee

        try:
            if token == '0x0000000000000000000000000000000000000000':
                self.logger.info("Testing secret-ETH to ETH swap")
                swap = query_scrt_swap(nonce, self.config["scrt_swap_address"],
                                       self.token_map['native'].address)
            else:
                self.logger.info(
                    f"Testing {self.token_map[token].address} to {token} swap")
                swap = query_scrt_swap(nonce, self.config["scrt_swap_address"],
                                       self.token_map[token].address)
        except subprocess.CalledProcessError as e:
            self.logger.error(f'Error querying transaction: {e}')
            raise RuntimeError from None

        try:
            swap_data = swap_query_res(swap)
            self.logger.debug(f'Parsing swap info: {swap_data}')
        except (AttributeError, JSONDecodeError) as e:
            raise ValueError from e
        if self._validate_tx_data(swap_data, submission_data):
            self.logger.info('Validated successfully')
            return True
        self.logger.info('Failed to validate')
        return False
Example #2
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'])
Example #3
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)
Example #4
0
    def _is_valid(self, submission_data: Dict[str, any]) -> bool:
        # lookup the tx hash in secret20, and validate it.
        nonce = submission_data['nonce']
        swap = query_scrt_swap(nonce, self.config['secret_swap_contract_address'])

        try:
            swap_data = swap_query_res(swap)
        except (AttributeError, JSONDecodeError) as e:
            raise ValueError from e
        if self._validate_tx_data(swap_data, submission_data):
            return True
        return False
Example #5
0
    def _scan_swap(self):
        """ Scans secret network contract for swap events """
        current_nonce = Management.last_processed(Source.SCRT.value)
        doc = Management.objects(nonce=current_nonce, src=Source.SCRT.value).get()
        next_nonce = current_nonce + 1

        while not self.stop_event.is_set():
            try:
                swap_data = query_scrt_swap(next_nonce, self.config['secret_swap_contract_address'])
                self._handle_swap(swap_data)
                doc.nonce = next_nonce
                doc.save()
                next_nonce += 1
                continue

            except CalledProcessError as e:
                if e.stderr != b'ERROR: query result: encrypted: AppendStorage access out of bounds\n':
                    if b'ERROR: query result: encrypted: Failed to get swap for key' not in e.stderr:
                        self.logger.error(e.stdout + e.stderr)

            self.stop_event.wait(self.config['sleep_interval'])
Example #6
0
    def _is_valid(self, submission_data: Dict[str, any]) -> bool:
        # lookup the tx hash in secret20, and validate it.
        self.logger.info(f"Testing validity of {submission_data}")
        nonce = submission_data['nonce']
        token = submission_data['token']

        try:
            swap = query_scrt_swap(nonce, self.config.scrt_swap_address,
                                   self._eth_to_scrt(token))
        except subprocess.CalledProcessError as e:
            self.logger.error(f'Error querying transaction: {e}')
            raise RuntimeError from None

        try:
            swap_data = swap_query_res(swap)
            self.logger.debug(f'Parsing swap info: {swap_data}')
        except (AttributeError, JSONDecodeError) as e:
            raise ValueError from e
        if self._validate_tx_data(swap_data, submission_data):
            self.logger.info('Validated successfully')
            return True
        self.logger.info('Failed to validate')
        return False