Merge pull request #9819 from f321x/fix_tui_crash
fix: text gui exceptions and and type errors
This commit is contained in:
@@ -13,12 +13,11 @@ try:
|
|||||||
except ImportError: # only use vendored lib as fallback, to allow Linux distros to bring their own
|
except ImportError: # only use vendored lib as fallback, to allow Linux distros to bring their own
|
||||||
from electrum._vendor import pyperclip
|
from electrum._vendor import pyperclip
|
||||||
|
|
||||||
import electrum
|
|
||||||
from electrum.gui import BaseElectrumGui
|
from electrum.gui import BaseElectrumGui
|
||||||
from electrum.bip21 import parse_bip21_URI
|
from electrum.bip21 import parse_bip21_URI
|
||||||
from electrum.util import format_satoshis, format_time
|
from electrum.util import format_time
|
||||||
from electrum.util import EventListener, event_listener
|
from electrum.util import EventListener, event_listener
|
||||||
from electrum.bitcoin import is_address, address_to_script, COIN
|
from electrum.bitcoin import is_address, address_to_script
|
||||||
from electrum.transaction import PartialTxOutput
|
from electrum.transaction import PartialTxOutput
|
||||||
from electrum.wallet import Wallet, Abstract_Wallet
|
from electrum.wallet import Wallet, Abstract_Wallet
|
||||||
from electrum.wallet_db import WalletDB
|
from electrum.wallet_db import WalletDB
|
||||||
@@ -64,15 +63,14 @@ class ElectrumGui(BaseElectrumGui, EventListener):
|
|||||||
BaseElectrumGui.__init__(self, config=config, daemon=daemon, plugins=plugins)
|
BaseElectrumGui.__init__(self, config=config, daemon=daemon, plugins=plugins)
|
||||||
self.network = daemon.network
|
self.network = daemon.network
|
||||||
storage = WalletStorage(config.get_wallet_path(use_gui_last_wallet=True))
|
storage = WalletStorage(config.get_wallet_path(use_gui_last_wallet=True))
|
||||||
|
password = None
|
||||||
if not storage.file_exists():
|
if not storage.file_exists():
|
||||||
print("Wallet not found. try 'electrum create'")
|
print("Wallet not found. try 'electrum create'")
|
||||||
exit()
|
exit()
|
||||||
if storage.is_encrypted():
|
if storage.is_encrypted():
|
||||||
password = getpass.getpass('Password:', stream=None)
|
password = getpass.getpass('Password:', stream=None)
|
||||||
storage.decrypt(password)
|
del storage
|
||||||
db = WalletDB(storage.read(), storage=storage, upgrade=True)
|
self.wallet = self.daemon.load_wallet(config.get_wallet_path(use_gui_last_wallet=True), password)
|
||||||
self.wallet = Wallet(db, config=config) # type: Optional[Abstract_Wallet]
|
|
||||||
self.wallet.start_network(self.network)
|
|
||||||
self.contacts = self.wallet.contacts
|
self.contacts = self.wallet.contacts
|
||||||
|
|
||||||
locale.setlocale(locale.LC_ALL, '')
|
locale.setlocale(locale.LC_ALL, '')
|
||||||
@@ -87,7 +85,7 @@ class ElectrumGui(BaseElectrumGui, EventListener):
|
|||||||
curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_CYAN)
|
curses.init_pair(2, curses.COLOR_WHITE, curses.COLOR_CYAN)
|
||||||
curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE)
|
curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_WHITE)
|
||||||
curses.halfdelay(1)
|
curses.halfdelay(1)
|
||||||
self.stdscr.keypad(1)
|
self.stdscr.keypad(True)
|
||||||
self.stdscr.border(0)
|
self.stdscr.border(0)
|
||||||
self.maxy, self.maxx = self.stdscr.getmaxyx()
|
self.maxy, self.maxx = self.stdscr.getmaxyx()
|
||||||
self.set_cursor(0)
|
self.set_cursor(0)
|
||||||
@@ -137,11 +135,11 @@ class ElectrumGui(BaseElectrumGui, EventListener):
|
|||||||
def verify_seed(self):
|
def verify_seed(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def get_string(self, y, x):
|
def get_string(self, y, x) -> str:
|
||||||
self.set_cursor(1)
|
self.set_cursor(1)
|
||||||
curses.echo()
|
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)
|
s = self.stdscr.getstr(y,x).decode()
|
||||||
curses.noecho()
|
curses.noecho()
|
||||||
self.set_cursor(0)
|
self.set_cursor(0)
|
||||||
return s
|
return s
|
||||||
@@ -515,7 +513,10 @@ class ElectrumGui(BaseElectrumGui, EventListener):
|
|||||||
elif out == "Edit label":
|
elif out == "Edit label":
|
||||||
s = self.get_string(6 + self.pos, 18)
|
s = self.get_string(6 + self.pos, 18)
|
||||||
if s:
|
if s:
|
||||||
self.wallet.set_label(key, s)
|
self.contacts[key] = ('address', s)
|
||||||
|
elif out == "Delete":
|
||||||
|
self.contacts.pop(key)
|
||||||
|
self.pos = 0
|
||||||
|
|
||||||
def run_addresses_tab(self, c):
|
def run_addresses_tab(self, c):
|
||||||
pass
|
pass
|
||||||
@@ -524,7 +525,7 @@ class ElectrumGui(BaseElectrumGui, EventListener):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
def run_channels_tab(self, c):
|
def run_channels_tab(self, c):
|
||||||
if c == ord("\n"):
|
if c == ord("\n") and self.channel_ids:
|
||||||
out = self.run_popup('Channel Details', ['Short channel ID:', self.channel_ids[self.pos]])
|
out = self.run_popup('Channel Details', ['Short channel ID:', self.channel_ids[self.pos]])
|
||||||
|
|
||||||
def run_banner_tab(self, c):
|
def run_banner_tab(self, c):
|
||||||
@@ -549,7 +550,7 @@ class ElectrumGui(BaseElectrumGui, EventListener):
|
|||||||
finally:
|
finally:
|
||||||
tty.setcbreak(sys.stdin)
|
tty.setcbreak(sys.stdin)
|
||||||
curses.nocbreak()
|
curses.nocbreak()
|
||||||
self.stdscr.keypad(0)
|
self.stdscr.keypad(False)
|
||||||
curses.echo()
|
curses.echo()
|
||||||
curses.endwin()
|
curses.endwin()
|
||||||
|
|
||||||
@@ -625,10 +626,13 @@ class ElectrumGui(BaseElectrumGui, EventListener):
|
|||||||
if amount_sat:
|
if amount_sat:
|
||||||
invoice.set_amount_msat(int(amount_sat * 1000))
|
invoice.set_amount_msat(int(amount_sat * 1000))
|
||||||
else:
|
else:
|
||||||
self.show_error(_('No amount'))
|
self.show_message(_('No amount'))
|
||||||
return
|
return None
|
||||||
elif is_address(self.str_recipient):
|
elif is_address(self.str_recipient):
|
||||||
amount_sat = self.parse_amount(self.str_amount)
|
amount_sat = self.parse_amount(self.str_amount)
|
||||||
|
if not amount_sat:
|
||||||
|
self.show_message(_('No amount'))
|
||||||
|
return None
|
||||||
scriptpubkey = address_to_script(self.str_recipient)
|
scriptpubkey = address_to_script(self.str_recipient)
|
||||||
outputs = [PartialTxOutput(scriptpubkey=scriptpubkey, value=amount_sat)]
|
outputs = [PartialTxOutput(scriptpubkey=scriptpubkey, value=amount_sat)]
|
||||||
invoice = self.wallet.create_invoice(
|
invoice = self.wallet.create_invoice(
|
||||||
@@ -638,7 +642,7 @@ class ElectrumGui(BaseElectrumGui, EventListener):
|
|||||||
URI=None)
|
URI=None)
|
||||||
else:
|
else:
|
||||||
self.show_message(_('Invalid Bitcoin address'))
|
self.show_message(_('Invalid Bitcoin address'))
|
||||||
return
|
return None
|
||||||
return invoice
|
return invoice
|
||||||
|
|
||||||
def do_save_invoice(self):
|
def do_save_invoice(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user