replace semantically relevant instances of 'assert' with exceptions
This commit is contained in:
parent
d253d8463b
commit
a7d3175799
|
@ -352,7 +352,8 @@ def parse_URI(uri, on_pr=None):
|
||||||
|
|
||||||
out = {k: v[0] for k, v in pq.items()}
|
out = {k: v[0] for k, v in pq.items()}
|
||||||
if address:
|
if address:
|
||||||
assert bitcoin.is_address(address)
|
if not bitcoin.is_address(address):
|
||||||
|
raise BaseException("Invalid bitcoin address:" + address)
|
||||||
out['address'] = address
|
out['address'] = address
|
||||||
if 'amount' in out:
|
if 'amount' in out:
|
||||||
am = out['amount']
|
am = out['amount']
|
||||||
|
|
|
@ -354,7 +354,8 @@ class Abstract_Wallet(PrintError):
|
||||||
return account is not None
|
return account is not None
|
||||||
|
|
||||||
def import_key(self, sec, password):
|
def import_key(self, sec, password):
|
||||||
assert self.can_import(), 'This wallet cannot import private keys'
|
if not self.can_import():
|
||||||
|
raise BaseException('This wallet cannot import private keys')
|
||||||
try:
|
try:
|
||||||
pubkey = public_key_from_private_key(sec)
|
pubkey = public_key_from_private_key(sec)
|
||||||
address = public_key_to_bc_address(pubkey.decode('hex'))
|
address = public_key_to_bc_address(pubkey.decode('hex'))
|
||||||
|
@ -929,7 +930,8 @@ class Abstract_Wallet(PrintError):
|
||||||
# check outputs
|
# check outputs
|
||||||
for type, data, value in outputs:
|
for type, data, value in outputs:
|
||||||
if type == TYPE_ADDRESS:
|
if type == TYPE_ADDRESS:
|
||||||
assert is_address(data), "Address " + data + " is invalid!"
|
if not is_address(data):
|
||||||
|
raise BaseException("Invalid bitcoin address:" + data)
|
||||||
|
|
||||||
# Avoid index-out-of-range with coins[0] below
|
# Avoid index-out-of-range with coins[0] below
|
||||||
if not coins:
|
if not coins:
|
||||||
|
@ -1040,7 +1042,8 @@ class Abstract_Wallet(PrintError):
|
||||||
# asynchronous
|
# asynchronous
|
||||||
self.tx_event.clear()
|
self.tx_event.clear()
|
||||||
# fixme: this does not handle the case where server does not answer
|
# fixme: this does not handle the case where server does not answer
|
||||||
assert self.network.interface, "Not connected."
|
if not self.network.interface:
|
||||||
|
raise BaseException("Not connected")
|
||||||
self.network.send([('blockchain.transaction.broadcast', [str(tx)])], self.on_broadcast)
|
self.network.send([('blockchain.transaction.broadcast', [str(tx)])], self.on_broadcast)
|
||||||
return tx.hash()
|
return tx.hash()
|
||||||
|
|
||||||
|
@ -1864,18 +1867,16 @@ class OldWallet(Deterministic_Wallet):
|
||||||
import old_mnemonic
|
import old_mnemonic
|
||||||
# see if seed was entered as hex
|
# see if seed was entered as hex
|
||||||
seed = seed.strip()
|
seed = seed.strip()
|
||||||
|
if seed:
|
||||||
try:
|
try:
|
||||||
assert seed
|
|
||||||
seed.decode('hex')
|
seed.decode('hex')
|
||||||
return OLD_SEED_VERSION, str(seed)
|
return OLD_SEED_VERSION, str(seed)
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
words = seed.split()
|
words = seed.split()
|
||||||
seed = old_mnemonic.mn_decode(words)
|
seed = old_mnemonic.mn_decode(words)
|
||||||
if not seed:
|
if not seed:
|
||||||
raise Exception("Invalid seed")
|
raise Exception("Invalid seed")
|
||||||
|
|
||||||
return OLD_SEED_VERSION, seed
|
return OLD_SEED_VERSION, seed
|
||||||
|
|
||||||
def create_master_keys(self, password):
|
def create_master_keys(self, password):
|
||||||
|
@ -2001,10 +2002,9 @@ class Wallet(object):
|
||||||
def is_old_mpk(mpk):
|
def is_old_mpk(mpk):
|
||||||
try:
|
try:
|
||||||
int(mpk, 16)
|
int(mpk, 16)
|
||||||
assert len(mpk) == 128
|
|
||||||
return True
|
|
||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
|
return len(mpk) == 128
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def is_xpub(text):
|
def is_xpub(text):
|
||||||
|
|
Loading…
Reference in New Issue