Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Commit d8c7114

Browse files
committed
python3 compatable byte string construction
1 parent e28a1cf commit d8c7114

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

ethereum/transactions.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def sender(self):
8787
pk.public_key = pk.ecdsa_recover(
8888
rawhash,
8989
pk.ecdsa_recoverable_deserialize(
90-
zpad("".join(chr(c) for c in int_to_32bytearray(self.r)), 32) + zpad("".join(chr(c) for c in int_to_32bytearray(self.s)), 32),
90+
zpad(utils.bytearray_to_bytestr(int_to_32bytearray(self.r)), 32) + zpad(utils.bytearray_to_bytestr(int_to_32bytearray(self.s)), 32),
9191
self.v - 27
9292
),
9393
raw=True
@@ -126,8 +126,8 @@ def sign(self, key):
126126
signature = pk.ecdsa_recoverable_serialize(
127127
pk.ecdsa_sign_recoverable(rawhash, raw=True)
128128
)
129-
signature = signature[0] + chr(signature[1]).encode('utf8')
130-
self.v = signature[64] + 27
129+
signature = signature[0] + utils.bytearray_to_bytestr([signature[1]])
130+
self.v = utils.safe_ord(signature[64]) + 27
131131
self.r = big_endian_to_int(signature[0:32])
132132
self.s = big_endian_to_int(signature[32:64])
133133

ethereum/utils.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ def to_string_for_regexp(value):
3535
return str(value)
3636
unicode = unicode
3737

38+
def bytearray_to_bytestr(value):
39+
return bytes(''.join(chr(c) for c in value))
40+
3841
else:
3942
is_numeric = lambda x: isinstance(x, int)
4043
is_string = lambda x: isinstance(x, bytes)
@@ -56,6 +59,9 @@ def to_string_for_regexp(value):
5659
return str(to_string(value), 'utf-8')
5760
unicode = str
5861

62+
def bytearray_to_bytestr(value):
63+
return bytes(value)
64+
5965
isnumeric = is_numeric
6066

6167

0 commit comments

Comments
 (0)