Skip to content
Snippets Groups Projects
Commit 43b9bba5 authored by inso's avatar inso
Browse files

Fix bug #671 : sent tx not added to local keys

parent 981c44ee
No related branches found
No related tags found
No related merge requests found
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)
......@@ -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():
for conn in self._connections_processor.connections():
if conn.pubkey == recipient:
self.app.sources_service.parse_transaction(recipient, transaction)
self.app.db.commit()
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):
......
......@@ -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:
......
......@@ -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
......
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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment