From d8d2f3329bf74282d96cb079eef23eb3e6b04e83 Mon Sep 17 00:00:00 2001 From: Vivek Teega Date: Mon, 10 Sep 2018 11:12:05 +0530 Subject: [PATCH] Save txcomments/floData locally --- electrum/address_synchronizer.py | 21 +++++++++++++++++++-- electrum/gui/qt/main_window.py | 2 +- electrum/transaction.py | 2 -- electrum/util.py | 3 ++- electrum/verifier.py | 3 ++- electrum/wallet.py | 6 +----- 6 files changed, 25 insertions(+), 12 deletions(-) diff --git a/electrum/address_synchronizer.py b/electrum/address_synchronizer.py index 2d6a70cc..13d688b6 100644 --- a/electrum/address_synchronizer.py +++ b/electrum/address_synchronizer.py @@ -66,8 +66,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, tx_comment) in verified_tx.items(): + self.verified_tx[txid] = VerifiedTxInfo(height, timestamp, txpos, header_hash, tx_comment) # Transactions pending verification. txid -> tx_height. Access with self.lock. self.unverified_tx = defaultdict(int) # true when synchronized @@ -596,6 +596,23 @@ class AddressSynchronizer(PrintError): # local transaction return TxMinedStatus(TX_HEIGHT_LOCAL, 0, None, None) + def get_tx_comment(self, tx_hash: str): + """ Given a transaction, returns txcomment/floData """ + with self.lock: + if tx_hash in self.verified_tx: + info = self.verified_tx[tx_hash] + tx_comment = info[4] + return tx_comment + elif tx_hash in self.unverified_tx: + tx = self.transactions.get(tx_hash) + tx_comment = tx.txcomment[5:] + return tx_comment + else: + # local transaction + tx = self.transactions.get(tx_hash) + tx_comment = tx.txcomment[5:] + return tx_comment + 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/main_window.py b/electrum/gui/qt/main_window.py index 0386c94e..4c3581b1 100644 --- a/electrum/gui/qt/main_window.py +++ b/electrum/gui/qt/main_window.py @@ -1103,7 +1103,7 @@ class ElectrumWindow(QMainWindow, MessageBoxMixin, PrintError): hbox.addStretch(1) grid.addLayout(hbox, 4, 4) - msg = _('Bitcoin transactions are in general not free. A transaction fee is paid by the sender of the funds.') + '\n\n'\ + msg = _('FLO transactions are in general not free. A transaction fee is paid by the sender of the funds.') + '\n\n'\ + _('The amount of fee can be decided freely by the sender. However, transactions with low fees take more time to be processed.') + '\n\n'\ + _('A suggested fee is automatically added to this field. You may override it. The suggested fee increases with the size of the transaction.') self.fee_e_label = HelpLabel(_('Fee'), msg) diff --git a/electrum/transaction.py b/electrum/transaction.py index 9e637e83..2fe2218f 100644 --- a/electrum/transaction.py +++ b/electrum/transaction.py @@ -1063,8 +1063,6 @@ class Transaction: return nVersion + marker + flag + txins + txouts + witness + nLocktime else: if self.version >= 2: - print("Before serialize to network ") - print(nVersion + txins + txouts + nLocktime + nTxComment) return nVersion + txins + txouts + nLocktime + nTxComment else: return nVersion + txins + txouts + nLocktime diff --git a/electrum/util.py b/electrum/util.py index b37ef62e..1a3f69f5 100644 --- a/electrum/util.py +++ b/electrum/util.py @@ -905,4 +905,5 @@ TxMinedStatus = NamedTuple("TxMinedStatus", [("height", int), VerifiedTxInfo = NamedTuple("VerifiedTxInfo", [("height", int), ("timestamp", int), ("txpos", int), - ("header_hash", str)]) + ("header_hash", str), + ("tx_comment", str)]) diff --git a/electrum/verifier.py b/electrum/verifier.py index 4a0d82ec..8278d1b4 100644 --- a/electrum/verifier.py +++ b/electrum/verifier.py @@ -110,7 +110,8 @@ class SPV(ThreadJob): 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) + tx_comment = self.wallet.get_tx_comment(tx_hash) + vtx_info = VerifiedTxInfo(tx_height, header.get('timestamp'), pos, header_hash, tx_comment) 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 18f10c1c..b30588e8 100644 --- a/electrum/wallet.py +++ b/electrum/wallet.py @@ -401,7 +401,7 @@ class Abstract_Wallet(AddressSynchronizer): 'value': Satoshis(value), 'balance': Satoshis(balance), 'date': timestamp_to_datetime(timestamp), - 'label': self.get_label(tx_hash), + 'label': self.get_label(tx_hash) } if show_addresses: tx = self.transactions.get(tx_hash) @@ -486,10 +486,6 @@ class Abstract_Wallet(AddressSynchronizer): return ', '.join(labels) return '' - def get_tx_comment(self, tx_hash): - tx = self.transactions.get(tx_hash) - comment = tx.txcomment[5:] - return comment def get_tx_status(self, tx_hash, tx_mined_status): extra = []