1
0

Catch wallet file related exceptions in Qt wizard.

This commit is contained in:
SomberNight
2018-03-17 22:56:20 +01:00
parent 680df7d6b6
commit 61a45edee0
7 changed files with 63 additions and 38 deletions

View File

@@ -32,7 +32,7 @@ import json
import ecdsa
import pyaes
from .util import bfh, bh2u, to_string
from .util import bfh, bh2u, to_string, BitcoinException
from . import version
from .util import print_error, InvalidPassword, assert_bytes, to_bytes, inv_dict
from . import segwit_addr
@@ -349,7 +349,7 @@ def address_to_script(addr):
script += push_script(bh2u(hash_160))
script += '87' # op_equal
else:
raise BaseException('unknown address type')
raise BitcoinException('unknown address type: {}'.format(addrtype))
return script
def address_to_scripthash(addr):
@@ -493,7 +493,8 @@ def deserialize_privkey(key):
vch = DecodeBase58Check(key)
except BaseException:
neutered_privkey = str(key)[:3] + '..' + str(key)[-2:]
raise BaseException("cannot deserialize", neutered_privkey)
raise BitcoinException("cannot deserialize privkey {}"
.format(neutered_privkey))
if txin_type is None:
# keys exported in version 3.0.x encoded script type in first byte
@@ -888,7 +889,8 @@ def deserialize_xkey(xkey, prv, *, net=None):
net = constants.net
xkey = DecodeBase58Check(xkey)
if len(xkey) != 78:
raise BaseException('Invalid length')
raise BitcoinException('Invalid length for extended key: {}'
.format(len(xkey)))
depth = xkey[4]
fingerprint = xkey[5:9]
child_number = xkey[9:13]
@@ -896,7 +898,8 @@ def deserialize_xkey(xkey, prv, *, net=None):
header = int('0x' + bh2u(xkey[0:4]), 16)
headers = net.XPRV_HEADERS if prv else net.XPUB_HEADERS
if header not in headers.values():
raise BaseException('Invalid xpub format', hex(header))
raise BitcoinException('Invalid extended key format: {}'
.format(hex(header)))
xtype = list(headers.keys())[list(headers.values()).index(header)]
n = 33 if prv else 32
K_or_k = xkey[13+n:]