diff --git a/src/sakia/data/entities/transaction.py b/src/sakia/data/entities/transaction.py index 1a282b9d1183a96825c4a81da4d745153153e6cf..e321d013423f73a2f9f8c32396d34549bfab8119 100644 --- a/src/sakia/data/entities/transaction.py +++ b/src/sakia/data/entities/transaction.py @@ -1,5 +1,6 @@ import attr from duniterpy.documents import block_uid +from duniterpy.documents import Transaction as TransactionDoc from duniterpy.documents.transaction import reduce_base from sakia.helpers import attrs_tuple_of_str import math @@ -77,7 +78,7 @@ class Transaction: :param str currency: the currency of the transaction :param str sha_hash: the hash of the transaction :param int written_block: the number of the block - :param str blockstamp: the blockstamp of the transaction + :param duniterpy.documents.BlockUID blockstamp: the blockstamp of the transaction :param int timestamp: the timestamp of the transaction :param str signature: the signature :param str issuer: the pubkey of the issuer @@ -110,3 +111,9 @@ class Transaction: state = attr.ib(convert=int, cmp=False) local = attr.ib(convert=bool, cmp=False, default=False) raw = attr.ib(convert=str, cmp=False, default="") + + def txdoc(self): + """ + :rtype: duniterpy.documents.Transaction + """ + return TransactionDoc.from_signed_raw(self.raw) diff --git a/src/sakia/gui/dialogs/transfer/model.py b/src/sakia/gui/dialogs/transfer/model.py index 7231b38659cb133bbbda02abd7a664ee7893cd8f..86b758590837d9161d2ead704c2c399b31c52ab6 100644 --- a/src/sakia/gui/dialogs/transfer/model.py +++ b/src/sakia/gui/dialogs/transfer/model.py @@ -95,10 +95,13 @@ class TransferModel(QObject): recipient, amount, amount_base, comment) for transaction in transactions: self.app.sources_service.parse_transaction(self.connection.pubkey, transaction) - if recipient in self._connections_processor.pubkeys(): - self.app.sources_service.parse_transaction(recipient, transaction) - self.app.db.commit() + for conn in self._connections_processor.connections(): + if conn.pubkey == recipient: + self.app.sources_service.parse_transaction(recipient, transaction) + new_tx = self.app.transactions_service.parse_sent_transaction(recipient, transaction) + self.app.new_transfer.emit(conn, new_tx) self.app.sources_refreshed.emit() + self.app.db.commit() return result, transactions def notifications(self): diff --git a/src/sakia/gui/navigation/txhistory/table_model.py b/src/sakia/gui/navigation/txhistory/table_model.py index 4bc5910927c914fa626d5181d295ee7ee9e758b8..a50b238162ee31123cac826b7bf317830f67eab1 100644 --- a/src/sakia/gui/navigation/txhistory/table_model.py +++ b/src/sakia/gui/navigation/txhistory/table_model.py @@ -218,7 +218,7 @@ class HistoryTableModel(QAbstractTableModel): def add_transfer(self, connection, transfer): if self.connection == connection: self.beginInsertRows(QModelIndex(), len(self.transfers_data), len(self.transfers_data)) - if transfer.issuer == self.connection.pubkey: + if self.connection.pubkey in transfer.issuers: self.transfers_data.append(self.data_sent(transfer)) if self.connection.pubkey in transfer.receivers: self.transfers_data.append(self.data_received(transfer)) @@ -238,7 +238,7 @@ class HistoryTableModel(QAbstractTableModel): self.transfers_data.pop(i) self.endRemoveRows() else: - if transfer.issuer == self.connection.pubkey: + if self.connection.pubkey in transfer.issuers: self.transfers_data[i] = self.data_sent(transfer) self.dataChanged.emit(self.index(i, 0), self.index(i, len(HistoryTableModel.columns_types))) if self.connection.pubkey in transfer.receivers: diff --git a/src/sakia/services/documents.py b/src/sakia/services/documents.py index c56d1ce3222ae8070e75828b6a06488bb8e0e089..4585952b01fba5f88cceb4fab6497d10f6d2fc73 100644 --- a/src/sakia/services/documents.py +++ b/src/sakia/services/documents.py @@ -435,8 +435,6 @@ class DocumentsService: for i, tx in enumerate(tx_entities): logging.debug("Transaction : [{0}]".format(tx.raw)) - txid = self._transactions_processor.next_txid(connection.currency, blockstamp.number) - tx_res, tx_entities[i] = await self._transactions_processor.send(tx, connection.currency) # Result can be negative if a tx is not accepted by the network diff --git a/src/sakia/services/transactions.py b/src/sakia/services/transactions.py index 15f6bbd30f37bfbfbeea42a7687b910e27c171c9..eeeb50609c72f61bed8dbd33a7941e8e779c90a4 100644 --- a/src/sakia/services/transactions.py +++ b/src/sakia/services/transactions.py @@ -1,5 +1,5 @@ from PyQt5.QtCore import QObject -from sakia.data.entities.transaction import parse_transaction_doc +from sakia.data.entities.transaction import parse_transaction_doc, Transaction from duniterpy.documents import Transaction as TransactionDoc from duniterpy.documents import SimpleTransaction, Block from sakia.data.entities import Dividend @@ -34,6 +34,23 @@ class TransactionsService(QObject): self.currency = currency self._logger = logging.getLogger('sakia') + def parse_sent_transaction(self, pubkey, transaction): + """ + Parse a block + :param sakia.data.entities.Transaction transaction: The transaction to parse + :return: The list of transfers sent + """ + if not self._transactions_processor.find_by_hash(pubkey, transaction.sha_hash): + txid = self._transactions_processor.next_txid(transaction.currency, -1) + tx = parse_transaction_doc(transaction.txdoc(), pubkey, + transaction.blockstamp.number, transaction.timestamp, txid+1) + tx.state = Transaction.AWAITING + if tx: + self._transactions_processor.commit(tx) + return tx + else: + logging.debug("Error during transfer parsing") + def _parse_block(self, block_doc, txid): """ Parse a block