Skip to content
Snippets Groups Projects
Commit 9ec4cb93 authored by inso's avatar inso
Browse files

Handle new dividends

parent ee751279
No related branches found
No related tags found
No related merge requests found
......@@ -4,15 +4,13 @@ import logging
import aiohttp
from PyQt5.QtCore import QObject, pyqtSignal, QTranslator, QCoreApplication, QLocale
from aiohttp.connector import ProxyConnector
from . import __version__
from .options import SakiaOptions
from sakia.data.connectors import BmaConnector
from sakia.services import NetworkService, BlockchainService, IdentitiesService, \
SourcesServices, TransactionsService, DocumentsService
from sakia.data.repositories import SakiaDatabase
from sakia.data.entities import Transaction, Connection, Identity
from sakia.data.entities import Transaction, Connection, Identity, Dividend
from sakia.data.processors import BlockchainProcessor, NodesProcessor, IdentitiesProcessor, \
CertificationsProcessor, SourcesProcessor, TransactionsProcessor, ConnectionsProcessor, DividendsProcessor
from sakia.data.files import AppDataFile, UserParametersFile
......@@ -43,6 +41,7 @@ class Application(QObject):
:param sakia.services.DocumentsService documents_service: A service to broadcast documents
"""
new_dividend = pyqtSignal(Dividend)
new_transfer = pyqtSignal(Transaction)
transaction_state_changed = pyqtSignal(Transaction)
identity_changed = pyqtSignal(Identity)
......
......@@ -48,6 +48,7 @@ class TxHistoryModel(QObject):
self._proxy.setSortRole(Qt.DisplayRole)
self._model.init_transfers()
self.app.new_transfer.connect(self._model.add_transfer)
self.app.new_dividend.connect(self._model.add_dividend)
self.app.transaction_state_changed.connect(self._model.change_transfer)
self.app.referential_changed.connect(self._model.modelReset)
......
......@@ -212,15 +212,18 @@ class HistoryTableModel(QAbstractTableModel):
def add_transfer(self, transfer):
self.beginInsertRows(QModelIndex(), 0, 0)
if isinstance(transfer, Transaction):
if transfer.issuer == self.connection.pubkey:
self.transfers_data.append(self.data_sent(transfer))
else:
self.transfers_data.append(self.data_received(transfer))
self.endInsertRows()
def add_dividend(self, dividend):
self.beginInsertRows(QModelIndex(), 0, 0)
self.transfers_data.append(self.data_dividend(dividend))
self.endInsertRows()
def change_transfer(self, transfer):
if isinstance(transfer, Transaction):
for i, data in enumerate(self.transfers_data):
if data[self.columns_types.index('txhash')] == transfer.sha_hash:
if transfer.issuer == self.connection.pubkey:
......
......@@ -127,7 +127,8 @@ class ContextMenu(QObject):
UserInformationController.show_identity(self.parent(), self._app, self._connection.currency, identity)
self.identity_information_loaded.emit(identity)
else:
UserInformationController.open_dialog(self.parent(), self._app, self._connection.currency, identity)
UserInformationController.search_and_show_pubkey(self.parent(), self._app, self._connection.currency,
identity.pubkey)
@asyncify
......
......@@ -42,13 +42,16 @@ class BlockchainService(QObject):
blocks = await self._blockchain_processor.blocks(with_identities + with_money + [network_blockstamp.number],
self.currency)
identities = await self._identities_service.handle_new_blocks(blocks)
transfers_changed, new_transfers = self._transactions_service.handle_new_blocks(blocks)
transfers_changed, new_transfers, new_dividends = self._transactions_service.handle_new_blocks(blocks)
self._blockchain_processor.handle_new_blocks(self.currency, blocks)
self.app.db.commit()
for tx in transfers_changed:
self.app.transaction_state_changed.emit(tx)
for tx in new_transfers:
self.app.new_transfer.emit(tx)
for ud in new_dividends:
self.app.new_dividend.emit(ud)
for idty in identities:
self.app.identity_changed.emit(idty)
except (NoPeerAvailable, DuniterError) as e:
......
......@@ -40,6 +40,7 @@ class TransactionsService(QObject):
"""
transfers_changed = []
new_transfers = []
new_dividends = []
for tx in [t for t in self._transactions_processor.awaiting(self.currency)]:
if self._transactions_processor.run_state_transitions(tx, block_doc):
transfers_changed.append(tx)
......@@ -56,6 +57,7 @@ class TransactionsService(QObject):
timestamp=block_doc.mediantime,
amount=block_doc.ud,
base=block_doc.unit_base)
new_dividends.append(dividend)
self._dividends_processor.commit(dividend)
for (i, tx_doc) in enumerate(new_transactions):
......@@ -66,7 +68,7 @@ class TransactionsService(QObject):
else:
logging.debug("Error during transfer parsing")
return transfers_changed, new_transfers
return transfers_changed, new_transfers, new_dividends
def handle_new_blocks(self, blocks):
"""
......@@ -77,13 +79,15 @@ class TransactionsService(QObject):
self._logger.debug("Refresh transactions")
transfers_changed = []
new_transfers = []
new_dividends = []
txid = 0
for block in blocks:
changes, news = self._parse_block(block, txid)
txid += len(news)
changes, new_tx, new_ud = self._parse_block(block, txid)
txid += len(new_tx)
transfers_changed += changes
new_transfers += news
return transfers_changed, new_transfers
new_transfers += new_tx
new_dividends += new_ud
return transfers_changed, new_transfers, new_dividends
def transfers(self, pubkey):
"""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment