diff --git a/src/cutecoin/core/account.py b/src/cutecoin/core/account.py index fe2e4c0dee65eccb4fab4b3d06dd3ac96a581155..d7111fa8819576f0325fa7899b61700c1f8525ad 100644 --- a/src/cutecoin/core/account.py +++ b/src/cutecoin/core/account.py @@ -353,6 +353,16 @@ class Account(QObject): sent.extend(w.transfers(community)) return sent + def dividends(self, community): + """ + Get all dividends received in this community + by the first wallet of this account + + :param community: The target community + :return: All account dividends + """ + return self.wallets[0].dividends(community) + @asyncio.coroutine def future_amount(self, community): """ diff --git a/src/cutecoin/core/net/api/bma/__init__.py b/src/cutecoin/core/net/api/bma/__init__.py index 29eea7b0e6e00592b83d403039cafd895a325271..9fb8038dc20f43ff51804c22cda9d9b20d8668ab 100644 --- a/src/cutecoin/core/net/api/bma/__init__.py +++ b/src/cutecoin/core/net/api/bma/__init__.py @@ -126,4 +126,4 @@ class API(object): logging.debug(url.toString(QUrl.FullyEncoded)) return reply -from . import network, blockchain, tx, wot +from . import network, blockchain, tx, wot, ud \ No newline at end of file diff --git a/src/cutecoin/core/txhistory.py b/src/cutecoin/core/txhistory.py index f32b0e035511a735fdeb0a62276587eb07acdc47..2f9c6d145ba206681d1956ba02e22f7d6fa92d2e 100644 --- a/src/cutecoin/core/txhistory.py +++ b/src/cutecoin/core/txhistory.py @@ -13,6 +13,7 @@ class TxHistory(): self._transfers = [] self.available_sources = [] + self._dividends = [] @property def latest_block(self): @@ -35,6 +36,9 @@ class TxHistory(): for s in data['sources']: self.available_sources.append(InputSource.from_inline(s['inline'])) + for d in data['dividends']: + self._dividends.append(d) + self.latest_block = data['latest_block'] def jsonify(self): @@ -47,14 +51,23 @@ class TxHistory(): s.index = 0 data_sources.append({'inline': "{0}\n".format(s.inline())}) + data_dividends = [] + for d in self._dividends: + data_dividends.append(d) + return {'latest_block': self.latest_block, 'transfers': data_transfer, - 'sources': data_sources} + 'sources': data_sources, + 'dividends': data_dividends} @property def transfers(self): return [t for t in self._transfers if t.state != Transfer.DROPPED] + @property + def dividends(self): + return self._dividends.copy() + def stop_coroutines(self): self._stop_coroutines = True @@ -138,7 +151,15 @@ class TxHistory(): parsed_block = self.latest_block current_block = community.network.latest_block logging.debug("Refresh from : {0} to {1}".format(self.latest_block, current_block)) + dividends_data = yield from community.bma_access.future_request(qtbma.ud.History, + req_args={'pubkey': self.wallet.pubkey}) + dividends = dividends_data['history']['history'] + for d in dividends: + if d['block_number'] not in range(parsed_block, parsed_block+99): + dividends.remove(d) + new_transfers = [] + new_dividends = [] # Lets look if transactions took too long to be validated awaiting = [t for t in self._transfers if t.state == Transfer.AWAITING] @@ -152,6 +173,12 @@ class TxHistory(): if self._stop_coroutines: return + udid = 0 + for d in dividends: + if d['block_number'] in range(parsed_block, parsed_block+99): + new_dividends.append(d) + udid += 1 + # We parse only blocks with transactions transactions = tx_history['history']['received'] + tx_history['history']['sent'] for (txid, txdata) in enumerate(transactions): @@ -162,7 +189,7 @@ class TxHistory(): parsed_block, current_block)) else: - transfer = yield from self._parse_transaction(community, txdata, received_list, txid) + transfer = yield from self._parse_transaction(community, txdata, received_list, udid + txid) if transfer: new_transfers.append(transfer) @@ -179,5 +206,6 @@ class TxHistory(): transfer.check_refused(current_block) self._transfers = self._transfers + new_transfers + self._dividends = self._dividends + new_dividends self.wallet.refresh_finished.emit(received_list) diff --git a/src/cutecoin/core/wallet.py b/src/cutecoin/core/wallet.py index 3d996beef8d0d8378ccd1699cca50180fbac6e15..a0628c52f15ceb1d8e4afc7e5b6555cd6a2bc34b 100644 --- a/src/cutecoin/core/wallet.py +++ b/src/cutecoin/core/wallet.py @@ -331,6 +331,18 @@ class Wallet(QObject): else: return [] + def dividends(self, community): + """ + Get all the dividends received by this wallet + + :param community: The community we want to get received dividends + :return: Result of udhistory request + """ + if community.currency in self.caches: + return self.caches[community.currency].dividends + else: + return [] + def stop_coroutines(self): for c in self.caches.values(): c.stop_coroutines() diff --git a/src/cutecoin/models/txhistory.py b/src/cutecoin/models/txhistory.py index e82f44c976a0435e70f03ddaceae875cbe52f507..2d0cd38b01c7ab664feeb94e030bcb178b17d33d 100644 --- a/src/cutecoin/models/txhistory.py +++ b/src/cutecoin/models/txhistory.py @@ -189,7 +189,7 @@ class HistoryTableModel(QAbstractTableModel): @property def transfers(self): - return self.account.transfers(self.community) + return self.account.transfers(self.community) + self.account.dividends(self.community) def data_received(self, transfer): amount = transfer.metadata['amount'] @@ -225,6 +225,16 @@ class HistoryTableModel(QAbstractTableModel): "", comment, transfer.state, txid, transfer.metadata['receiver']) + def data_dividend(self, dividend): + amount = dividend['amount'] + comment = "" + receiver = self.account.name + date_ts = dividend['time'] + udid = dividend['udid'] + return (date_ts, receiver, amount, + "", "", Transfer.VALIDATED, udid, + self.account.pubkey) + def refresh_transfers(self): self.beginResetModel() self.transfers_data = []