def _broadcast_validation(self, document: Swap): # pylint: disable=unused-argument """validation of submitted broadcast signed tx **kwargs needs to be here even if unused, because this function gets passed arguments from mongo internals """ if not document.status == Status.SWAP_SUBMITTED: return tx_hash = document.dst_tx_hash try: res = query_data_success(tx_hash) if res and res["mint_from_ext_chain"]["status"] == "success": document.update(status=Status.SWAP_CONFIRMED) else: # maybe the block took a long time - we wait 60 seconds before we mark it as failed if (datetime.utcnow() - document.updated_on ).total_seconds() < BROADCAST_VALIDATION_COOLDOWN: return document.update(status=Status.SWAP_FAILED) self.logger.critical( f"Failed confirming broadcast for tx: {document}") except (IndexError, json.JSONDecodeError, RuntimeError) as e: self.logger.critical( f"Failed confirming broadcast for tx: {document}. Error: {e}") # This can fail, but if it does we want to crash - this can lead to duplicate amounts and confusion # Better to just stop and make sure everything is kosher before continuing document.update(status=Status.SWAP_FAILED)
def _broadcast_validation(self, document: Swap) -> bool: # pylint: disable=unused-argument """validation of submitted broadcast signed tx **kwargs needs to be here even if unused, because this function gets passed arguments from mongo internals """ if not document.status == Status.SWAP_SUBMITTED or not document.src_network == "Ethereum": return False tx_hash = document.dst_tx_hash try: res = query_data_success(tx_hash) if res and res["mint_from_ext_chain"]["status"] == "success": self.logger.info("Updated status to confirmed") document.update(status=Status.SWAP_CONFIRMED) return True # maybe the block took a long time - we wait 60 seconds before we mark it as failed # The returned value is just here to let us know if we need to retry the next transactions if (datetime.utcnow() - document.updated_on ).total_seconds() < BROADCAST_VALIDATION_COOLDOWN: return True # TX isn't on-chain. We can retry it document.update(status=Status.SWAP_RETRY) # update sequence number - just in case we failed because we are out of sync self.manager.update_sequence() self.logger.critical( f"Failed confirming broadcast for tx: {repr(document)}, Hash: {tx_hash}, res: {res}" ) return False except (ValueError, KeyError) as e: # TX failed for whatever reason. Might be a duplicate, out of gas, or any other reason self.logger.error( f"Failed confirming broadcast for tx: {repr(document)}. Error: {e}" ) # The DB update can fail, but if it does we want to crash - this can lead to # duplicate amounts and confusion. Better to just stop and make sure # everything is kosher before continuing document.update(status=Status.SWAP_FAILED) self.manager.update_sequence() return False