diff --git a/src/sakia/data/connectors/bma.py b/src/sakia/data/connectors/bma.py index 65e639f77961d10c4f199c34b9464fa8da84d4d5..241b4e742628a654163641491002b6ad57538895 100644 --- a/src/sakia/data/connectors/bma.py +++ b/src/sakia/data/connectors/bma.py @@ -142,7 +142,7 @@ class BmaConnector: responses = await asyncio.gather(*futures, return_exceptions=True) for r in responses: if isinstance(r, errors.DuniterError): - data_hash = hash(r) + data_hash = hash(r.ucode) elif isinstance(r, BaseException): self._logger.debug("Exception in responses : " + str(r)) continue diff --git a/src/sakia/data/processors/transactions.py b/src/sakia/data/processors/transactions.py index 39e765b10ab32f9b22841abb69b4fa494aef0f61..c247630dc50eec517da19f3ca49325c3b7f13cf3 100644 --- a/src/sakia/data/processors/transactions.py +++ b/src/sakia/data/processors/transactions.py @@ -98,7 +98,7 @@ class TransactionsProcessor: """ transition_keys = [k for k in tx_lifecycle.states.keys() if k[0] == tx.state] for key in transition_keys: - if self._try_transition(tx, key, inputs): + if self._try_transition(tx, key, *inputs): self._repo.update(tx) return True return False @@ -120,6 +120,7 @@ class TransactionsProcessor: :param txdoc: A transaction duniterpy object :param currency: The community target of the transaction """ + self._logger.debug(txdoc.signed_raw()) self._repo.insert(tx) responses = await self._bma_connector.broadcast(currency, bma.tx.process, req_args={'transaction': txdoc.signed_raw()}) result = (False, "") @@ -132,7 +133,7 @@ class TransactionsProcessor: result = (False, (await r.text())) else: await r.text() - self.run_state_transitions(tx, [r.status for r in responses]) + self.run_state_transitions(tx, [r.status for r in responses if not isinstance(r, BaseException)]) return result, tx async def initialize_transactions(self, connection, log_stream): diff --git a/src/sakia/gui/dialogs/transfer/controller.py b/src/sakia/gui/dialogs/transfer/controller.py index 3e0ba57ed6f9594fd66f6022bea52176ceaf5b7d..f4e3cc4520dee62041ef65a4a78ea00b5408b656 100644 --- a/src/sakia/gui/dialogs/transfer/controller.py +++ b/src/sakia/gui/dialogs/transfer/controller.py @@ -4,6 +4,7 @@ import logging from PyQt5.QtCore import Qt, QObject from PyQt5.QtWidgets import QApplication +from sakia.data.processors import ConnectionsProcessor from sakia.decorators import asyncify from sakia.gui.password_asker import PasswordAskerDialog from sakia.gui.sub.search_user.controller import SearchUserController @@ -79,26 +80,26 @@ class TransferController(QObject): return await dialog.async_exec() @classmethod - async def send_transfer_again(cls, parent, app, connection, resent_transfer): + def send_transfer_again(cls, parent, app, connection, resent_transfer): dialog = cls.create(parent, app) dialog.view.combo_connections.setCurrentText(connection.title()) dialog.view.edit_pubkey.setText(resent_transfer.receiver) dialog.view.radio_pubkey.setChecked(True) dialog.refresh() - relative = await dialog.model.quant_to_rel(resent_transfer.metadata['amount']) - dialog.view.set_spinboxes_parameters(1, resent_transfer.metadata['amount'], relative) + relative = dialog.model.quant_to_rel(resent_transfer.amount) + dialog.view.set_spinboxes_parameters(1, resent_transfer.amount, relative) dialog.view.change_relative_amount(relative) - dialog.view.change_quantitative_amount(resent_transfer.metadata['amount']) + dialog.view.change_quantitative_amount(resent_transfer.amount) - account = resent_transfer.metadata['issuer'] - wallet_index = [w.pubkey for w in app.current_account.wallets].index(account) + connections_processor = ConnectionsProcessor.instanciate(app) + wallet_index = connections_processor.connections().index(connection) dialog.view.combo_connections.setCurrentIndex(wallet_index) - dialog.view.edit_pubkey.setText(resent_transfer.metadata['receiver']) + dialog.view.edit_pubkey.setText(resent_transfer.receiver) dialog.view.radio_pubkey.setChecked(True) - dialog.view.edit_message.setText(resent_transfer.metadata['comment']) + dialog.view.edit_message.setText(resent_transfer.comment) - return await dialog.async_exec() + return dialog.exec() def set_search_user(self, search_user): """ diff --git a/src/sakia/gui/navigation/txhistory/table_model.py b/src/sakia/gui/navigation/txhistory/table_model.py index 789d4f03a2a53074089cef4e23c62d4ffcf78f17..40d588d8f3fe9ae5f3f811bf3b1602634bcfe1b6 100644 --- a/src/sakia/gui/navigation/txhistory/table_model.py +++ b/src/sakia/gui/navigation/txhistory/table_model.py @@ -226,11 +226,16 @@ class HistoryTableModel(QAbstractTableModel): def change_transfer(self, transfer): for i, data in enumerate(self.transfers_data): if data[self.columns_types.index('txhash')] == transfer.sha_hash: - if transfer.issuer == self.connection.pubkey: + if transfer.state == Transaction.DROPPED: + self.beginRemoveRows(QModelIndex(), i, i) + self.transfers_data.pop(i) + self.endRemoveRows() + elif transfer.issuer == self.connection.pubkey: self.transfers_data[i] = self.data_sent(transfer) + self.dataChanged.emit(self.index(i, 0), self.index(i, len(self.columns_types))) else: self.transfers_data[i] = self.data_received(transfer) - self.dataChanged.emit(self.index(i, 0), self.index(i, len(self.columns_types))) + self.dataChanged.emit(self.index(i, 0), self.index(i, len(self.columns_types))) return def data_received(self, transfer): @@ -300,10 +305,11 @@ class HistoryTableModel(QAbstractTableModel): self.transfers_data = [] transfers = self.transfers() for transfer in transfers: - if transfer.issuer == self.connection.pubkey: - self.transfers_data.append(self.data_sent(transfer)) - else: - self.transfers_data.append(self.data_received(transfer)) + if transfer.state != Transaction.DROPPED: + if transfer.issuer == self.connection.pubkey: + self.transfers_data.append(self.data_sent(transfer)) + else: + self.transfers_data.append(self.data_received(transfer)) dividends = self.dividends() for dividend in dividends: self.transfers_data.append(self.data_dividend(dividend)) diff --git a/src/sakia/gui/widgets/context_menu.py b/src/sakia/gui/widgets/context_menu.py index 340ee2080a99b6cc3095dcb8019ca27539df8426..817e01d8bfe2d0c4f4d815a9109dc5cb2a41037c 100644 --- a/src/sakia/gui/widgets/context_menu.py +++ b/src/sakia/gui/widgets/context_menu.py @@ -5,7 +5,7 @@ from PyQt5.QtWidgets import QMenu, QAction, QApplication, QMessageBox from duniterpy.documents import Block from sakia.data.entities import Identity, Transaction -from sakia.data.processors import BlockchainProcessor +from sakia.data.processors import BlockchainProcessor, TransactionsProcessor from sakia.decorators import asyncify from sakia.gui.dialogs.certification.controller import CertificationController from sakia.gui.dialogs.transfer.controller import TransferController @@ -142,10 +142,8 @@ class ContextMenu(QObject): async def certify_identity(self, identity): await CertificationController.certify_identity(None, self._app, self._connection, identity) - @asyncify - async def send_again(self, transfer): - await TransferController.send_transfer_again(None, self._app, self._connection, transfer) - self._app.refresh_transfers.emit() + def send_again(self, transfer): + TransferController.send_transfer_again(None, self._app, self._connection, transfer) def cancel_transfer(self, transfer): reply = QMessageBox.warning(self.qmenu, self.tr("Warning"), @@ -153,8 +151,10 @@ class ContextMenu(QObject): This money transfer will be removed and not sent."""), QMessageBox.Ok | QMessageBox.Cancel) if reply == QMessageBox.Ok: - transfer.cancel() - self._app.refresh_transfers.emit() + transactions_processor = TransactionsProcessor.instanciate(self._app) + transactions_processor.cancel(transfer) + self._app.db.commit() + self._app.transaction_state_changed.emit(transfer) def copy_transaction_to_clipboard(self, tx): clipboard = QApplication.clipboard()