diff --git a/src/sakia/data/processors/identities.py b/src/sakia/data/processors/identities.py index f87543bcbf57e7ca8e8e5c6a66763c47ec5c3709..d0f87ca46da7135ee6a7b9c18b72291edb10a04d 100644 --- a/src/sakia/data/processors/identities.py +++ b/src/sakia/data/processors/identities.py @@ -100,6 +100,7 @@ class IdentitiesProcessor: def get_identity(self, currency, pubkey, uid=""): """ Return the identity corresponding to a given pubkey, uid and currency + If no UID is given, o :param str currency: :param str pubkey: :param str uid: optionally, specify an uid to lookup @@ -112,8 +113,11 @@ class IdentitiesProcessor: if identities: recent = identities[0] for i in identities: - if i.blockstamp > recent.blockstamp and i.uid == uid: - recent = i + if i.blockstamp > recent.blockstamp: + if uid and i.uid == uid: + recent = i + elif not uid: + recent = i return recent else: return written[0] diff --git a/src/sakia/data/processors/transactions.py b/src/sakia/data/processors/transactions.py index 277bba41f9c2bf720ba7e01cffd62b9cfcdca5dc..17bf2b7161a996c948f6603e82c51f83e451c267 100644 --- a/src/sakia/data/processors/transactions.py +++ b/src/sakia/data/processors/transactions.py @@ -25,6 +25,16 @@ class TransactionsProcessor: return cls(app.db.transactions_repo, BmaConnector(NodesProcessor(app.db.nodes_repo))) + def transfers(self, currency, pubkey): + """ + Get all transfers from or to a given pubkey + :param str currency: + :param str pubkey: + :return: the list of Transaction entities + :rtype: List[sakia.data.entities.Transaction] + """ + return self._repo.get_transfers(currency, pubkey) + def _try_transition(self, tx, transition_key, inputs): """ Try the transition defined by the given transition_key diff --git a/src/sakia/data/repositories/transactions.py b/src/sakia/data/repositories/transactions.py index 041aec29fc8f3a740f3e39efa8c6df7224a8433c..3457db6602f87ad6c50dfb8c8eddd862f1d711fd 100644 --- a/src/sakia/data/repositories/transactions.py +++ b/src/sakia/data/repositories/transactions.py @@ -87,6 +87,29 @@ class TransactionsRepo: return [Transaction(*data) for data in datas] return [] + def get_transfers(self, currency, pubkey, offset=0, limit=1000, sort_by="currency", sort_order="ASC"): + """ + Get all transfers in the database on a given currency from or to a pubkey + + :param str pubkey: the criterions of the lookup + :rtype: List[sakia.data.entities.Transaction] + """ + with self._conn: + request = """SELECT * FROM transactions + WHERE currency=? AND (issuer=? or receiver=?) + ORDER BY {sort_by} {sort_order} + LIMIT {limit} OFFSET {offset}""" \ + .format(offset=offset, + limit=limit, + sort_by=sort_by, + sort_order=sort_order + ) + c = self._conn.execute(request, (currency, pubkey, pubkey)) + datas = c.fetchall() + if datas: + return [Transaction(*data) for data in datas] + return [] + def drop(self, transaction): """ Drop an existing transaction from the database diff --git a/src/sakia/gui/navigation/model.py b/src/sakia/gui/navigation/model.py index 38ec512f80eeb477bd2b2d970296e9bc3b5dde84..296b3a841e1e89ce618858d55f4ba53ae339e8fd 100644 --- a/src/sakia/gui/navigation/model.py +++ b/src/sakia/gui/navigation/model.py @@ -43,14 +43,18 @@ class NavigationModel(ComponentModel): 'connection': connection, }, 'children': [ - # { - # 'node': { - # 'title': self.tr('Transfers'), - # 'icon': ':/icons/tx_icon', - # 'component': "TxHistory", - # 'transactions_service': self.app.transactions_services[connection.currency], - # } - # }, + { + 'node': { + 'title': self.tr('Transfers'), + 'icon': ':/icons/tx_icon', + 'component': "TxHistory", + 'connection': connection, + 'identities_service': self.app.identities_services[connection.currency], + 'blockchain_service': self.app.blockchain_services[connection.currency], + 'transactions_service': self.app.transactions_services[connection.currency], + "sources_service": self.app.sources_services[connection.currency] + } + }, { 'node': { 'title': self.tr('Network'), diff --git a/src/sakia/gui/navigation/txhistory/controller.py b/src/sakia/gui/navigation/txhistory/controller.py index c6f02e11bff28f86accc09bc565c5e2f99c4b4d7..4a749ab55e103ffb99fc29e13e8a7d894d070402 100644 --- a/src/sakia/gui/navigation/txhistory/controller.py +++ b/src/sakia/gui/navigation/txhistory/controller.py @@ -35,16 +35,19 @@ class TxHistoryController(ComponentController): self.view.date_from.dateChanged['QDate'].connect(self.dates_changed) self.view.date_to.dateChanged['QDate'].connect(self.dates_changed) self.view.table_history.customContextMenuRequested['QPoint'].connect(self.history_context_menu) - self.model.loading_progressed.connect(self.view.set_progress_bar) self.refresh() @classmethod def create(cls, parent, app, **kwargs): - account = kwargs['account'] - community = kwargs['community'] + connection = kwargs['connection'] + identities_service = kwargs['identities_service'] + blockchain_service = kwargs['blockchain_service'] + transactions_service = kwargs['transactions_service'] + sources_service = kwargs['sources_service'] view = TxHistoryView(parent.view) - model = TxHistoryModel(None, app, account, community) + model = TxHistoryModel(None, app, connection, blockchain_service, identities_service, + transactions_service, sources_service) txhistory = cls(parent, view, model) model.setParent(txhistory) return txhistory @@ -56,15 +59,13 @@ class TxHistoryController(ComponentController): @property def model(self) -> TxHistoryModel: return self._model - - @once_at_a_time - @asyncify - async def refresh_minimum_maximum(self): + + def refresh_minimum_maximum(self): """ Refresh minimum and maximum datetime """ - minimum, maximum = await self.model.minimum_maximum_datetime() - await self.view.set_minimum_maximum_datetime(minimum, maximum) + minimum, maximum = self.model.minimum_maximum_datetime() + self.view.set_minimum_maximum_datetime(minimum, maximum) def refresh(self): self.refresh_minimum_maximum() diff --git a/src/sakia/gui/navigation/txhistory/model.py b/src/sakia/gui/navigation/txhistory/model.py index 1eadcc0f2e2cb91d0c1cce27666677ff52a335ab..b183ce53b7af67186d0068e6935acf7eb1f587dd 100644 --- a/src/sakia/gui/navigation/txhistory/model.py +++ b/src/sakia/gui/navigation/txhistory/model.py @@ -11,23 +11,27 @@ class TxHistoryModel(ComponentModel): """ The model of Navigation component """ - loading_progressed = pyqtSignal(int, int) - - def __init__(self, parent, app, account, community): + def __init__(self, parent, app, connection, blockchain_service, identities_service, + transactions_service, sources_service): """ :param sakia.gui.txhistory.TxHistoryParent parent: the parent controller - :param sakia.core.Application app: the app - :param sakia.core.Account account: the account - :param sakia.core.Community community: the community + :param sakia.app.Application app: the app + :param sakia.data.entities.Connection connection: the connection + :param sakia.services.BlockchainService blockchain_service: the blockchain service + :param sakia.services.IdentitiesService identities_service: the identities service + :param sakia.services.TransactionsService transactions_service: the identities service + :param sakia.services.SourcesService sources_service: the sources service """ super().__init__(parent) self.app = app - self.account = account - self.community = community + self.connection = connection + self.blockchain_service = blockchain_service + self.identities_service = identities_service + self.transactions_service = transactions_service + self.sources_service = sources_service self._model = None self._proxy = None - self.connect_progress() def init_history_table_model(self, ts_from, ts_to): """ @@ -36,8 +40,9 @@ class TxHistoryModel(ComponentModel): :param int ts_to: date to where to filter tx :return: """ - self._model = HistoryTableModel(self.app, self.account, self.community) - self._proxy = TxFilterProxyModel(ts_from, ts_to) + self._model = HistoryTableModel(self, self.app, self.connection, + self.identities_service, self.transactions_service) + self._proxy = TxFilterProxyModel(self, ts_from, ts_to, self.blockchain_service) self._proxy.setSourceModel(self._model) self._proxy.setDynamicSortFilter(True) self._proxy.setSortRole(Qt.DisplayRole) @@ -55,8 +60,7 @@ class TxHistoryModel(ComponentModel): source_index = self.table_model.mapToSource(index) pubkey_col = self.table_model.sourceModel().columns_types.index('pubkey') - pubkey_index = self.table_model.sourceModel().index(source_index.row(), - pubkey_col) + pubkey_index = self.table_model.sourceModel().index(source_index.row(), pubkey_col) pubkey = self.table_model.sourceModel().data(pubkey_index, Qt.DisplayRole) identity = await self.app.identities_registry.future_find(pubkey, self.community) @@ -65,30 +69,16 @@ class TxHistoryModel(ComponentModel): return True, identity, transfer return False, None, None - def connect_progress(self): - def progressing(community, value, maximum): - if community == self.community: - self.loading_progressed.emit(value, maximum) - - self.account.loading_progressed.connect(progressing) - self.account.loading_finished.connect(self.stop_progress) - - def stop_progress(self, community, received_list): - if community == self.community: - self.loading_progressed.emit(100, 100) - self.table_model.sourceModel().refresh_transfers() - self.parent().notification_reception(received_list) - - async def minimum_maximum_datetime(self): + def minimum_maximum_datetime(self): """ Get minimum and maximum datetime :rtype: Tuple[PyQt5.QtCore.QDateTime, PyQt5.QtCore.QDateTime] :return: minimum and maximum datetime """ try: - block = await self.community.get_block(1) + blockchain_time = self.blockchain_service.time() minimum_datetime = QDateTime() - minimum_datetime.setTime_t(block['medianTime']) + minimum_datetime.setTime_t(blockchain_time) minimum_datetime.setTime(QTime(0, 0)) tomorrow_datetime = QDateTime().currentDateTime().addDays(1) return minimum_datetime, tomorrow_datetime @@ -107,24 +97,20 @@ class TxHistoryModel(ComponentModel): amount = 0 for r in received_list: amount += r.metadata['amount'] - localized_amount = await self.app.current_account.current_ref.instance(amount, self.community, self.app) \ - .localized(units=True, - international_system=self.app.preferences['international_system_of_units']) + localized_amount = await self.app.current_ref.instance(amount, self.connection.currency, self.app) \ + .localized(units=True, international_system=self.app.parameters.international_system_of_units) return localized_amount - async def localized_balance(self): + def localized_balance(self): """ Get the localized amount of the given tx history :return: the localized amount of given account in given community :rtype: int """ try: - amount = await self.app.current_account.amount(self.community) - localized_amount = await self.app.current_account.current_ref.instance(amount, self.community, - self.app).localized(units=True, - international_system= - self.app.preferences[ - 'international_system_of_units']) + amount = self.sources_service.amount(self.connection.pubkey) + localized_amount = self.app.current_ref.instance(amount, self.connection.currency, self.app)\ + .localized(units=True, international_system=self.app.parameters.international_system_of_units) return localized_amount except NoPeerAvailable as e: logging.debug(str(e)) @@ -137,4 +123,4 @@ class TxHistoryModel(ComponentModel): return self._proxy def notifications(self): - return self.app.preferences['notifications'] \ No newline at end of file + return self.app.parameters.notifications \ No newline at end of file diff --git a/src/sakia/gui/navigation/txhistory/table_model.py b/src/sakia/gui/navigation/txhistory/table_model.py index 4fcad39c534ed1802cfbc418daf32cf3e9ffc0de..2ce9d2c3cc7fee714828f32754edadd6ea5b8829 100644 --- a/src/sakia/gui/navigation/txhistory/table_model.py +++ b/src/sakia/gui/navigation/txhistory/table_model.py @@ -14,17 +14,27 @@ from PyQt5.QtCore import QAbstractTableModel, Qt, QVariant, QSortFilterProxyMode from PyQt5.QtGui import QFont, QColor, QIcon from sakia.errors import NoPeerAvailable from sakia.data.entities import Transaction +from sakia.constants import MAX_CONFIRMATIONS from sakia.decorators import asyncify, once_at_a_time, cancel_once_task class TxFilterProxyModel(QSortFilterProxyModel): - def __init__(self, ts_from, ts_to, parent=None): + def __init__(self, parent, ts_from, ts_to, blockchain_service): + """ + History of all transactions + :param PyQt5.QtWidgets.QWidget parent: parent widget + :param int ts_from: the min timestamp of latest tx + :param in ts_to: the max timestamp of most recent tx + :param sakia.services.BlockchainService blockchain_service: the blockchain service + """ super().__init__(parent) self.app = None self.ts_from = ts_from self.ts_to = ts_to self.payments = 0 self.deposits = 0 + self.blockchain_service = blockchain_service + @property def account(self): @@ -154,18 +164,14 @@ class TxFilterProxyModel(QSortFilterProxyModel): current_confirmations = 0 if state_data == Transaction.VALIDATING: - current_blockUID_number = self.community.network.current_blockUID.number - if current_blockUID_number: - current_confirmations = current_blockUID_number - block_data + current_confirmations = self.blockchain_service.current_buid().number - block_data elif state_data == Transaction.AWAITING: current_confirmations = 0 - max_confirmations = self.sourceModel().max_confirmations() - if self.app.preferences['expert_mode']: - return self.tr("{0} / {1} confirmations").format(current_confirmations, max_confirmations) + return self.tr("{0} / {1} confirmations").format(current_confirmations, MAX_CONFIRMATIONS) else: - confirmation = current_confirmations / max_confirmations * 100 + confirmation = current_confirmations / MAX_CONFIRMATIONS * 100 confirmation = 100 if confirmation > 100 else confirmation return self.tr("Confirming... {0} %").format(QLocale().toString(float(confirmation), 'f', 0)) @@ -178,14 +184,20 @@ class HistoryTableModel(QAbstractTableModel): A Qt abstract item model to display communities in a tree """ - def __init__(self, app, account, community, parent=None): + def __init__(self, parent, app, connection, identities_service, transactions_service): """ - Constructor + History of all transactions + :param PyQt5.QtWidgets.QWidget parent: parent widget + :param sakia.app.Application app: the main application + :param sakia.data.entities.Connection connection: the connection + :param sakia.services.IdentitiesService identities_service: the identities service + :param sakia.services.TransactionsService transactions_service: the transactions service """ super().__init__(parent) self.app = app - self.account = account - self.community = community + self.connection = connection + self.identities_service = identities_service + self.transactions_service = transactions_service self.transfers_data = [] self.refresh_transfers() @@ -214,124 +226,93 @@ class HistoryTableModel(QAbstractTableModel): lambda: 'Block Number' ) - def change_account(self, account): - cancel_once_task(self, self.refresh_transfers) - self.account = account - - def change_community(self, community): - cancel_once_task(self, self.refresh_transfers) - self.community = community - def transfers(self): - if self.account: - return self.account.transfers(self.community) + self.account.dividends(self.community) - else: - return [] + """ + Transfer + :rtype: sakia.data.entities.Transfer + """ + #TODO: Handle dividends + return self.transactions_service.transfers(self.connection.pubkey) - async def data_received(self, transfer): - amount = transfer.metadata['amount'] - if transfer.blockUID: - block_number = transfer.blockUID.number + def data_received(self, transfer): + """ + Converts a transaction to table data + :param sakia.data.entities.Transaction transfer: the transaction + :return: data as tuple + """ + if transfer.blockstamp: + block_number = transfer.blockstamp.number else: block_number = None + + amount = transfer.amount * 10**transfer.amount_base try: - deposit = await self.account.current_ref.instance(transfer.metadata['amount'], self.community, - self.app, block_number)\ + deposit = self.account.current_ref.instance(amount, self.connection.currency, self.app, block_number)\ .diff_localized(international_system=self.app.preferences['international_system_of_units']) except NoPeerAvailable: deposit = "Could not compute" - comment = "" - if transfer.metadata['comment'] != "": - comment = transfer.metadata['comment'] - if transfer.metadata['issuer_uid'] != "": - sender = transfer.metadata['issuer_uid'] + + identity = self.identities_service.get_identity(transfer.receiver) + if identity: + sender = identity.uid else: - sender = "pub:{0}".format(transfer.metadata['issuer'][:5]) + sender = "pub:{0}".format(transfer.receiver[:5]) - date_ts = transfer.metadata['time'] - txid = transfer.metadata['txid'] + date_ts = transfer.timestamp + txid = transfer.txid return (date_ts, sender, "", deposit, - comment, transfer.state, txid, + transfer.comment, transfer.state, txid, transfer.metadata['issuer'], block_number, amount) async def data_sent(self, transfer): - if transfer.blockUID: - block_number = transfer.blockUID.number + """ + Converts a transaction to table data + :param sakia.data.entities.Transaction transfer: the transaction + :return: data as tuple + """ + if transfer.blockstamp: + block_number = transfer.blockstamp.number else: block_number = None - amount = transfer.metadata['amount'] + amount = transfer.amount * 10**transfer.amount_base try: - paiment = await self.account.current_ref.instance(transfer.metadata['amount'], self.community, - self.app, block_number)\ - .diff_localized(international_system=self.app.preferences['international_system_of_units']) + paiement = self.app.current_ref.instance(amount, self.connection.currency, self.app, block_number)\ + .diff_localized(international_system=self.app.parameters.international_system_of_units) except NoPeerAvailable: - paiment = "Could not compute" - comment = "" - if transfer.metadata['comment'] != "": - comment = transfer.metadata['comment'] - if transfer.metadata['receiver_uid'] != "": - receiver = transfer.metadata['receiver_uid'] + paiement = "Could not compute" + + identity = self.identities_service.get_identity(transfer.receiver) + if identity: + receiver = identity.uid else: - receiver = "pub:{0}".format(transfer.metadata['receiver'][:5]) + receiver = "pub:{0}".format(transfer.receiver[:5]) - date_ts = transfer.metadata['time'] - txid = transfer.metadata['txid'] - return (date_ts, receiver, paiment, - "", comment, transfer.state, txid, - transfer.metadata['receiver'], block_number, amount) + date_ts = transfer.timestamp + txid = transfer.txid + return (date_ts, receiver, paiement, + "", transfer.comment, transfer.state, txid, + transfer.receiver, block_number, amount) async def data_dividend(self, dividend): - amount = dividend['amount'] * math.pow(10, dividend['base']) - try: - deposit = await self.account.current_ref.instance(amount, self.community, self.app, dividend['block_number'])\ - .diff_localized(international_system=self.app.preferences['international_system_of_units']) - except NoPeerAvailable: - deposit = "Could not compute" - comment = "" - receiver = self.account.name - date_ts = dividend['time'] - id = dividend['id'] - block_number = dividend['block_number'] - state = dividend['state'] - - return (date_ts, receiver, "", - deposit, "", state, id, - self.account.pubkey, block_number, amount) - - @once_at_a_time - @asyncify - async def refresh_transfers(self): - self.beginResetModel() - self.transfers_data = [] - self.endResetModel() + pass + + def refresh_transfers(self): self.beginResetModel() transfers_data = [] - if self.community: - requests_coro = [] - data_list = [] - count = 0 - transfers = self.transfers() - for transfer in transfers: - coro = None - count += 1 - if type(transfer) is Transaction: - if transfer.metadata['issuer'] == self.account.pubkey: - coro = asyncio.ensure_future(self.data_sent(transfer)) - else: - coro = asyncio.ensure_future(self.data_received(transfer)) - elif type(transfer) is dict: - coro = asyncio.ensure_future(self.data_dividend(transfer)) - if coro: - requests_coro.append(coro) - if count % 25 == 0: - gathered_list = await asyncio.gather(*requests_coro) - requests_coro = [] - data_list.extend(gathered_list) - # One last gathering - gathered_list = await asyncio.gather(*requests_coro) - data_list.extend(gathered_list) + data_list = [] + count = 0 + transfers = self.transfers() + for transfer in transfers: + count += 1 + if type(transfer) is Transaction: + if transfer.issuer == self.connection.pubkey: + data_list += self.data_sent(transfer) + else: + data_list += self.data_received(transfer) + elif type(transfer) is dict: + data_list += self.data_dividend(transfer) for data in data_list: transfers_data.append(data) @@ -345,15 +326,14 @@ class HistoryTableModel(QAbstractTableModel): return len(self.columns_types) def headerData(self, section, orientation, role): - if self.account and self.community: - if role == Qt.DisplayRole: - if self.columns_types[section] == 'payment' or self.columns_types[section] == 'deposit': - return '{:}\n({:})'.format( - self.column_headers[section](), - self.account.current_ref.instance(0, self.community, self.app, None).diff_units - ) - - return self.column_headers[section]() + if role == Qt.DisplayRole: + if self.columns_types[section] == 'payment' or self.columns_types[section] == 'deposit': + return '{:}\n({:})'.format( + self.column_headers[section](), + self.app.current_ref.instance(0, self.connection.currency, self.app, None).diff_units + ) + + return self.column_headers[section]() def data(self, index, role): row = index.row() diff --git a/src/sakia/gui/navigation/txhistory/txhistory.ui b/src/sakia/gui/navigation/txhistory/txhistory.ui index 8aa79961a224b47b29042bc02e8f62d752040095..838345c54cfeb45b29caea9b3b1dc9f9d1f905d1 100644 --- a/src/sakia/gui/navigation/txhistory/txhistory.ui +++ b/src/sakia/gui/navigation/txhistory/txhistory.ui @@ -72,16 +72,6 @@ </item> </layout> </item> - <item> - <widget class="QProgressBar" name="progressbar"> - <property name="maximum"> - <number>0</number> - </property> - <property name="value"> - <number>-1</number> - </property> - </widget> - </item> <item> <widget class="QTableView" name="table_history"> <property name="contextMenuPolicy"> @@ -117,7 +107,7 @@ </customwidget> </customwidgets> <resources> - <include location="../../../../res/icons/icons.qrc"/> + <include location="../../../../../res/icons/icons.qrc"/> </resources> <connections/> </ui> diff --git a/src/sakia/gui/navigation/txhistory/view.py b/src/sakia/gui/navigation/txhistory/view.py index c1049f3455a5f196940fc28cd0d2d0ff224a1d01..78a840b6a7cf6dbd2594de8fbb2dc9affa60e3d9 100644 --- a/src/sakia/gui/navigation/txhistory/view.py +++ b/src/sakia/gui/navigation/txhistory/view.py @@ -12,7 +12,6 @@ class TxHistoryView(QWidget, Ui_TxHistoryWidget): super().__init__(parent) self.setupUi(self) self.busy_balance.hide() - self.progressbar.hide() def get_time_frame(self): """ @@ -35,7 +34,7 @@ class TxHistoryView(QWidget, Ui_TxHistoryWidget): model.modelReset.connect(lambda: self.table_history.setEnabled(True)) model.modelReset.connect(self.table_history.resizeColumnsToContents) - async def set_minimum_maximum_datetime(self, minimum, maximum): + def set_minimum_maximum_datetime(self, minimum, maximum): """ Configure minimum and maximum datetime in date filter :param PyQt5.QtCore.QDateTime minimum: the minimum @@ -60,20 +59,6 @@ class TxHistoryView(QWidget, Ui_TxHistoryWidget): "{:}".format(balance) ) - def set_progress_bar(self, value, maximum): - """ - Set progress bar value - :param int value: - :param maximum: - :return: - """ - if value >= maximum: - self.progressbar.hide() - else: - self.progressbar.show() - self.progressbar.setValue(value) - self.progressbar.setMaximum(maximum) - def resizeEvent(self, event): self.busy_balance.resize(event.size()) super().resizeEvent(event) diff --git a/src/sakia/services/blockchain.py b/src/sakia/services/blockchain.py index 28c010416c302b77f1ed0b0ce69e557279f058c4..7b2cede4cab6e0b8c75d418375a55667331b3700 100644 --- a/src/sakia/services/blockchain.py +++ b/src/sakia/services/blockchain.py @@ -37,9 +37,15 @@ class BlockchainService(QObject): await self._identities_service.handle_new_blocks(blocks) await self._transactions_service.handle_new_blocks(blocks) + def current_buid(self): + return self._blockchain_processor.current_buid(self.currency) + def parameters(self): return self._blockchain_processor.parameters(self.currency) + def time(self): + return self._blockchain_processor.time(self.currency) + def current_members_count(self): return self._blockchain_processor.current_members_count(self.currency) diff --git a/src/sakia/services/identities.py b/src/sakia/services/identities.py index e6d173b5eaa21d414576a05ad2aa535d0a81faa5..4d59cc156ebdf43b965a9805260067aa0f40e2fb 100644 --- a/src/sakia/services/identities.py +++ b/src/sakia/services/identities.py @@ -265,6 +265,9 @@ class IdentitiesService(QObject): """ return await self._identities_processor.lookup(self.currency, text) + def get_identity(self, pubkey, uid=""): + return self._identities_processor.get_identity(self.currency, pubkey, uid) + def expiration_date(self, identity): """ Get the expiration date of the identity diff --git a/src/sakia/services/transactions.py b/src/sakia/services/transactions.py index 76c76e9647f2e3f8b941be627bf766d884cd5ae8..f45569ce6a1c65d970a06e1e37824c305e0918a9 100644 --- a/src/sakia/services/transactions.py +++ b/src/sakia/services/transactions.py @@ -1,9 +1,6 @@ from PyQt5.QtCore import QObject -from duniterpy.api import bma -from duniterpy.grammars.output import Condition from duniterpy.documents.transaction import reduce_base from duniterpy.documents import Transaction, SimpleTransaction -from duniterpy.api import errors from sakia.data.entities import Transaction import math import logging @@ -21,7 +18,7 @@ class TransactionsService(QObject): :param str currency: The currency name of the community :param sakia.data.processors.IdentitiesProcessor identities_processor: the identities processor for given currency - :param sakia.data.processors.TransactionProcessor transactions_processor: the transactions processor for given currency + :param sakia.data.processors.TransactionsProcessor transactions_processor: the transactions processor for given currency :param sakia.data.connectors.BmaConnector bma_connector: The connector to BMA API """ super().__init__() @@ -106,10 +103,9 @@ class TransactionsService(QObject): block_doc.mediantime, txid+i) if tx: #logging.debug("Transfer amount : {0}".format(transfer.metadata['amount'])) - transfers.append(tx) + self._transactions_processor.commit(tx) else: - pass - #logging.debug("None transfer") + logging.debug("Error during transfer parsing") return transfers async def handle_new_blocks(self, blocks): @@ -123,3 +119,12 @@ class TransactionsService(QObject): for block in blocks: transfers = await self._parse_block(block, txid) txid += len(transfers) + + def transfers(self, pubkey): + """ + Get all transfers from or to a given pubkey + :param str pubkey: + :return: the list of Transaction entities + :rtype: List[sakia.data.entities.Transaction] + """ + return self._transactions_processor.transfers(self.currency, pubkey) \ No newline at end of file