From 91273f7114517d722bdecdd4cffec04b18bc9b32 Mon Sep 17 00:00:00 2001 From: Vivek Teega Date: Sat, 29 Sep 2018 23:09:21 +0530 Subject: [PATCH] Adding FLO data support 1. All the GUI changes for the QT version of the wallet 2. Saving flodata locally in the wallet --- electrum/address_synchronizer.py | 21 +++++++++++++++++++-- electrum/gui/qt/history_list.py | 5 +++-- electrum/gui/qt/main_window.py | 13 ++++++++++--- electrum/gui/qt/transaction_dialog.py | 3 +++ electrum/util.py | 3 ++- electrum/verifier.py | 3 ++- electrum/wallet.py | 14 +++++++++++++- 7 files changed, 52 insertions(+), 10 deletions(-) diff --git a/electrum/address_synchronizer.py b/electrum/address_synchronizer.py index 7e425bff..ae088319 100644 --- a/electrum/address_synchronizer.py +++ b/electrum/address_synchronizer.py @@ -69,8 +69,8 @@ class AddressSynchronizer(PrintError): # Verified transactions. txid -> VerifiedTxInfo. Access with self.lock. verified_tx = storage.get('verified_tx3', {}) self.verified_tx = {} - for txid, (height, timestamp, txpos, header_hash) in verified_tx.items(): - self.verified_tx[txid] = VerifiedTxInfo(height, timestamp, txpos, header_hash) + for txid, (height, timestamp, txpos, header_hash, flodata) in verified_tx.items(): + self.verified_tx[txid] = VerifiedTxInfo(height, timestamp, txpos, header_hash, flodata) # Transactions pending verification. txid -> tx_height. Access with self.lock. self.unverified_tx = defaultdict(int) # true when synchronized @@ -640,6 +640,23 @@ class AddressSynchronizer(PrintError): # local transaction return TxMinedStatus(TX_HEIGHT_LOCAL, 0, None, None) + def get_flodata(self, tx_hash: str): + """ Given a transaction, returns flodata """ + with self.lock: + if tx_hash in self.verified_tx: + info = self.verified_tx[tx_hash] + flodata = info[4] + return flodata + elif tx_hash in self.unverified_tx: + tx = self.transactions.get(tx_hash) + flodata = tx.flodata[5:] + return flodata + else: + # local transaction + tx = self.transactions.get(tx_hash) + flodata = tx.flodata[5:] + return flodata + def set_up_to_date(self, up_to_date): with self.lock: self.up_to_date = up_to_date diff --git a/electrum/gui/qt/history_list.py b/electrum/gui/qt/history_list.py index d12903c7..6a88985a 100644 --- a/electrum/gui/qt/history_list.py +++ b/electrum/gui/qt/history_list.py @@ -74,7 +74,7 @@ class HistoryList(MyTreeWidget, AcceptFileDragDrop): return str(datetime.date(d.year, d.month, d.day)) if d else _('None') def refresh_headers(self): - headers = ['', '', _('Date'), _('Description'), _('Amount'), _('Balance')] + headers = ['', '', _('Date'), _('Description'), _('Amount'), _('Balance'), _('FLO Data')] fx = self.parent.fx if fx and fx.show_history(): headers.extend(['%s '%fx.ccy + _('Value')]) @@ -247,7 +247,8 @@ class HistoryList(MyTreeWidget, AcceptFileDragDrop): icon = self.icon_cache.get(":icons/" + TX_ICONS[status]) v_str = self.parent.format_amount(value, is_diff=True, whitespaces=True) balance_str = self.parent.format_amount(balance, whitespaces=True) - entry = ['', tx_hash, status_str, label, v_str, balance_str] + flodata = self.wallet.get_flodata(tx_hash) + entry = ['', tx_hash, status_str, label, v_str, balance_str, flodata] fiat_value = None if value is not None and fx and fx.show_history(): fiat_value = tx_item['fiat_value'].value diff --git a/electrum/gui/qt/main_window.py b/electrum/gui/qt/main_window.py index f89b9e7f..a80bd926 100644 --- a/electrum/gui/qt/main_window.py +++ b/electrum/gui/qt/main_window.py @@ -1094,6 +1094,12 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): self.message_e = MyLineEdit() grid.addWidget(self.message_e, 2, 1, 1, -1) + msg = _('This is where you write the FLO Data for the transaction') + flodata_label = HelpLabel(_('FLO Data'), msg) + grid.addWidget(flodata_label, 7, 0) + self.message_tx = MyLineEdit() + grid.addWidget(self.message_tx, 7, 1, 1, -1) + self.from_label = QLabel(_('From')) grid.addWidget(self.from_label, 3, 0) self.from_list = MyTreeWidget(self, self.from_list_menu, ['','']) @@ -1490,6 +1496,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): self.show_error(_('Payment request has expired')) return label = self.message_e.text() + flodata = self.message_tx.text() if self.payment_request: outputs = self.payment_request.get_outputs() @@ -1525,7 +1532,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): fee_estimator = self.get_send_fee_estimator() coins = self.get_coins() - return outputs, fee_estimator, label, coins + return outputs, fee_estimator, label, coins, flodata def do_preview(self): self.do_send(preview = True) @@ -1536,12 +1543,12 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): r = self.read_send_tab() if not r: return - outputs, fee_estimator, tx_desc, coins = r + outputs, fee_estimator, tx_desc, coins, flodata = r try: is_sweep = bool(self.tx_external_keypairs) tx = self.wallet.make_unsigned_transaction( coins, outputs, self.config, fixed_fee=fee_estimator, - is_sweep=is_sweep) + is_sweep=is_sweep, flodata=flodata) except NotEnoughFunds: self.show_message(_("Insufficient funds")) return diff --git a/electrum/gui/qt/transaction_dialog.py b/electrum/gui/qt/transaction_dialog.py index d2affb6c..2299773d 100644 --- a/electrum/gui/qt/transaction_dialog.py +++ b/electrum/gui/qt/transaction_dialog.py @@ -113,6 +113,8 @@ class TxDialog(QDialog, MessageBoxMixin): vbox.addWidget(self.size_label) self.fee_label = QLabel() vbox.addWidget(self.fee_label) + self.flodata_label = QLabel() + vbox.addWidget(self.flodata_label) self.add_io(vbox) @@ -266,6 +268,7 @@ class TxDialog(QDialog, MessageBoxMixin): self.amount_label.setText(amount_str) self.fee_label.setText(fee_str) self.size_label.setText(size_str) + self.flodata_label.setText("FLO data: " + self.tx.flodata) run_hook('transaction_dialog_update', self) def add_io(self, vbox): diff --git a/electrum/util.py b/electrum/util.py index 20af6e17..5178a3b2 100644 --- a/electrum/util.py +++ b/electrum/util.py @@ -867,7 +867,8 @@ TxMinedStatus = NamedTuple("TxMinedStatus", [("height", int), VerifiedTxInfo = NamedTuple("VerifiedTxInfo", [("height", int), ("timestamp", int), ("txpos", int), - ("header_hash", str)]) + ("header_hash", str), + ("flodata", str)]) def make_aiohttp_session(proxy): if proxy: diff --git a/electrum/verifier.py b/electrum/verifier.py index cb6bdfa6..b9b13b1b 100644 --- a/electrum/verifier.py +++ b/electrum/verifier.py @@ -113,7 +113,8 @@ class SPV(PrintError): except KeyError: pass self.print_error("verified %s" % tx_hash) header_hash = hash_header(header) - vtx_info = VerifiedTxInfo(tx_height, header.get('timestamp'), pos, header_hash) + flodata = self.wallet.get_flodata(tx_hash) + vtx_info = VerifiedTxInfo(tx_height, header.get('timestamp'), pos, header_hash, flodata) self.wallet.add_verified_tx(tx_hash, vtx_info) if self.is_up_to_date() and self.wallet.is_up_to_date(): self.wallet.save_verified_tx(write=True) diff --git a/electrum/wallet.py b/electrum/wallet.py index 011fd6ac..92884b8c 100644 --- a/electrum/wallet.py +++ b/electrum/wallet.py @@ -492,6 +492,11 @@ class Abstract_Wallet(AddressSynchronizer): return ', '.join(labels) return '' + def get_flodata(self, tx_hash): + tx = self.transactions.get(tx_hash) + flodata = tx.flodata[5:] + return flodata + def get_tx_status(self, tx_hash, tx_mined_status): extra = [] height = tx_mined_status.height @@ -539,7 +544,7 @@ class Abstract_Wallet(AddressSynchronizer): return dust_threshold(self.network) def make_unsigned_transaction(self, inputs, outputs, config, fixed_fee=None, - change_addr=None, is_sweep=False): + change_addr=None, is_sweep=False, flodata=None): # check outputs i_max = None for i, o in enumerate(outputs): @@ -561,6 +566,9 @@ class Abstract_Wallet(AddressSynchronizer): for item in inputs: self.add_input_info(item) + if flodata is None: + flodata='' + # change address # if we leave it empty, coin_chooser will set it change_addrs = [] @@ -609,6 +617,10 @@ class Abstract_Wallet(AddressSynchronizer): # Timelock tx to current height. tx.locktime = self.get_local_height() + # Transactions with transaction comments/floData are version 2 + if flodata != "": + tx.version = 2 + tx.flodata = "text:" + flodata run_hook('make_unsigned_transaction', self, tx) return tx