You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
143 lines
5.6 KiB
143 lines
5.6 KiB
10 years ago
|
#!/usr/bin/env python
|
||
|
#
|
||
|
# Electrum - lightweight Bitcoin client
|
||
|
# Copyright (C) 2015 Thomas Voegtlin
|
||
|
#
|
||
9 years ago
|
# Permission is hereby granted, free of charge, to any person
|
||
|
# obtaining a copy of this software and associated documentation files
|
||
|
# (the "Software"), to deal in the Software without restriction,
|
||
|
# including without limitation the rights to use, copy, modify, merge,
|
||
|
# publish, distribute, sublicense, and/or sell copies of the Software,
|
||
|
# and to permit persons to whom the Software is furnished to do so,
|
||
|
# subject to the following conditions:
|
||
10 years ago
|
#
|
||
9 years ago
|
# The above copyright notice and this permission notice shall be
|
||
|
# included in all copies or substantial portions of the Software.
|
||
10 years ago
|
#
|
||
9 years ago
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||
|
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||
|
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||
|
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
||
|
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
||
|
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||
|
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||
|
# SOFTWARE.
|
||
10 years ago
|
|
||
|
|
||
|
import webbrowser
|
||
|
|
||
|
from util import *
|
||
|
from electrum.i18n import _
|
||
10 years ago
|
from electrum.util import block_explorer_URL, format_satoshis, format_time
|
||
10 years ago
|
from electrum.plugins import run_hook
|
||
|
|
||
|
|
||
9 years ago
|
class HistoryList(MyTreeWidget):
|
||
10 years ago
|
|
||
|
def __init__(self, parent=None):
|
||
9 years ago
|
MyTreeWidget.__init__(self, parent, self.create_menu, [], 3)
|
||
|
self.refresh_headers()
|
||
10 years ago
|
self.setColumnHidden(1, True)
|
||
10 years ago
|
|
||
9 years ago
|
def refresh_headers(self):
|
||
|
headers = ['', '', _('Date'), _('Description') , _('Amount'),
|
||
|
_('Balance')]
|
||
|
run_hook('history_tab_headers', headers)
|
||
|
self.update_headers(headers)
|
||
|
|
||
10 years ago
|
def get_icon(self, conf, timestamp):
|
||
|
time_str = _("unknown")
|
||
|
if conf > 0:
|
||
|
time_str = format_time(timestamp)
|
||
|
if conf == -1:
|
||
9 years ago
|
time_str = _('Not Verified')
|
||
10 years ago
|
icon = QIcon(":icons/unconfirmed.png")
|
||
|
elif conf == 0:
|
||
9 years ago
|
time_str = _('Unconfirmed')
|
||
10 years ago
|
icon = QIcon(":icons/unconfirmed.png")
|
||
|
elif conf < 6:
|
||
|
icon = QIcon(":icons/clock%d.png"%conf)
|
||
|
else:
|
||
|
icon = QIcon(":icons/confirmed.png")
|
||
|
return icon, time_str
|
||
|
|
||
9 years ago
|
def get_domain(self):
|
||
|
'''Replaced in address_dialog.py'''
|
||
|
return self.wallet.get_account_addresses(self.parent.current_account)
|
||
|
|
||
9 years ago
|
def on_update(self):
|
||
10 years ago
|
self.wallet = self.parent.wallet
|
||
9 years ago
|
h = self.wallet.get_history(self.get_domain())
|
||
9 years ago
|
|
||
10 years ago
|
item = self.currentItem()
|
||
|
current_tx = item.data(0, Qt.UserRole).toString() if item else None
|
||
|
self.clear()
|
||
9 years ago
|
run_hook('history_tab_update_begin')
|
||
9 years ago
|
for tx in h:
|
||
|
tx_hash, conf, value, timestamp, balance = tx
|
||
10 years ago
|
if conf is None and timestamp is None:
|
||
|
continue # skip history in offline mode
|
||
10 years ago
|
icon, time_str = self.get_icon(conf, timestamp)
|
||
10 years ago
|
v_str = self.parent.format_amount(value, True, whitespaces=True)
|
||
|
balance_str = self.parent.format_amount(balance, whitespaces=True)
|
||
9 years ago
|
label = self.wallet.get_label(tx_hash)
|
||
9 years ago
|
entry = ['', tx_hash, time_str, label, v_str, balance_str]
|
||
|
run_hook('history_tab_update', tx, entry)
|
||
9 years ago
|
item = QTreeWidgetItem(entry)
|
||
10 years ago
|
item.setIcon(0, icon)
|
||
9 years ago
|
for i in range(len(entry)):
|
||
9 years ago
|
if i>3:
|
||
|
item.setTextAlignment(i, Qt.AlignRight)
|
||
9 years ago
|
if i!=2:
|
||
|
item.setFont(i, QFont(MONOSPACE_FONT))
|
||
10 years ago
|
if value < 0:
|
||
9 years ago
|
item.setForeground(3, QBrush(QColor("#BC1E1E")))
|
||
10 years ago
|
item.setForeground(4, QBrush(QColor("#BC1E1E")))
|
||
10 years ago
|
if tx_hash:
|
||
|
item.setData(0, Qt.UserRole, tx_hash)
|
||
|
self.insertTopLevelItem(0, item)
|
||
|
if current_tx == tx_hash:
|
||
|
self.setCurrentItem(item)
|
||
|
|
||
10 years ago
|
def update_item(self, tx_hash, conf, timestamp):
|
||
|
icon, time_str = self.get_icon(conf, timestamp)
|
||
|
items = self.findItems(tx_hash, Qt.UserRole|Qt.MatchContains|Qt.MatchRecursive, column=1)
|
||
|
if items:
|
||
|
item = items[0]
|
||
|
item.setIcon(0, icon)
|
||
|
item.setText(2, time_str)
|
||
10 years ago
|
|
||
|
def create_menu(self, position):
|
||
|
self.selectedIndexes()
|
||
|
item = self.currentItem()
|
||
|
if not item:
|
||
|
return
|
||
9 years ago
|
column = self.currentColumn()
|
||
10 years ago
|
tx_hash = str(item.data(0, Qt.UserRole).toString())
|
||
|
if not tx_hash:
|
||
|
return
|
||
9 years ago
|
if column is 0:
|
||
|
column_title = "ID"
|
||
|
column_data = tx_hash
|
||
|
else:
|
||
|
column_title = self.headerItem().text(column)
|
||
|
column_data = item.text(column)
|
||
|
|
||
10 years ago
|
tx_URL = block_explorer_URL(self.config, 'tx', tx_hash)
|
||
9 years ago
|
conf, timestamp = self.wallet.get_confirmations(tx_hash)
|
||
|
tx = self.wallet.transactions.get(tx_hash)
|
||
|
is_relevant, is_mine, v, fee = self.wallet.get_wallet_delta(tx)
|
||
|
rbf = is_mine and (conf == 0) and tx and not tx.is_final()
|
||
10 years ago
|
menu = QMenu()
|
||
9 years ago
|
|
||
|
menu.addAction(_("Copy %s")%column_title, lambda: self.parent.app.clipboard().setText(column_data))
|
||
|
if column in self.editable_columns:
|
||
|
menu.addAction(_("Edit %s")%column_title, lambda: self.editItem(item, column))
|
||
|
|
||
9 years ago
|
menu.addAction(_("Details"), lambda: self.parent.show_transaction(tx))
|
||
|
if rbf:
|
||
|
menu.addAction(_("Increase fee"), lambda: self.parent.bump_fee_dialog(tx))
|
||
|
if tx_URL:
|
||
|
menu.addAction(_("View on block explorer"), lambda: webbrowser.open(tx_URL))
|
||
10 years ago
|
menu.exec_(self.viewport().mapToGlobal(position))
|