Skip to content
Snippets Groups Projects
Commit 44cd9a84 authored by inso's avatar inso
Browse files

Transactions refused now appear in red

parent a8f625e6
No related branches found
No related tags found
No related merge requests found
......@@ -3,7 +3,7 @@ Created on 31 janv. 2015
@author: inso
'''
import logging
from ucoinpy.api import bma
from ucoinpy.documents.transaction import Transaction
......@@ -65,10 +65,15 @@ class Transfer(object):
self.metadata['time'] = community.get_block().time
def check_registered(self, tx, metadata):
logging.debug("{0} > {1} ?".format(metadata['block'],
self.metadata['block'] + 15))
if tx.signed_raw() == self.txdoc.signed_raw():
self.state = Transfer.VALIDATED
self.metadata = metadata
if metadata['block'] > self.metadata['block'] + 15:
def check_refused(self, block):
if block > self.metadata['block'] + 15:
self.state = Transfer.REFUSED
......
......@@ -59,14 +59,15 @@ class Cache():
def refresh(self, community):
current_block = 0
try:
try:
block_data = community.request(bma.blockchain.Current)
current_block = block_data['number']
except ValueError as e:
if '404' in str(e):
current_block = 0
else:
raise
block_data = community.current_blockid()
current_block = block_data['number']
# Lets look if transactions took too long to be validated
awaiting = [t for t in self._transfers
if t.state == Transfer.AWAITING]
for transfer in awaiting:
transfer.check_refused(current_block)
with_tx = community.request(bma.blockchain.TX)
# We parse only blocks with transactions
......@@ -109,8 +110,9 @@ class Cache():
if tx.signed_raw() not in awaiting_docs:
transfer = Transfer.create_validated(tx, metadata)
self._transfers.append(transfer)
for transfer in awaiting:
transfer.check_registered(tx, metadata)
else:
for transfer in awaiting:
transfer.check_registered(tx, metadata)
else:
outputs = [o for o in tx.outputs
if o.pubkey == self.wallet.pubkey]
......
......@@ -9,8 +9,8 @@ from ..core.transfer import Transfer, Received
from ..core.person import Person
from ..tools.exceptions import PersonNotFoundError
from PyQt5.QtCore import QAbstractTableModel, Qt, QVariant, QSortFilterProxyModel, \
QDateTime, QModelIndex
from PyQt5.QtGui import QFont
QDateTime
from PyQt5.QtGui import QFont, QColor
class TxFilterProxyModel(QSortFilterProxyModel):
......@@ -147,9 +147,15 @@ class HistoryTableModel(QAbstractTableModel):
font = QFont()
if transfer.state == Transfer.AWAITING:
font.setItalic(True)
elif transfer.state == Transfer.REFUSED:
font.setItalic(True)
else:
font.setItalic(False)
return font
if role == Qt.ForegroundRole:
if transfer.state == Transfer.REFUSED:
return QColor(Qt.red)
def flags(self, index):
return Qt.ItemIsSelectable | Qt.ItemIsEnabled
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