from typing import Dict


def decode_transaction(raw_transaction: bytes) -> Dict:
    """
    Decodes bytes representation of a transaction into transaction dictionary.

    Args:
        raw_transaction: Bytes representing a transaction.

    Returns:
        Transaction in dictionary form.
    """
    tx_items = raw_transaction.decode().split('\0')
    transaction = {}

    transaction['blockHash'] = tx_items[0]
    transaction['blockNumber'] = tx_items[1]
    transaction['from'] = tx_items[2]
    transaction['to'] = tx_items[3]
    transaction['gas'] = tx_items[4]
    transaction['gasPrice'] = tx_items[5]
    # transaction['transactionHash'] = tx_items[6]
    transaction['input'] = tx_items[6]
    transaction['nonce'] = tx_items[7]
    transaction['value'] = tx_items[8]
    transaction['cumulativeGasUsed'] = tx_items[9]
    transaction['gasUsed'] = tx_items[10]
    transaction['logs'] = tx_items[11]
    transaction['contractAddress'] = tx_items[12]
    transaction['timestamp'] = tx_items[13]
    transaction['internalTxIndex'] = int(tx_items[14])  # type: ignore

    logs = []
    if (transaction['logs'] != '' and transaction['logs'][-1] == '|'):
        transaction['logs'] = transaction['logs'][:-1]

    for log in transaction['logs'].split('|'):
        fields = log.split('+')
        full_log = {}
        full_log['data'] = fields[0]
        if len(fields) == 2:
            topics = fields[1].split('-')
            full_log['topics'] = topics  # type: ignore
        else:
            full_log['topics'] = []  # type: ignore
        logs.append(full_log)

    transaction['logs'] = logs  # type: ignore

    return transaction