parent
7f04c30567
commit
909c063eb1
|
@ -26,7 +26,7 @@ import webbrowser
|
||||||
|
|
||||||
from electrum.i18n import _
|
from electrum.i18n import _
|
||||||
from electrum.bitcoin import is_address
|
from electrum.bitcoin import is_address
|
||||||
from electrum.util import block_explorer_URL
|
from electrum.util import block_explorer_URL, FileImportFailed
|
||||||
from electrum.plugins import run_hook
|
from electrum.plugins import run_hook
|
||||||
from PyQt5.QtGui import *
|
from PyQt5.QtGui import *
|
||||||
from PyQt5.QtCore import *
|
from PyQt5.QtCore import *
|
||||||
|
@ -57,7 +57,10 @@ class ContactList(MyTreeWidget):
|
||||||
filename, __ = QFileDialog.getOpenFileName(self.parent, "Select your wallet file", wallet_folder)
|
filename, __ = QFileDialog.getOpenFileName(self.parent, "Select your wallet file", wallet_folder)
|
||||||
if not filename:
|
if not filename:
|
||||||
return
|
return
|
||||||
self.parent.contacts.import_file(filename)
|
try:
|
||||||
|
self.parent.contacts.import_file(filename)
|
||||||
|
except FileImportFailed as e:
|
||||||
|
self.parent.show_message(str(e))
|
||||||
self.on_update()
|
self.on_update()
|
||||||
|
|
||||||
def create_menu(self, position):
|
def create_menu(self, position):
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
from .util import *
|
from .util import *
|
||||||
from electrum.i18n import _
|
from electrum.i18n import _
|
||||||
from electrum.util import format_time
|
from electrum.util import format_time, FileImportFailed
|
||||||
|
|
||||||
|
|
||||||
class InvoiceList(MyTreeWidget):
|
class InvoiceList(MyTreeWidget):
|
||||||
|
@ -61,7 +61,10 @@ class InvoiceList(MyTreeWidget):
|
||||||
filename, __ = QFileDialog.getOpenFileName(self.parent, "Select your wallet file", wallet_folder)
|
filename, __ = QFileDialog.getOpenFileName(self.parent, "Select your wallet file", wallet_folder)
|
||||||
if not filename:
|
if not filename:
|
||||||
return
|
return
|
||||||
self.parent.invoices.import_file(filename)
|
try:
|
||||||
|
self.parent.invoices.import_file(filename)
|
||||||
|
except FileImportFailed as e:
|
||||||
|
self.parent.show_message(str(e))
|
||||||
self.on_update()
|
self.on_update()
|
||||||
|
|
||||||
def create_menu(self, position):
|
def create_menu(self, position):
|
||||||
|
|
|
@ -23,9 +23,12 @@
|
||||||
import re
|
import re
|
||||||
import dns
|
import dns
|
||||||
import json
|
import json
|
||||||
|
import traceback
|
||||||
|
import sys
|
||||||
|
|
||||||
from . import bitcoin
|
from . import bitcoin
|
||||||
from . import dnssec
|
from . import dnssec
|
||||||
|
from .util import FileImportFailed, FileImportFailedEncrypted
|
||||||
|
|
||||||
|
|
||||||
class Contacts(dict):
|
class Contacts(dict):
|
||||||
|
@ -51,8 +54,12 @@ class Contacts(dict):
|
||||||
try:
|
try:
|
||||||
with open(path, 'r') as f:
|
with open(path, 'r') as f:
|
||||||
d = self._validate(json.loads(f.read()))
|
d = self._validate(json.loads(f.read()))
|
||||||
except:
|
except json.decoder.JSONDecodeError:
|
||||||
return
|
traceback.print_exc(file=sys.stderr)
|
||||||
|
raise FileImportFailedEncrypted()
|
||||||
|
except BaseException:
|
||||||
|
traceback.print_exc(file=sys.stdout)
|
||||||
|
raise FileImportFailed()
|
||||||
self.update(d)
|
self.update(d)
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,7 @@ except ImportError:
|
||||||
from . import bitcoin
|
from . import bitcoin
|
||||||
from . import util
|
from . import util
|
||||||
from .util import print_error, bh2u, bfh
|
from .util import print_error, bh2u, bfh
|
||||||
|
from .util import FileImportFailed, FileImportFailedEncrypted
|
||||||
from . import transaction
|
from . import transaction
|
||||||
from . import x509
|
from . import x509
|
||||||
from . import rsakey
|
from . import rsakey
|
||||||
|
@ -471,9 +472,12 @@ class InvoiceStore(object):
|
||||||
with open(path, 'r') as f:
|
with open(path, 'r') as f:
|
||||||
d = json.loads(f.read())
|
d = json.loads(f.read())
|
||||||
self.load(d)
|
self.load(d)
|
||||||
except:
|
except json.decoder.JSONDecodeError:
|
||||||
traceback.print_exc(file=sys.stderr)
|
traceback.print_exc(file=sys.stderr)
|
||||||
return
|
raise FileImportFailedEncrypted()
|
||||||
|
except BaseException:
|
||||||
|
traceback.print_exc(file=sys.stdout)
|
||||||
|
raise FileImportFailed()
|
||||||
self.save()
|
self.save()
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
|
|
13
lib/util.py
13
lib/util.py
|
@ -58,6 +58,19 @@ class InvalidPassword(Exception):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return _("Incorrect password")
|
return _("Incorrect password")
|
||||||
|
|
||||||
|
|
||||||
|
class FileImportFailed(Exception):
|
||||||
|
def __str__(self):
|
||||||
|
return _("Failed to import file.")
|
||||||
|
|
||||||
|
|
||||||
|
class FileImportFailedEncrypted(FileImportFailed):
|
||||||
|
def __str__(self):
|
||||||
|
return (_('Failed to import file.') + ' ' +
|
||||||
|
_('Perhaps it is encrypted...') + '\n' +
|
||||||
|
_('Importing encrypted files is not supported.'))
|
||||||
|
|
||||||
|
|
||||||
# Throw this exception to unwind the stack like when an error occurs.
|
# Throw this exception to unwind the stack like when an error occurs.
|
||||||
# However unlike other exceptions the user won't be informed.
|
# However unlike other exceptions the user won't be informed.
|
||||||
class UserCancelled(Exception):
|
class UserCancelled(Exception):
|
||||||
|
|
Loading…
Reference in New Issue