From 56a5166493711675ff5d7c454cc48b7933a154fa Mon Sep 17 00:00:00 2001 From: Inso <insomniak.fr@gmail.com> Date: Sat, 24 Jan 2015 23:48:17 +0100 Subject: [PATCH] Sorted tableview with dated transactions --- res/ui/currency_tab.ui | 10 +++------- src/cutecoin/core/account.py | 18 +++++++++--------- src/cutecoin/core/wallet.py | 23 ++++++++++++----------- src/cutecoin/models/txhistory.py | 20 +++++++++++++------- 4 files changed, 37 insertions(+), 34 deletions(-) diff --git a/res/ui/currency_tab.ui b/res/ui/currency_tab.ui index dc899841..065353e5 100644 --- a/res/ui/currency_tab.ui +++ b/res/ui/currency_tab.ui @@ -67,15 +67,11 @@ <layout class="QHBoxLayout" name="horizontalLayout_3"> <item> <layout class="QVBoxLayout" name="verticalLayout_3"> - <item> - <widget class="QLabel" name="label"> - <property name="text"> - <string>History</string> - </property> - </widget> - </item> <item> <widget class="QTableView" name="table_history"> + <attribute name="horizontalHeaderStretchLastSection"> + <bool>true</bool> + </attribute> <attribute name="verticalHeaderVisible"> <bool>false</bool> </attribute> diff --git a/src/cutecoin/core/account.py b/src/cutecoin/core/account.py index 90e20cfe..36118a05 100644 --- a/src/cutecoin/core/account.py +++ b/src/cutecoin/core/account.py @@ -141,33 +141,33 @@ class Account(object): def transactions_received(self, community): received = [] for w in self.wallets: - for t in w.transactions_received(community): + for tx in w.transactions_received(community): # Lets remove transactions from our own wallets pubkeys = [wallet.pubkey for wallet in self.wallets] - if t.issuers[0] not in pubkeys: - received.append(t) + if tx[1].issuers[0] not in pubkeys: + received.append(tx) return received def transactions_sent(self, community): sent = [] for w in self.wallets: - for t in w.transactions_sent(community): + for tx in w.transactions_sent(community): # Lets remove transactions to our own wallets pubkeys = [wallet.pubkey for wallet in self.wallets] - outputs = [o for o in t.outputs if o.pubkey not in pubkeys] + outputs = [o for o in tx[1].outputs if o.pubkey not in pubkeys] if len(outputs) > 0: - sent.append(t) + sent.append(tx) return sent def transactions_awaiting(self, community): awaiting = [] for w in self.wallets: - for t in w.transactions_awaiting(community): + for tx in w.transactions_awaiting(community): # Lets remove transactions to our own wallets pubkeys = [wallet.pubkey for wallet in self.wallets] - outputs = [o for o in t.outputs if o.pubkey not in pubkeys] + outputs = [o for o in tx[1].outputs if o.pubkey not in pubkeys] if len(outputs) > 0: - awaiting.append(t) + awaiting.append(tx) return awaiting def member_of(self, community): diff --git a/src/cutecoin/core/wallet.py b/src/cutecoin/core/wallet.py index 7789640b..f1f6889a 100644 --- a/src/cutecoin/core/wallet.py +++ b/src/cutecoin/core/wallet.py @@ -30,15 +30,15 @@ class Cache(): data_received = data['received'] for r in data_received: - self.tx_received.append(Transaction.from_signed_raw(r['raw'])) + self.tx_received.append((r['block'], Transaction.from_signed_raw(r['raw']))) data_sent = data['sent'] for s in data_sent: - self.tx_sent.append(Transaction.from_signed_raw(s['raw'])) + self.tx_sent.append((r['block'], Transaction.from_signed_raw(s['raw']))) data_awaiting = data['awaiting'] for s in data_awaiting: - self.awaiting_tx.append(Transaction.from_signed_raw(s['raw'])) + self.awaiting_tx.append((r['block'], Transaction.from_signed_raw(s['raw']))) if 'sources' in data: data_sources = data['sources'] @@ -50,15 +50,15 @@ class Cache(): def jsonify(self): data_received = [] for r in self.tx_received: - data_received.append({'raw': r.signed_raw()}) + data_received.append({'block': r[0], 'raw': r[1].signed_raw()}) data_sent = [] for s in self.tx_sent: - data_sent.append({'raw': s.signed_raw()}) + data_sent.append({'block': r[0], 'raw': s[1].signed_raw()}) data_awaiting = [] for s in self.awaiting_tx: - data_awaiting.append({'raw': s.signed_raw()}) + data_awaiting.append({'block': r[0], 'raw': s[1].signed_raw()}) data_sources = [] for s in self.available_sources: @@ -110,15 +110,15 @@ class Cache(): in_outputs = [o for o in tx.outputs if o.pubkey == self.wallet.pubkey] if len(in_outputs) > 0: - self.tx_received.append(tx) + self.tx_received.append((block_number, tx)) in_inputs = [i for i in tx.issuers if i == self.wallet.pubkey] if len(in_inputs) > 0: # remove from waiting transactions list the one which were # validated in the blockchain - self.awaiting_tx = [awaiting for awaiting in self.awaiting_tx - if awaiting.compact() != tx.compact()] - self.tx_sent.append(tx) + self.awaiting_tx = [awaiting[1] for awaiting in self.awaiting_tx + if awaiting[1].compact() != tx.compact()] + self.tx_sent.append((block_number, tx)) if current_block > self.latest_block: self.available_sources = self.wallet.sources(community) @@ -259,7 +259,8 @@ class Wallet(object): try: community.broadcast(bma.tx.Process, post_args={'transaction': tx.signed_raw()}) - self.caches[community.currency].awaiting_tx.append(tx) + block_number = community.current_blockid()['number'] + self.caches[community.currency].awaiting_tx.append((block_number, tx)) except: raise diff --git a/src/cutecoin/models/txhistory.py b/src/cutecoin/models/txhistory.py index 0207b191..c8dce537 100644 --- a/src/cutecoin/models/txhistory.py +++ b/src/cutecoin/models/txhistory.py @@ -9,6 +9,8 @@ from ..core.person import Person from ..tools.exceptions import PersonNotFoundError from PyQt5.QtCore import QAbstractTableModel, Qt, QVariant from PyQt5.QtGui import QFont +from operator import itemgetter +import datetime class HistoryTableModel(QAbstractTableModel): @@ -30,7 +32,6 @@ class HistoryTableModel(QAbstractTableModel): transactions = self.account.transactions_sent(self.community) + \ self.account.transactions_awaiting(self.community) + \ self.account.transactions_received(self.community) - logging.debug("rowcount: {0}:{1}".format(parent.row(), len(transactions))) return len(transactions) def columnCount(self, parent): @@ -43,25 +44,28 @@ class HistoryTableModel(QAbstractTableModel): def data_received(self, tx): outputs = [] amount = 0 - for o in tx.outputs: + for o in tx[1].outputs: pubkeys = [w.pubkey for w in self.account.wallets] if o.pubkey not in pubkeys: outputs.append(o) amount += o.amount - pubkey = tx.issuers[0] + pubkey = tx[1].issuers[0] sender = "" try: sender = Person.lookup(pubkey, self.community) except PersonNotFoundError: sender = "" - return ("", sender.name, pubkey, "", "{0}".format(amount)) + date_ts = self.community.get_block(tx[0]).mediantime + date = datetime.datetime.fromtimestamp(date_ts).strftime('%Y-%m-%d %H:%M:%S') + + return (date, sender.name, pubkey, "", "{0}".format(amount)) def data_sent(self, tx): amount = 0 outputs = [] - for o in tx.outputs: + for o in tx[1].outputs: pubkeys = [w.pubkey for w in self.account.wallets] if o.pubkey not in pubkeys: outputs.append(o) @@ -73,8 +77,10 @@ class HistoryTableModel(QAbstractTableModel): receiver = Person.lookup(pubkey, self.community) except PersonNotFoundError: receiver = "" + date_ts = self.community.get_block(tx[0]).mediantime + date = datetime.datetime.fromtimestamp(date_ts).strftime('%Y-%m-%d %H:%M:%S') - return ("", receiver.name, pubkey, "-{0}".format(amount), "") + return (date, receiver.name, pubkey, "-{0}".format(amount), "") def data(self, index, role): row = index.row() @@ -82,12 +88,12 @@ class HistoryTableModel(QAbstractTableModel): transactions = self.account.transactions_sent(self.community) + \ self.account.transactions_awaiting(self.community) + \ self.account.transactions_received(self.community) + transactions = sorted(transactions, reverse=True, key=itemgetter(0)) if not index.isValid(): return QVariant() if role == Qt.DisplayRole: - logging.debug("{0}/{1}".format(row, len(transactions))) if transactions[row] in self.account.transactions_sent(self.community) \ or transactions[row] in self.account.transactions_awaiting(self.community): return self.data_sent(transactions[row])[col] -- GitLab