# Buggy code
def get_transactions(self):
    if not self.created:
        return succeed([])

    # Update all transactions
    self.wallet.transactions_update(network=self.network)

    txs = (
        self.wallet._session.query(
            DbTransaction.raw,
            DbTransaction.confirmations,
            DbTransaction.date,
            DbTransaction.fee,
        )
        .filter(DbTransaction.wallet_id == self.wallet.wallet_id)
        .all()
    )
    transactions = []

    for db_result in txs:
        transaction = Transaction.import_raw(db_result[0], network=self.network)
        transaction.confirmations = db_result[1]
        transaction.date = db_result[2]
        transaction.fee = db_result[3]
        transactions.append(transaction)

    # Sort them based on locktime
    transactions.sort(key=lambda tx: tx.locktime, reverse=True)

    my_keys = [
        key.address for key in self.wallet.keys(network=self.network, is_active=False)
    ]

    transactions_list = []
    for transaction in transactions:
        value = 0
        input_addresses = []
        output_addresses = []
        for tx_input in transaction.inputs:
            input_addresses.append(tx_input.address)
            if tx_input.address in my_keys:
                # At this point, we do not have the value of the input so we should do a database query for it
                db_res = (
                    self.wallet._session.query(DbTransactionInput.value)
                    .filter(
                        tx_input.prev_hash.encode("hex")
                        == DbTransactionInput.prev_hash,
                        tx_input.output_n_int == DbTransactionInput.output_n,
                    )
                    .all()
                )
                if db_res:
                    value -= db_res[0][0]

        for tx_output in transaction.outputs:
            output_addresses.append(tx_output.address)
            if tx_output.address in my_keys:
                value += tx_output.value

        transactions_list.append(
            {
                "id": transaction.hash,
                "outgoing": value < 0,
                "from": ",".join(input_addresses),
                "to": ",".join(output_addresses),
                "amount": abs(value),
                "fee_amount": transaction.fee,
                "currency": "BTC",
                "timestamp": time.mktime(transaction.date.timetuple()),
                "description": "Confirmations: %d" % transaction.confirmations,
            }
        )

    return succeed(transactions_list)


# Traceback (RuntimeError)
Traceback (most recent call last):
File "TriblerGUI\core_manager.py", line 114, in on_received_state
RuntimeError: Unhandled Error
Traceback (most recent call last):
File "lib\site-packages\twisted\internet\base.py", line 428, in fireEvent

File "lib\site-packages\twisted\internet\defer.py", line 321, in addCallback

File "lib\site-packages\twisted\internet\defer.py", line 310, in addCallbacks

File "lib\site-packages\twisted\internet\defer.py", line 653, in _runCallbacks

--- <exception caught here> ---
File "lib\site-packages\twisted\internet\base.py", line 441, in _continueFiring

File "run_tribler.py", line 73, in start_tribler

File "Tribler\pyipv8\ipv8\util.py", line 14, in helper

File "Tribler\pyipv8\ipv8\util.py", line 26, in blockingCallFromThread

File "Tribler\Core\Session.py", line 487, in start

File "Tribler\Core\APIImplementation\LaunchManyCore.py", line 226, in register

File "Tribler\Core\APIImplementation\LaunchManyCore.py", line 406, in init

File "c:\python27\Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module

File "Tribler\Core\Modules\wallet\btc_wallet.py", line 4, in <module>

File "c:\python27\Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module

File "lib\site-packages\bitcoinlib\__init__.py", line 20, in <module>

File "c:\python27\Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module

File "lib\site-packages\bitcoinlib\encoding.py", line 30, in <module>

File "c:\python27\Lib\site-packages\PyInstaller\loader\pyimod03_importers.py", line 389, in load_module

File "lib\site-packages\bitcoinlib\main.py", line 75, in <module>

File "lib\site-packages\bitcoinlib\main.py", line 69, in initialize_lib

exceptions.WindowsError: [Error 3] Het systeem kan het opgegeven pad niet vinden: 'D:\\Program Files\\Tribler\\bitcoinlib\\data/*.*'

# Fixed code
def get_transactions(self):
    if not self.created:
        return succeed([])

    from bitcoinlib.transactions import Transaction
    from bitcoinlib.wallets import DbTransaction, DbTransactionInput

    # Update all transactions
    self.wallet.transactions_update(network=self.network)

    txs = (
        self.wallet._session.query(
            DbTransaction.raw,
            DbTransaction.confirmations,
            DbTransaction.date,
            DbTransaction.fee,
        )
        .filter(DbTransaction.wallet_id == self.wallet.wallet_id)
        .all()
    )
    transactions = []

    for db_result in txs:
        transaction = Transaction.import_raw(db_result[0], network=self.network)
        transaction.confirmations = db_result[1]
        transaction.date = db_result[2]
        transaction.fee = db_result[3]
        transactions.append(transaction)

    # Sort them based on locktime
    transactions.sort(key=lambda tx: tx.locktime, reverse=True)

    my_keys = [
        key.address for key in self.wallet.keys(network=self.network, is_active=False)
    ]

    transactions_list = []
    for transaction in transactions:
        value = 0
        input_addresses = []
        output_addresses = []
        for tx_input in transaction.inputs:
            input_addresses.append(tx_input.address)
            if tx_input.address in my_keys:
                # At this point, we do not have the value of the input so we should do a database query for it
                db_res = (
                    self.wallet._session.query(DbTransactionInput.value)
                    .filter(
                        tx_input.prev_hash.encode("hex")
                        == DbTransactionInput.prev_hash,
                        tx_input.output_n_int == DbTransactionInput.output_n,
                    )
                    .all()
                )
                if db_res:
                    value -= db_res[0][0]

        for tx_output in transaction.outputs:
            output_addresses.append(tx_output.address)
            if tx_output.address in my_keys:
                value += tx_output.value

        transactions_list.append(
            {
                "id": transaction.hash,
                "outgoing": value < 0,
                "from": ",".join(input_addresses),
                "to": ",".join(output_addresses),
                "amount": abs(value),
                "fee_amount": transaction.fee,
                "currency": "BTC",
                "timestamp": time.mktime(transaction.date.timetuple()),
                "description": "Confirmations: %d" % transaction.confirmations,
            }
        )

    return succeed(transactions_list)