def create_output_transaction(
        transaction: transaction_model.TransactionModel,
        smart_contract_output: Union[Dict[Any, Any], str]) -> None:
    # Replace tags if specified
    if isinstance(smart_contract_output,
                  dict) and "tag" in smart_contract_output and isinstance(
                      smart_contract_output["tag"], str):
        transaction.tag = smart_contract_output["tag"]
        del smart_contract_output["tag"]

    #  Create new transaction by modifying invocation request
    transaction.invoker = transaction.txn_id
    transaction.payload = smart_contract_output
    transaction.txn_id = str(uuid.uuid4())
def _add_transaction_stub(txn_model: transaction_model.TransactionModel) -> None:
    """store a stub for a transaction in the index to prevent 404s from getting immediately after posting
    Args:
        txn_model: txn model to stub in the index
    """
    redisearch.put_document(txn_model.txn_type, txn_model.txn_id, txn_model.export_as_search_index(stub=True))
    redisearch.put_document(redisearch.Indexes.transaction.value, f"txn-{txn_model.txn_id}", {"block_id": "0"})
def output_transaction(
        transaction: transaction_model.TransactionModel) -> None:
    _log.info("Enqueueing to transaction processor")
    new_transaction = json.dumps(transaction.export_as_queue_task(),
                                 separators=(",", ":"))
    pushed = redis.lpush_sync("dc:tx:incoming", new_transaction)
    if pushed == 0:
        _log.info("Could not output transaction")
        raise exceptions.LedgerError("Error outputting contract data on chain")
    else:
        _log.info("Successfully enqueued SC response as transaction")