Skip to content

Commit

Permalink
changed runtimeerrors
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmysong committed Nov 6, 2018
1 parent 2483fbc commit 70cb7ed
Show file tree
Hide file tree
Showing 15 changed files with 51 additions and 51 deletions.
10 changes: 5 additions & 5 deletions code-ch04/ecc.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,22 +569,22 @@ def parse(cls, signature_bin):
s = BytesIO(signature_bin)
compound = s.read(1)[0]
if compound != 0x30:
raise RuntimeError("Bad Signature")
raise SyntaxError("Bad Signature")
length = s.read(1)[0]
if length + 2 != len(signature_bin):
raise RuntimeError("Bad Signature Length")
raise SyntaxError("Bad Signature Length")
marker = s.read(1)[0]
if marker != 0x02:
raise RuntimeError("Bad Signature")
raise SyntaxError("Bad Signature")
rlength = s.read(1)[0]
r = int(s.read(rlength).hex(), 16)
marker = s.read(1)[0]
if marker != 0x02:
raise RuntimeError("Bad Signature")
raise SyntaxError("Bad Signature")
slength = s.read(1)[0]
s = int(s.read(slength).hex(), 16)
if len(signature_bin) != 6 + rlength + slength:
raise RuntimeError("Signature too long")
raise SyntaxError("Signature too long")
return cls(r, s)


Expand Down
4 changes: 2 additions & 2 deletions code-ch05/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def decode_base58(s):
combined = num.to_bytes(25, byteorder='big')
checksum = combined[-4:]
if hash256(combined[:-4])[:4] != checksum:
raise RuntimeError('bad address: {} {}'.format(checksum, hash256(combined)[:4]))
raise ValueError('bad address: {} {}'.format(checksum, hash256(combined)[:4]))
return combined[1:-4]


Expand Down Expand Up @@ -97,7 +97,7 @@ def encode_varint(i):
elif i < 0x10000000000000000:
return b'\xff' + int_to_little_endian(i, 8)
else:
raise RuntimeError('integer too large: {}'.format(i))
raise ValueError('integer too large: {}'.format(i))


class HelperTest(TestCase):
Expand Down
4 changes: 2 additions & 2 deletions code-ch06/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def decode_base58(s):
combined = num.to_bytes(25, byteorder='big')
checksum = combined[-4:]
if hash256(combined[:-4])[:4] != checksum:
raise RuntimeError('bad address: {} {}'.format(checksum, hash256(combined)[:4]))
raise ValueError('bad address: {} {}'.format(checksum, hash256(combined)[:4]))
return combined[1:-4]


Expand Down Expand Up @@ -97,7 +97,7 @@ def encode_varint(i):
elif i < 0x10000000000000000:
return b'\xff' + int_to_little_endian(i, 8)
else:
raise RuntimeError('integer too large: {}'.format(i))
raise ValueError('integer too large: {}'.format(i))


class HelperTest(TestCase):
Expand Down
10 changes: 5 additions & 5 deletions code-ch07/ecc.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,22 +569,22 @@ def parse(cls, signature_bin):
s = BytesIO(signature_bin)
compound = s.read(1)[0]
if compound != 0x30:
raise RuntimeError("Bad Signature")
raise SyntaxError("Bad Signature")
length = s.read(1)[0]
if length + 2 != len(signature_bin):
raise RuntimeError("Bad Signature Length")
raise SyntaxError("Bad Signature Length")
marker = s.read(1)[0]
if marker != 0x02:
raise RuntimeError("Bad Signature")
raise SyntaxError("Bad Signature")
rlength = s.read(1)[0]
r = int(s.read(rlength).hex(), 16)
marker = s.read(1)[0]
if marker != 0x02:
raise RuntimeError("Bad Signature")
raise SyntaxError("Bad Signature")
slength = s.read(1)[0]
s = int(s.read(slength).hex(), 16)
if len(signature_bin) != 6 + rlength + slength:
raise RuntimeError("Signature too long")
raise SyntaxError("Signature too long")
return cls(r, s)


Expand Down
4 changes: 2 additions & 2 deletions code-ch07/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def decode_base58(s):
combined = num.to_bytes(25, byteorder='big')
checksum = combined[-4:]
if hash256(combined[:-4])[:4] != checksum:
raise RuntimeError('bad address: {} {}'.format(checksum, hash256(combined)[:4]))
raise ValueError('bad address: {} {}'.format(checksum, hash256(combined)[:4]))
return combined[1:-4]


Expand Down Expand Up @@ -100,7 +100,7 @@ def encode_varint(i):
elif i < 0x10000000000000000:
return b'\xff' + int_to_little_endian(i, 8)
else:
raise RuntimeError('integer too large: {}'.format(i))
raise ValueError('integer too large: {}'.format(i))


class HelperTest(TestCase):
Expand Down
10 changes: 5 additions & 5 deletions code-ch08/ecc.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,22 +569,22 @@ def parse(cls, signature_bin):
s = BytesIO(signature_bin)
compound = s.read(1)[0]
if compound != 0x30:
raise RuntimeError("Bad Signature")
raise SyntaxError("Bad Signature")
length = s.read(1)[0]
if length + 2 != len(signature_bin):
raise RuntimeError("Bad Signature Length")
raise SyntaxError("Bad Signature Length")
marker = s.read(1)[0]
if marker != 0x02:
raise RuntimeError("Bad Signature")
raise SyntaxError("Bad Signature")
rlength = s.read(1)[0]
r = int(s.read(rlength).hex(), 16)
marker = s.read(1)[0]
if marker != 0x02:
raise RuntimeError("Bad Signature")
raise SyntaxError("Bad Signature")
slength = s.read(1)[0]
s = int(s.read(slength).hex(), 16)
if len(signature_bin) != 6 + rlength + slength:
raise RuntimeError("Signature too long")
raise SyntaxError("Signature too long")
return cls(r, s)


Expand Down
4 changes: 2 additions & 2 deletions code-ch08/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def decode_base58(s):
combined = num.to_bytes(25, byteorder='big')
checksum = combined[-4:]
if hash256(combined[:-4])[:4] != checksum:
raise RuntimeError('bad address: {} {}'.format(checksum, hash256(combined)[:4]))
raise ValueError('bad address: {} {}'.format(checksum, hash256(combined)[:4]))
return combined[1:-4]


Expand Down Expand Up @@ -100,7 +100,7 @@ def encode_varint(i):
elif i < 0x10000000000000000:
return b'\xff' + int_to_little_endian(i, 8)
else:
raise RuntimeError('integer too large: {}'.format(i))
raise ValueError('integer too large: {}'.format(i))


def h160_to_p2pkh_address(h160, testnet=False):
Expand Down
10 changes: 5 additions & 5 deletions code-ch09/ecc.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,22 +569,22 @@ def parse(cls, signature_bin):
s = BytesIO(signature_bin)
compound = s.read(1)[0]
if compound != 0x30:
raise RuntimeError("Bad Signature")
raise SyntaxError("Bad Signature")
length = s.read(1)[0]
if length + 2 != len(signature_bin):
raise RuntimeError("Bad Signature Length")
raise SyntaxError("Bad Signature Length")
marker = s.read(1)[0]
if marker != 0x02:
raise RuntimeError("Bad Signature")
raise SyntaxError("Bad Signature")
rlength = s.read(1)[0]
r = int(s.read(rlength).hex(), 16)
marker = s.read(1)[0]
if marker != 0x02:
raise RuntimeError("Bad Signature")
raise SyntaxError("Bad Signature")
slength = s.read(1)[0]
s = int(s.read(slength).hex(), 16)
if len(signature_bin) != 6 + rlength + slength:
raise RuntimeError("Signature too long")
raise SyntaxError("Signature too long")
return cls(r, s)


Expand Down
4 changes: 2 additions & 2 deletions code-ch09/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def decode_base58(s):
combined = num.to_bytes(25, byteorder='big')
checksum = combined[-4:]
if hash256(combined[:-4])[:4] != checksum:
raise RuntimeError('bad address: {} {}'.format(checksum, hash256(combined)[:4]))
raise ValueError('bad address: {} {}'.format(checksum, hash256(combined)[:4]))
return combined[1:-4]


Expand Down Expand Up @@ -101,7 +101,7 @@ def encode_varint(i):
elif i < 0x10000000000000000:
return b'\xff' + int_to_little_endian(i, 8)
else:
raise RuntimeError('integer too large: {}'.format(i))
raise ValueError('integer too large: {}'.format(i))


def h160_to_p2pkh_address(h160, testnet=False):
Expand Down
10 changes: 5 additions & 5 deletions code-ch10/ecc.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,22 +569,22 @@ def parse(cls, signature_bin):
s = BytesIO(signature_bin)
compound = s.read(1)[0]
if compound != 0x30:
raise RuntimeError("Bad Signature")
raise SyntaxError("Bad Signature")
length = s.read(1)[0]
if length + 2 != len(signature_bin):
raise RuntimeError("Bad Signature Length")
raise SyntaxError("Bad Signature Length")
marker = s.read(1)[0]
if marker != 0x02:
raise RuntimeError("Bad Signature")
raise SyntaxError("Bad Signature")
rlength = s.read(1)[0]
r = int(s.read(rlength).hex(), 16)
marker = s.read(1)[0]
if marker != 0x02:
raise RuntimeError("Bad Signature")
raise SyntaxError("Bad Signature")
slength = s.read(1)[0]
s = int(s.read(slength).hex(), 16)
if len(signature_bin) != 6 + rlength + slength:
raise RuntimeError("Signature too long")
raise SyntaxError("Signature too long")
return cls(r, s)


Expand Down
4 changes: 2 additions & 2 deletions code-ch10/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def decode_base58(s):
combined = num.to_bytes(25, byteorder='big')
checksum = combined[-4:]
if hash256(combined[:-4])[:4] != checksum:
raise RuntimeError('bad address: {} {}'.format(checksum, hash256(combined)[:4]))
raise ValueError('bad address: {} {}'.format(checksum, hash256(combined)[:4]))
return combined[1:-4]


Expand Down Expand Up @@ -102,7 +102,7 @@ def encode_varint(i):
elif i < 0x10000000000000000:
return b'\xff' + int_to_little_endian(i, 8)
else:
raise RuntimeError('integer too large: {}'.format(i))
raise ValueError('integer too large: {}'.format(i))


def h160_to_p2pkh_address(h160, testnet=False):
Expand Down
10 changes: 5 additions & 5 deletions code-ch11/ecc.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,22 +569,22 @@ def parse(cls, signature_bin):
s = BytesIO(signature_bin)
compound = s.read(1)[0]
if compound != 0x30:
raise RuntimeError("Bad Signature")
raise SyntaxError("Bad Signature")
length = s.read(1)[0]
if length + 2 != len(signature_bin):
raise RuntimeError("Bad Signature Length")
raise SyntaxError("Bad Signature Length")
marker = s.read(1)[0]
if marker != 0x02:
raise RuntimeError("Bad Signature")
raise SyntaxError("Bad Signature")
rlength = s.read(1)[0]
r = int(s.read(rlength).hex(), 16)
marker = s.read(1)[0]
if marker != 0x02:
raise RuntimeError("Bad Signature")
raise SyntaxError("Bad Signature")
slength = s.read(1)[0]
s = int(s.read(slength).hex(), 16)
if len(signature_bin) != 6 + rlength + slength:
raise RuntimeError("Signature too long")
raise SyntaxError("Signature too long")
return cls(r, s)


Expand Down
4 changes: 2 additions & 2 deletions code-ch11/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def decode_base58(s):
combined = num.to_bytes(25, byteorder='big')
checksum = combined[-4:]
if hash256(combined[:-4])[:4] != checksum:
raise RuntimeError('bad address: {} {}'.format(checksum, hash256(combined)[:4]))
raise ValueError('bad address: {} {}'.format(checksum, hash256(combined)[:4]))
return combined[1:-4]


Expand Down Expand Up @@ -102,7 +102,7 @@ def encode_varint(i):
elif i < 0x10000000000000000:
return b'\xff' + int_to_little_endian(i, 8)
else:
raise RuntimeError('integer too large: {}'.format(i))
raise ValueError('integer too large: {}'.format(i))


def h160_to_p2pkh_address(h160, testnet=False):
Expand Down
10 changes: 5 additions & 5 deletions code-ch12/ecc.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,22 +569,22 @@ def parse(cls, signature_bin):
s = BytesIO(signature_bin)
compound = s.read(1)[0]
if compound != 0x30:
raise RuntimeError("Bad Signature")
raise SyntaxError("Bad Signature")
length = s.read(1)[0]
if length + 2 != len(signature_bin):
raise RuntimeError("Bad Signature Length")
raise SyntaxError("Bad Signature Length")
marker = s.read(1)[0]
if marker != 0x02:
raise RuntimeError("Bad Signature")
raise SyntaxError("Bad Signature")
rlength = s.read(1)[0]
r = int(s.read(rlength).hex(), 16)
marker = s.read(1)[0]
if marker != 0x02:
raise RuntimeError("Bad Signature")
raise SyntaxError("Bad Signature")
slength = s.read(1)[0]
s = int(s.read(slength).hex(), 16)
if len(signature_bin) != 6 + rlength + slength:
raise RuntimeError("Signature too long")
raise SyntaxError("Signature too long")
return cls(r, s)


Expand Down
4 changes: 2 additions & 2 deletions code-ch12/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def decode_base58(s):
combined = num.to_bytes(25, byteorder='big')
checksum = combined[-4:]
if hash256(combined[:-4])[:4] != checksum:
raise RuntimeError('bad address: {} {}'.format(checksum, hash256(combined)[:4]))
raise ValueError('bad address: {} {}'.format(checksum, hash256(combined)[:4]))
return combined[1:-4]


Expand Down Expand Up @@ -102,7 +102,7 @@ def encode_varint(i):
elif i < 0x10000000000000000:
return b'\xff' + int_to_little_endian(i, 8)
else:
raise RuntimeError('integer too large: {}'.format(i))
raise ValueError('integer too large: {}'.format(i))


def h160_to_p2pkh_address(h160, testnet=False):
Expand Down

0 comments on commit 70cb7ed

Please sign in to comment.