def enqueue_l1_pipeline(pipeline: "Pipeline", transaction: Dict[str, Any]) -> "Pipeline": txn_type_string = transaction["header"]["txn_type"] invocation_attempt = not transaction["header"].get("invoker") # This transaction is an invocation attempt if there is no invoker try: transaction_type = transaction_type_dao.get_registered_transaction_type(txn_type_string) except exceptions.NotFound: _log.error("Invalid transaction type") raise exceptions.InvalidTransactionType(f"Transaction of type {txn_type_string} does not exist") pipeline.lpush(INCOMING_TX_KEY, json.dumps(transaction, separators=(",", ":"))) pipeline.sadd(TEMPORARY_TX_KEY, transaction["header"]["txn_id"]) # Attempt contract invocation if necessary if transaction_type.contract_id and invocation_attempt: _log.info("Checking if smart contract is associated with this txn_type") contract = smart_contract_dao.get_contract_by_id(transaction_type.contract_id) # Explicitly checked for existence above contract_active = contract.status["state"] in ["active", "updating"] _log.info(f"Contract found: {contract}") if contract_active: transaction["payload"] = json.loads(transaction["payload"]) # We must parse the stringied payload of the SC invocation before sending invocation_request = contract.export_as_invoke_request(transaction) pipeline.lpush(CONTRACT_INVOKE_MQ_KEY, json.dumps(invocation_request, separators=(",", ":"))) return pipeline
def enqueue_l1(transaction: dict) -> None: txn_type_string = transaction["header"]["txn_type"] invocation_attempt = not transaction["header"].get( "invoker" ) # This transaction is an invocation attempt if there is no invoker try: transaction_type = transaction_type_dao.get_registered_transaction_type( txn_type_string) except exceptions.NotFound: _log.error("Invalid transaction type") raise exceptions.InvalidTransactionType( f"Transaction of type {txn_type_string} does not exist") # Enqueue to transaction queue enqueue_generic(transaction, queue=INCOMING_TX_KEY, deadline=0) # Attempt contract invocation if necessary if transaction_type.contract_id and invocation_attempt: _log.info( "Checking if smart contract is associated with this txn_type") contract = smart_contract_dao.get_contract_by_id( transaction_type.contract_id ) # Explicitly checked for existence above contract_active = contract.status["state"] in ["active", "updating"] _log.info(f"Contract found: {contract}") if contract_active: transaction["payload"] = json.loads( transaction["payload"] ) # We must parse the stringied payload of the SC invocation before sending invocation_request = contract.export_as_invoke_request(transaction) enqueue_generic(invocation_request, queue=CONTRACT_INVOKE_MQ_KEY, deadline=0)
def test_webserver_error_handler_invalid_transaction_type(self, mock_http_response, mock_report_exception): exception = exceptions.InvalidTransactionType() helpers.webserver_error_handler(exception) mock_report_exception.assert_not_called() mock_http_response.assert_called_once_with(400, ANY)