Browse Source

jm_qt.py: rm FilteredPlainTextEdit

add-joinmarket
zebra-lucky 1 year ago
parent
commit
684c59495f
  1. 47
      electrum/plugins/joinmarket/jm_qt.py
  2. 33
      electrum/plugins/joinmarket/jm_util.py

47
electrum/plugins/joinmarket/jm_qt.py

@ -27,7 +27,7 @@ from electrum.gui.qt.util import (read_QIcon, HelpLabel, MessageBoxMixin,
MONOSPACE_FONT, WindowModalDialog, MONOSPACE_FONT, WindowModalDialog,
Buttons, OkButton) Buttons, OkButton)
from .jm_util import guess_address_script_type, filter_log_line, JMStates from .jm_util import guess_address_script_type, JMStates
from .jmclient import (JMClientProtocolFactory, Taker, get_max_cj_fee_values, from .jmclient import (JMClientProtocolFactory, Taker, get_max_cj_fee_values,
fidelity_bond_weighted_order_choose, get_schedule, fidelity_bond_weighted_order_choose, get_schedule,
ScheduleGenerationErrorNoFunds, schedule_to_text, ScheduleGenerationErrorNoFunds, schedule_to_text,
@ -65,49 +65,6 @@ class GUIConfig:
GUIconf = GUIConfig() GUIconf = GUIConfig()
class FilteredPlainTextEdit(QPlainTextEdit):
def contextMenuEvent(self, event):
f_copy = QAction(_('Copy filtered'), self)
f_copy.triggered.connect(lambda checked: self.copy_filtered())
f_copy.setEnabled(self.textCursor().hasSelection())
copy_icon = QIcon.fromTheme('edit-copy')
if copy_icon:
f_copy.setIcon(copy_icon)
menu = self.createStandardContextMenu(event.pos())
menu.insertAction(menu.actions()[0], f_copy)
menu.exec(event.globalPos())
def copy_filtered(self):
cursor = self.textCursor()
if not cursor.hasSelection():
return
all_lines = self.toPlainText().splitlines()
sel_beg = cursor.selectionStart()
sel_end = cursor.selectionEnd()
l_beg = 0
result_lines = []
for i in range(len(all_lines)):
cur_line = all_lines[i]
cur_len = len(cur_line)
l_end = l_beg + cur_len
if l_end > sel_beg and l_beg < sel_end:
filtered_line = filter_log_line(cur_line)
l_sel_start = None if sel_beg <= l_beg else sel_beg - l_beg
l_sel_end = None if sel_end >= l_end else sel_end - l_beg
clipped_line = filtered_line[l_sel_start:l_sel_end]
result_lines.append(clipped_line)
l_beg += (cur_len + 1)
if l_beg > sel_end:
break
QApplication.clipboard().setText('\n'.join(result_lines))
class WarnExDialog(WindowModalDialog): class WarnExDialog(WindowModalDialog):
def __init__(self, jmman, parent): def __init__(self, jmman, parent):
@ -340,7 +297,7 @@ class JMDlg(QtEventListener, QDialog, MessageBoxMixin):
# setup logging # setup logging
self.log_handler = self.jmman.log_handler self.log_handler = self.jmman.log_handler
self.logger = self.jmman.logger self.logger = self.jmman.logger
self.log_view = FilteredPlainTextEdit() self.log_view = QPlainTextEdit()
self.log_view.setMaximumBlockCount(1000) self.log_view.setMaximumBlockCount(1000)
self.log_view.setVerticalScrollBarPolicy( self.log_view.setVerticalScrollBarPolicy(
Qt.ScrollBarPolicy.ScrollBarAlwaysOn) Qt.ScrollBarPolicy.ScrollBarAlwaysOn)

33
electrum/plugins/joinmarket/jm_util.py

@ -17,13 +17,6 @@ from electrum.transaction import (PartialTransaction, Transaction,
from electrum.util import to_bytes from electrum.util import to_bytes
TXID_PATTERN = re.compile('([0123456789ABCDEFabcdef]{64})')
ADDR_PATTERN = re.compile(
'([123456789ABCDEFGHJKLMNPQRSTUVWXYZ'
'abcdefghijkmnopqrstuvwxyz]{20,80})')
FILTERED_TXID = '<filtered txid>'
FILTERED_ADDR = '<filtered address>'
# secp256k1 prime # secp256k1 prime
prime = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F prime = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F
@ -48,32 +41,6 @@ def verify_signature(pubkey: bytes, sig: bytes, h: bytes) -> bool:
return ecc.ECPubkey(pubkey).ecdsa_verify(sig, h) return ecc.ECPubkey(pubkey).ecdsa_verify(sig, h)
def filter_log_line(line):
'''Filter out txids/addresses from log lines'''
pos = 0
output_line = ''
while pos < len(line):
m = TXID_PATTERN.search(line, pos)
if m:
output_line += line[pos:m.start()]
output_line += FILTERED_TXID
pos = m.end()
continue
m = ADDR_PATTERN.search(line, pos)
if m:
addr = m.group()
if is_address(addr, net=constants.net):
output_line += line[pos:m.start()]
output_line += FILTERED_ADDR
pos = m.end()
continue
output_line += line[pos:]
break
return output_line
def guess_address_script_type(addr): def guess_address_script_type(addr):
net = constants.net net = constants.net
if not is_address(addr, net=net): if not is_address(addr, net=net):

Loading…
Cancel
Save