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

Commit 18e7d3a

Browse files
committed
encode_abi failed in python3 due to non-bytestrings, sha3 also required utf-8 string to be encoded before hashing
1 parent b7a551c commit 18e7d3a

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

ethereum/abi.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def __init__(self, full_signature):
3232
" name. Use %s to call %s with types %r"
3333
% (name, sig_item['name'], encode_types))
3434
sig = name + '(' + ','.join(encode_types) + ')'
35+
sig = sig.encode('utf-8')
3536
if sig_item['type'] == 'function':
3637
prefix = big_endian_to_int(utils.sha3(sig)[:4])
3738
decode_types = [f['type'] for f in sig_item['outputs']]
@@ -118,7 +119,7 @@ def decint(n):
118119

119120
# Encodes a base type
120121
def encode_single(arg, base, sub):
121-
normal_args, len_args, var_args = '', '', ''
122+
normal_args, len_args, var_args = b'', b'', b''
122123
# Unsigned integers: uint<sz>
123124
if base == 'uint':
124125
sub = int(sub)
@@ -234,31 +235,31 @@ def encode_any(arg, base, sub, arrlist):
234235
if base == 'string' and sub == '':
235236
raise Exception('Array of dynamic-sized items not allowed: %r'
236237
% arg)
237-
o = ''
238+
o = b''
238239
assert isinstance(arg, list), "Expecting array: %r" % arg
239240
for a in arg:
240241
_, n, _ = encode_any(a, base, sub, arrlist[:-1])
241242
o += n
242-
return zpad(encode_int(len(arg)), 32), '', o
243+
return zpad(encode_int(len(arg)), 32), b'', o
243244
# Fixed-sized arrays
244245
else:
245246
if base == 'string' and sub == '':
246247
raise Exception('Array of dynamic-sized items not allowed')
247248
sz = int(arrlist[-1][1:-1])
248249
assert isinstance(arg, list), "Expecting array: %r" % arg
249250
assert sz == len(arg), "Wrong number of elements in array: %r" % arg
250-
o = ''
251+
o = b''
251252
for a in arg:
252253
_, n, _ = encode_any(a, base, sub, arrlist[:-1])
253254
o += n
254-
return '', o, ''
255+
return b'', o, b''
255256

256257

257258
# Encodes ABI data given a prefix, a list of types, and a list of arguments
258259
def encode_abi(types, args):
259-
len_args = ''
260-
normal_args = ''
261-
var_args = ''
260+
len_args = b''
261+
normal_args = b''
262+
var_args = b''
262263
if len(types) != len(args):
263264
raise Exception("Wrong number of arguments!")
264265
for typ, arg in zip(types, args):

0 commit comments

Comments
 (0)