def order_transactions(transactions):
    """Given a list of unordered transactions, order and return them in
    a new list.

    Assumes that the given transactions never have more than one input
    and output (and therefore, as well, that there is never any
    transaction that divides assets); this allows us to represent the
    ordered transactions as a list rather than a branching graph.

    Args:
        transactions (list): Unordered list of transactions

    Returns:
        list: Ordered list of transactions, beginning from the first
        available transaction.

    Raises:
        :exc:`ValueError`: If the given list of transactions include two
            or more disjoint chains (i.e. not linkable into a single
            chain).
    """
    if not transactions:
        return []

    # Find the end tx:
    #   Go through the transactions and find the transaction whose id is not
    #   listed as a dependency of any other transaction
    end_tx = None
    input_dependencies = {tx['inputs'][0]['fulfills']['transaction_id']
                          for tx in transactions
                          if tx['inputs'][0]['fulfills']}
    for tx in transactions:
        if tx['id'] not in input_dependencies:
            if end_tx:
                raise ValueError(
                    ('More than one transaction (ids include `{}` and `{}`) '
                     'was found to have no other transactions depend upon it '
                     'when attempting to order a list of transactions. This '
                     'means that the given list either contains a transaction '
                     'chain that is not flat or that some transactions are '
                     'missing from the list.'.format(end_tx['id'], tx['id'])))
            end_tx = tx

    if not end_tx:
        raise ValueError(('Could not find an end transaction when attempting '
                          'to order a list of transactions. This most likely '
                          'means the given list contains a cycle somewhere.'))

    # Create the ordered list of transactions, going backwards from the end
    ordered_tx = [None] * len(transactions)
    txs_by_id = {tx['id']: tx for tx in transactions}
    for ii in reversed(range(0, len(transactions))):
        ordered_tx[ii] = end_tx

        # If we're at the start of the tx chain, there is no next tx to find
        if ii is not 0:
            end_tx = txs_by_id[end_tx['inputs'][0]['fulfills']['transaction_id']]

    return ordered_tx