Skip to content
Snippets Groups Projects
Commit 56a51664 authored by inso's avatar inso
Browse files

Sorted tableview with dated transactions

parent 86205315
No related branches found
No related tags found
No related merge requests found
...@@ -67,15 +67,11 @@ ...@@ -67,15 +67,11 @@
<layout class="QHBoxLayout" name="horizontalLayout_3"> <layout class="QHBoxLayout" name="horizontalLayout_3">
<item> <item>
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>History</string>
</property>
</widget>
</item>
<item> <item>
<widget class="QTableView" name="table_history"> <widget class="QTableView" name="table_history">
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
<attribute name="verticalHeaderVisible"> <attribute name="verticalHeaderVisible">
<bool>false</bool> <bool>false</bool>
</attribute> </attribute>
......
...@@ -141,33 +141,33 @@ class Account(object): ...@@ -141,33 +141,33 @@ class Account(object):
def transactions_received(self, community): def transactions_received(self, community):
received = [] received = []
for w in self.wallets: 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 # Lets remove transactions from our own wallets
pubkeys = [wallet.pubkey for wallet in self.wallets] pubkeys = [wallet.pubkey for wallet in self.wallets]
if t.issuers[0] not in pubkeys: if tx[1].issuers[0] not in pubkeys:
received.append(t) received.append(tx)
return received return received
def transactions_sent(self, community): def transactions_sent(self, community):
sent = [] sent = []
for w in self.wallets: 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 # Lets remove transactions to our own wallets
pubkeys = [wallet.pubkey for wallet in self.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: if len(outputs) > 0:
sent.append(t) sent.append(tx)
return sent return sent
def transactions_awaiting(self, community): def transactions_awaiting(self, community):
awaiting = [] awaiting = []
for w in self.wallets: 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 # Lets remove transactions to our own wallets
pubkeys = [wallet.pubkey for wallet in self.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: if len(outputs) > 0:
awaiting.append(t) awaiting.append(tx)
return awaiting return awaiting
def member_of(self, community): def member_of(self, community):
......
...@@ -30,15 +30,15 @@ class Cache(): ...@@ -30,15 +30,15 @@ class Cache():
data_received = data['received'] data_received = data['received']
for r in 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'] data_sent = data['sent']
for s in 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'] data_awaiting = data['awaiting']
for s in 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: if 'sources' in data:
data_sources = data['sources'] data_sources = data['sources']
...@@ -50,15 +50,15 @@ class Cache(): ...@@ -50,15 +50,15 @@ class Cache():
def jsonify(self): def jsonify(self):
data_received = [] data_received = []
for r in self.tx_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 = [] data_sent = []
for s in self.tx_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 = [] data_awaiting = []
for s in self.awaiting_tx: 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 = [] data_sources = []
for s in self.available_sources: for s in self.available_sources:
...@@ -110,15 +110,15 @@ class Cache(): ...@@ -110,15 +110,15 @@ class Cache():
in_outputs = [o for o in tx.outputs in_outputs = [o for o in tx.outputs
if o.pubkey == self.wallet.pubkey] if o.pubkey == self.wallet.pubkey]
if len(in_outputs) > 0: 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] in_inputs = [i for i in tx.issuers if i == self.wallet.pubkey]
if len(in_inputs) > 0: if len(in_inputs) > 0:
# remove from waiting transactions list the one which were # remove from waiting transactions list the one which were
# validated in the blockchain # validated in the blockchain
self.awaiting_tx = [awaiting for awaiting in self.awaiting_tx self.awaiting_tx = [awaiting[1] for awaiting in self.awaiting_tx
if awaiting.compact() != tx.compact()] if awaiting[1].compact() != tx.compact()]
self.tx_sent.append(tx) self.tx_sent.append((block_number, tx))
if current_block > self.latest_block: if current_block > self.latest_block:
self.available_sources = self.wallet.sources(community) self.available_sources = self.wallet.sources(community)
...@@ -259,7 +259,8 @@ class Wallet(object): ...@@ -259,7 +259,8 @@ class Wallet(object):
try: try:
community.broadcast(bma.tx.Process, community.broadcast(bma.tx.Process,
post_args={'transaction': tx.signed_raw()}) 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: except:
raise raise
......
...@@ -9,6 +9,8 @@ from ..core.person import Person ...@@ -9,6 +9,8 @@ from ..core.person import Person
from ..tools.exceptions import PersonNotFoundError from ..tools.exceptions import PersonNotFoundError
from PyQt5.QtCore import QAbstractTableModel, Qt, QVariant from PyQt5.QtCore import QAbstractTableModel, Qt, QVariant
from PyQt5.QtGui import QFont from PyQt5.QtGui import QFont
from operator import itemgetter
import datetime
class HistoryTableModel(QAbstractTableModel): class HistoryTableModel(QAbstractTableModel):
...@@ -30,7 +32,6 @@ class HistoryTableModel(QAbstractTableModel): ...@@ -30,7 +32,6 @@ class HistoryTableModel(QAbstractTableModel):
transactions = self.account.transactions_sent(self.community) + \ transactions = self.account.transactions_sent(self.community) + \
self.account.transactions_awaiting(self.community) + \ self.account.transactions_awaiting(self.community) + \
self.account.transactions_received(self.community) self.account.transactions_received(self.community)
logging.debug("rowcount: {0}:{1}".format(parent.row(), len(transactions)))
return len(transactions) return len(transactions)
def columnCount(self, parent): def columnCount(self, parent):
...@@ -43,25 +44,28 @@ class HistoryTableModel(QAbstractTableModel): ...@@ -43,25 +44,28 @@ class HistoryTableModel(QAbstractTableModel):
def data_received(self, tx): def data_received(self, tx):
outputs = [] outputs = []
amount = 0 amount = 0
for o in tx.outputs: for o in tx[1].outputs:
pubkeys = [w.pubkey for w in self.account.wallets] pubkeys = [w.pubkey for w in self.account.wallets]
if o.pubkey not in pubkeys: if o.pubkey not in pubkeys:
outputs.append(o) outputs.append(o)
amount += o.amount amount += o.amount
pubkey = tx.issuers[0] pubkey = tx[1].issuers[0]
sender = "" sender = ""
try: try:
sender = Person.lookup(pubkey, self.community) sender = Person.lookup(pubkey, self.community)
except PersonNotFoundError: except PersonNotFoundError:
sender = "" 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): def data_sent(self, tx):
amount = 0 amount = 0
outputs = [] outputs = []
for o in tx.outputs: for o in tx[1].outputs:
pubkeys = [w.pubkey for w in self.account.wallets] pubkeys = [w.pubkey for w in self.account.wallets]
if o.pubkey not in pubkeys: if o.pubkey not in pubkeys:
outputs.append(o) outputs.append(o)
...@@ -73,8 +77,10 @@ class HistoryTableModel(QAbstractTableModel): ...@@ -73,8 +77,10 @@ class HistoryTableModel(QAbstractTableModel):
receiver = Person.lookup(pubkey, self.community) receiver = Person.lookup(pubkey, self.community)
except PersonNotFoundError: except PersonNotFoundError:
receiver = "" 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): def data(self, index, role):
row = index.row() row = index.row()
...@@ -82,12 +88,12 @@ class HistoryTableModel(QAbstractTableModel): ...@@ -82,12 +88,12 @@ class HistoryTableModel(QAbstractTableModel):
transactions = self.account.transactions_sent(self.community) + \ transactions = self.account.transactions_sent(self.community) + \
self.account.transactions_awaiting(self.community) + \ self.account.transactions_awaiting(self.community) + \
self.account.transactions_received(self.community) self.account.transactions_received(self.community)
transactions = sorted(transactions, reverse=True, key=itemgetter(0))
if not index.isValid(): if not index.isValid():
return QVariant() return QVariant()
if role == Qt.DisplayRole: if role == Qt.DisplayRole:
logging.debug("{0}/{1}".format(row, len(transactions)))
if transactions[row] in self.account.transactions_sent(self.community) \ if transactions[row] in self.account.transactions_sent(self.community) \
or transactions[row] in self.account.transactions_awaiting(self.community): or transactions[row] in self.account.transactions_awaiting(self.community):
return self.data_sent(transactions[row])[col] return self.data_sent(transactions[row])[col]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment