Skip to content

Commit

Permalink
Merge pull request #2211 from gasull/backport-btc-to-bch-minor-style-…
Browse files Browse the repository at this point in the history
…changes

Style changes (from backport), small refactorings
  • Loading branch information
cculianu committed Mar 25, 2021
2 parents f9ed4d4 + bc20c41 commit a93e579
Show file tree
Hide file tree
Showing 17 changed files with 57 additions and 60 deletions.
5 changes: 1 addition & 4 deletions contrib/sign_packages
Expand Up @@ -10,9 +10,6 @@ if __name__ == '__main__':
for f in os.listdir('.'):
if f.endswith('asc'):
continue
os.system( "gpg --sign --armor --detach --passphrase \"%s\" %s"%(password, f) )
os.system("gpg --sign --armor --detach --passphrase \"%s\" %s"%(password, f))

os.chdir("..")



2 changes: 1 addition & 1 deletion electroncash/coinchooser.py
Expand Up @@ -221,7 +221,7 @@ def bucket_candidates(self, buckets, sufficient_funds):
# Add all singletons
for n, bucket in enumerate(buckets):
if sufficient_funds([bucket]):
candidates.add((n, ))
candidates.add((n,))

# And now some random ones
attempts = min(100, (len(buckets) - 1) * 10 + 1)
Expand Down
2 changes: 1 addition & 1 deletion electroncash/mnemonic.py
Expand Up @@ -52,7 +52,7 @@
(0x2B740, 0x2B81F, 'CJK Unified Ideographs Extension D'),
(0xF900, 0xFAFF, 'CJK Compatibility Ideographs'),
(0x2F800, 0x2FA1D, 'CJK Compatibility Ideographs Supplement'),
(0x3190, 0x319F , 'Kanbun'),
(0x3190, 0x319F, 'Kanbun'),
(0x2E80, 0x2EFF, 'CJK Radicals Supplement'),
(0x2F00, 0x2FDF, 'CJK Radicals'),
(0x31C0, 0x31EF, 'CJK Strokes'),
Expand Down
6 changes: 3 additions & 3 deletions electroncash/old_mnemonic.py
Expand Up @@ -1661,7 +1661,7 @@
# Note about US patent no 5892470: Here each word does not represent a given digit.
# Instead, the digit represented by a word is variable, it depends on the previous word.

def mn_encode( message ):
def mn_encode(message):
assert len(message) % 8 == 0
out = []
for i in range(len(message)//8):
Expand All @@ -1670,11 +1670,11 @@ def mn_encode( message ):
w1 = (x%n)
w2 = ((x//n) + w1)%n
w3 = ((x//n//n) + w2)%n
out += [ words[w1], words[w2], words[w3] ]
out += [words[w1], words[w2], words[w3]]
return out


def mn_decode( wlist ):
def mn_decode(wlist):
out = ''
for i in range(len(wlist)//3):
word1, word2, word3 = wlist[3*i:3*i+3]
Expand Down
2 changes: 1 addition & 1 deletion electroncash/plot.py
Expand Up @@ -33,7 +33,7 @@ def plot_history(wallet, history):

f, axarr = plt.subplots(2, sharex=True)
plt.subplots_adjust(bottom=0.2)
plt.xticks( rotation=25 )
plt.xticks(rotation=25)
ax = plt.gca()
plt.ylabel('BCH')
plt.xlabel('Month')
Expand Down
2 changes: 1 addition & 1 deletion electroncash/tests/test_bitcoin.py
Expand Up @@ -154,7 +154,7 @@ def test_hash(self):

def test_var_int(self):
for i in range(0xfd):
self.assertEqual(var_int(i), "{:02x}".format(i) )
self.assertEqual(var_int(i), "{:02x}".format(i))

self.assertEqual(var_int(0xfd), "fdfd00")
self.assertEqual(var_int(0xfe), "fdfe00")
Expand Down
12 changes: 6 additions & 6 deletions electroncash_gui/qt/main_window.py
Expand Up @@ -968,7 +968,6 @@ def update_status(self):
_("Balance: {amount_and_unit}").format(
amount_and_unit=self.format_amount_and_units(c))
]

if u:
text_items.append(_("[{amount} unconfirmed]").format(
amount=self.format_amount(u, True).strip()))
Expand Down Expand Up @@ -1006,11 +1005,10 @@ def update_status(self):

self.tray.setToolTip("%s (%s)" % (text, self.wallet.basename()))
self.balance_label.setText(text)
self.status_button.setIcon( icon )
self.status_button.setIcon(icon)
self.status_button.setStatusTip( status_tip )
run_hook('window_update_status', self)


def update_wallet(self):
self.need_update.set() # will enqueue an _update_wallet() call in at most 0.5 seconds from now.

Expand Down Expand Up @@ -2876,7 +2874,7 @@ def create_status_bar(self):
self.update_available_button.setVisible(bool(self.gui_object.new_version_available)) # if hidden now gets unhidden by on_update_available when a new version comes in

self.lock_icon = QIcon()
self.password_button = StatusBarButton(self.lock_icon, _("Password"), self.change_password_dialog )
self.password_button = StatusBarButton(self.lock_icon, _("Password"), self.change_password_dialog)
sb.addPermanentWidget(self.password_button)

self.addr_converter_button = StatusBarButton(
Expand All @@ -2889,8 +2887,10 @@ def create_status_bar(self):
self.addr_converter_button.setHidden(self.gui_object.is_cashaddr_status_button_hidden())
self.gui_object.cashaddr_status_button_hidden_signal.connect(self.addr_converter_button.setHidden)

sb.addPermanentWidget(StatusBarButton(QIcon(":icons/preferences.svg"), _("Preferences"), self.settings_dialog ) )
self.seed_button = StatusBarButton(QIcon(":icons/seed.png"), _("Seed"), self.show_seed_dialog )
q_icon_prefs = QIcon(":icons/preferences.svg"), _("Preferences"), self.settings_dialog)
sb.addPermanentWidget(StatusBarButton(q_icon_prefs))
q_icon_seed = QIcon(":icons/seed.png"), _("Seed"), self.show_seed_dialog)
self.seed_button = StatusBarButton(q_icon_seed)
sb.addPermanentWidget(self.seed_button)
weakSelf = Weak.ref(self)
gui_object = self.gui_object
Expand Down
12 changes: 6 additions & 6 deletions electroncash_gui/qt/network_dialog.py
Expand Up @@ -159,7 +159,7 @@ def create_menu(self, position):
menu.exec_(self.viewport().mapToGlobal(position))

def keyPressEvent(self, event):
if event.key() in [ Qt.Key_F2, Qt.Key_Return ]:
if event.key() in {Qt.Key_F2, Qt.Key_Return}:
item, col = self.currentItem(), self.currentColumn()
if item and col > -1:
self.on_activated(item, col)
Expand Down Expand Up @@ -927,11 +927,11 @@ def set_server(self, onion_hack=False):
def set_proxy(self):
host, port, protocol, proxy, auto_connect = self.network.get_parameters()
if self.proxy_cb.isChecked():
proxy = { 'mode':str(self.proxy_mode.currentText()).lower(),
'host':str(self.proxy_host.text()),
'port':str(self.proxy_port.text()),
'user':str(self.proxy_user.text()),
'password':str(self.proxy_password.text())}
proxy = {'mode':str(self.proxy_mode.currentText()).lower(),
'host':str(self.proxy_host.text()),
'port':str(self.proxy_port.text()),
'user':str(self.proxy_user.text()),
'password':str(self.proxy_password.text())}
else:
proxy = None
self.network.set_parameters(host, port, protocol, proxy, auto_connect)
Expand Down
2 changes: 1 addition & 1 deletion electroncash_gui/qt/password_dialog.py
Expand Up @@ -48,7 +48,7 @@ def check_password_strength(password):
num = re.search("[0-9]", password) is not None and re.match("^[0-9]*$", password) is None
caps = password != password.upper() and password != password.lower()
extra = re.match("^[a-zA-Z0-9]*$", password) is None
score = len(password)*( n + caps + num + extra)/20
score = len(password)*(n + caps + num + extra)/20
password_strength = {0:"Weak",1:"Medium",2:"Strong",3:"Very Strong"}
return password_strength[min(3, int(score))]

Expand Down
2 changes: 1 addition & 1 deletion electroncash_gui/qt/qrcodewidget.py
Expand Up @@ -80,7 +80,7 @@ def paintEvent(self, e):

margin = 5
framesize = min(r.width(), r.height())
boxsize = int( (framesize - 2*margin)/k )
boxsize = int((framesize - 2*margin)/k)
size = k*boxsize
left = (r.width() - size)/2
top = (r.height() - size)/2
Expand Down
4 changes: 2 additions & 2 deletions electroncash_gui/qt/util.py
Expand Up @@ -531,7 +531,7 @@ def filename_field(config, defaultname, select_msg):
hbox = QHBoxLayout()

directory = config.get('io_dir', os.path.expanduser('~'))
path = os.path.join( directory, defaultname )
path = os.path.join(directory, defaultname)
filename_e = QLineEdit()
filename_e.setText(path)

Expand Down Expand Up @@ -660,7 +660,7 @@ def editItem(self, item, column):
item.setFlags(item.flags() & ~Qt.ItemIsEditable)

def keyPressEvent(self, event):
if event.key() in [ Qt.Key_F2, Qt.Key_Return ] and self.editor is None:
if event.key() in {Qt.Key_F2, Qt.Key_Return} and self.editor is None:
item, col = self.currentItem(), self.currentColumn()
if item and col > -1:
self.on_activated(item, col)
Expand Down
12 changes: 6 additions & 6 deletions electroncash_gui/stdio.py
Expand Up @@ -46,7 +46,7 @@ def __init__(self, config, daemon, plugins):
_("[r] - show own receipt addresses"), \
_("[c] - display contacts"), \
_("[b] - print server banner"), \
_("[q] - quit") ]
_("[q] - quit")]
self.num_commands = len(self.commands)

def on_network(self, event, *args):
Expand Down Expand Up @@ -101,7 +101,7 @@ def print_history(self):
label = self.wallet.get_label(tx_hash)
messages.append( format_str%( time_str, label, format_satoshis(delta, whitespaces=True), format_satoshis(balance, whitespaces=True) ) )

self.print_list(messages[::-1], format_str%( _("Date"), _("Description"), _("Amount"), _("Balance")))
self.print_list(messages[::-1], format_str%(_("Date"), _("Description"), _("Amount"), _("Balance")))


def print_balance(self):
Expand All @@ -110,7 +110,7 @@ def print_balance(self):
def get_balance(self):
if self.wallet.network.is_connected():
if not self.wallet.up_to_date:
msg = _( "Synchronizing..." )
msg = _("Synchronizing...")
else:
c, u, x = self.wallet.get_balance()
msg = _("Balance")+": %f "%(PyDecimal(c) / COIN)
Expand All @@ -119,7 +119,7 @@ def get_balance(self):
if x:
msg += " [%f unmatured]"%(PyDecimal(x) / COIN)
else:
msg = _( "Not connected" )
msg = _("Not connected")

return(msg)

Expand Down Expand Up @@ -148,8 +148,8 @@ def send_order(self):
self.do_send()

def print_banner(self):
for i, x in enumerate( self.wallet.network.banner.split('\n') ):
print( x )
for i, x in enumerate(self.wallet.network.banner.split('\n')):
print(x)

def print_list(self, lst, firstline):
lst = list(lst)
Expand Down
38 changes: 19 additions & 19 deletions electroncash_gui/text.py
Expand Up @@ -79,7 +79,7 @@ def verify_seed(self):
def get_string(self, y, x):
self.set_cursor(1)
curses.echo()
self.stdscr.addstr( y, x, " "*20, curses.A_REVERSE)
self.stdscr.addstr(y, x, " "*20, curses.A_REVERSE)
s = self.stdscr.getstr(y,x)
curses.noecho()
self.set_cursor(0)
Expand All @@ -100,7 +100,7 @@ def print_history(self):
if self.history is None:
self.update_history()

self.print_list(self.history[::-1], format_str%( _("Date"), _("Description"), _("Amount"), _("Balance")))
self.print_list(self.history[::-1], format_str%(_("Date"), _("Description"), _("Amount"), _("Balance")))

def update_history(self):
width = [20, 40, 14, 14]
Expand Down Expand Up @@ -141,10 +141,10 @@ def print_balance(self):
else:
msg = _("Not connected")

self.stdscr.addstr( self.maxy -1, 3, msg)
self.stdscr.addstr(self.maxy -1, 3, msg)

for i in range(self.num_tabs):
self.stdscr.addstr( 0, 2 + 2*i + len(''.join(self.tab_names[0:i])), ' '+self.tab_names[i]+' ', curses.A_BOLD if self.tab == i else 0)
self.stdscr.addstr(0, 2 + 2*i + len(''.join(self.tab_names[0:i])), ' '+self.tab_names[i]+' ', curses.A_BOLD if self.tab == i else 0)

self.stdscr.addstr(self.maxy -1, self.maxx-30, ' '.join([_("Settings"), _("Network"), _("Quit")]))

Expand All @@ -165,18 +165,18 @@ def print_addresses(self):
self.print_list(messages, fmt % ("Address", "Label"))

def print_edit_line(self, y, label, text, index, size):
text += " "*(size - len(text) )
self.stdscr.addstr( y, 2, label)
self.stdscr.addstr( y, 15, text, curses.A_REVERSE if self.pos%6==index else curses.color_pair(1))
text += " "*(size - len(text))
self.stdscr.addstr(y, 2, label)
self.stdscr.addstr(y, 15, text, curses.A_REVERSE if self.pos%6==index else curses.color_pair(1))

def print_send_tab(self):
self.stdscr.clear()
self.print_edit_line(3, _("Pay to"), self.str_recipient, 0, 40)
self.print_edit_line(5, _("Description"), self.str_description, 1, 40)
self.print_edit_line(7, _("Amount"), self.str_amount, 2, 15)
self.print_edit_line(9, _("Fee"), self.str_fee, 3, 15)
self.stdscr.addstr( 12, 15, _("[Send]"), curses.A_REVERSE if self.pos%6==4 else curses.color_pair(2))
self.stdscr.addstr( 12, 25, _("[Clear]"), curses.A_REVERSE if self.pos%6==5 else curses.color_pair(2))
self.stdscr.addstr(12, 15, _("[Send]"), curses.A_REVERSE if self.pos%6==4 else curses.color_pair(2))
self.stdscr.addstr(12, 25, _("[Clear]"), curses.A_REVERSE if self.pos%6==5 else curses.color_pair(2))
self.maxpos = 6

def print_banner(self):
Expand Down Expand Up @@ -206,13 +206,13 @@ def print_list(self, lst, firstline = None):
if not self.maxpos: return
if firstline:
firstline += " "*(self.maxx -2 - len(firstline))
self.stdscr.addstr( 1, 1, firstline )
self.stdscr.addstr(1, 1, firstline)
for i in range(self.maxy-4):
msg = lst[i] if i < len(lst) else ""
msg += " "*(self.maxx - 2 - len(msg))
m = msg[0:self.maxx - 2]
m = m.encode(self.encoding)
self.stdscr.addstr( i+2, 1, m, curses.A_REVERSE if i == (self.pos % self.maxpos) else 0)
self.stdscr.addstr(i+2, 1, m, curses.A_REVERSE if i == (self.pos % self.maxpos) else 0)

def refresh(self):
if self.tab == -1: return
Expand Down Expand Up @@ -401,7 +401,7 @@ def network_dialog(self):
def settings_dialog(self):
fee = str(PyDecimal(self.config.fee_per_kb()) / COIN)
out = self.run_dialog('Settings', [
{'label':'Default fee', 'type':'satoshis', 'value': fee }
{'label':'Default fee', 'type':'satoshis', 'value': fee}
], buttons = 1)
if out:
if out.get('Default fee'):
Expand All @@ -419,13 +419,13 @@ def password_dialog(self):
def run_dialog(self, title, items, interval=2, buttons=None, y_pos=3):
self.popup_pos = 0

self.w = curses.newwin( 5 + len(list(items))*interval + (2 if buttons else 0), 50, y_pos, 5)
self.w = curses.newwin(5 + len(list(items))*interval + (2 if buttons else 0), 50, y_pos, 5)
w = self.w
out = {}
while True:
w.clear()
w.border(0)
w.addstr( 0, 2, title)
w.addstr(0, 2, title)

num = len(list(items))

Expand All @@ -451,14 +451,14 @@ def run_dialog(self, title, items, interval=2, buttons=None, y_pos=3):
value += ' '*(20-len(value))

if 'value' in item:
w.addstr( 2+interval*i, 2, label)
w.addstr( 2+interval*i, 15, value, curses.A_REVERSE if self.popup_pos%numpos==i else curses.color_pair(1) )
w.addstr(2+interval*i, 2, label)
w.addstr(2+interval*i, 15, value, curses.A_REVERSE if self.popup_pos%numpos==i else curses.color_pair(1))
else:
w.addstr( 2+interval*i, 2, label, curses.A_REVERSE if self.popup_pos%numpos==i else 0)
w.addstr(2+interval*i, 2, label, curses.A_REVERSE if self.popup_pos%numpos==i else 0)

if buttons:
w.addstr( 5+interval*i, 10, "[ ok ]", curses.A_REVERSE if self.popup_pos%numpos==(numpos-2) else curses.color_pair(2))
w.addstr( 5+interval*i, 25, "[cancel]", curses.A_REVERSE if self.popup_pos%numpos==(numpos-1) else curses.color_pair(2))
w.addstr(5+interval*i, 10, "[ ok ]", curses.A_REVERSE if self.popup_pos%numpos==(numpos-2) else curses.color_pair(2))
w.addstr(5+interval*i, 25, "[cancel]", curses.A_REVERSE if self.popup_pos%numpos==(numpos-1) else curses.color_pair(2))

w.refresh()

Expand Down
2 changes: 1 addition & 1 deletion electroncash_plugins/hw_wallet/cmdline.py
Expand Up @@ -8,7 +8,7 @@ def get_passphrase(self, msg, confirm):
return getpass.getpass('')

def get_pin(self, msg):
t = { 'a':'7', 'b':'8', 'c':'9', 'd':'4', 'e':'5', 'f':'6', 'g':'1', 'h':'2', 'i':'3'}
t = {'a':'7', 'b':'8', 'c':'9', 'd':'4', 'e':'5', 'f':'6', 'g':'1', 'h':'2', 'i':'3'}
print_msg(msg)
print_msg("a b c\nd e f\ng h i\n-----")
o = raw_input()
Expand Down
8 changes: 4 additions & 4 deletions electroncash_plugins/keepkey/keepkey.py
Expand Up @@ -312,16 +312,16 @@ def get_xpub(self, device_id, derivation, xtype, wizard):
return xpub

def get_keepkey_input_script_type(self, electrum_txin_type: str):
if electrum_txin_type in ('p2pkh', ):
if electrum_txin_type in ('p2pkh',):
return self.types.SPENDADDRESS
if electrum_txin_type in ('p2sh', ):
if electrum_txin_type in ('p2sh',):
return self.types.SPENDMULTISIG
raise ValueError('unexpected txin type: {}'.format(electrum_txin_type))

def get_keepkey_output_script_type(self, electrum_txin_type: str):
if electrum_txin_type in ('p2pkh', ):
if electrum_txin_type in ('p2pkh',):
return self.types.PAYTOADDRESS
if electrum_txin_type in ('p2sh', ):
if electrum_txin_type in ('p2sh',):
return self.types.PAYTOMULTISIG
raise ValueError('unexpected txin type: {}'.format(electrum_txin_type))

Expand Down
4 changes: 2 additions & 2 deletions electroncash_plugins/ledger/auth2fa.py
Expand Up @@ -15,7 +15,7 @@
"put your cursor into it, and plug your device into that computer. " \
"It will output a summary of the transaction being signed and a one-time PIN.<br><br>" \
"Verify the transaction summary and type the PIN code here.<br><br>" \
"Before pressing enter, plug the device back into this computer.<br>" ),
"Before pressing enter, plug the device back into this computer.<br>"),
_("Verify the address below.<br>Type the character from your security card corresponding to the <u><b>BOLD</b></u> character.")
]

Expand Down Expand Up @@ -150,7 +150,7 @@ def update_dlg(self):
def getDevice2FAMode(self):
apdu = [0xe0, 0x24, 0x01, 0x00, 0x00, 0x01] # get 2fa mode
try:
mode = self.dongle.exchange( bytearray(apdu) )
mode = self.dongle.exchange(bytearray(apdu))
return mode
except BTChipException as e:
print_error('Device getMode Failed')
Expand Down
2 changes: 1 addition & 1 deletion electroncash_plugins/ledger/ledger.py
Expand Up @@ -180,7 +180,7 @@ def perform_hw1_preflight(self):
except BTChipException as e:
if (e.sw == 0x6985):
self.dongleObject.dongle.close()
self.handler.get_setup( )
self.handler.get_setup()
# Acquire the new client on the next run
else:
raise e
Expand Down

0 comments on commit a93e579

Please sign in to comment.