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

Commit b90a503

Browse files
committed
contracts now compile with python 3 bytestrings
1 parent bc137bf commit b90a503

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

ethereum/vm.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
verify_stack_after_op = False
44

55
# ######################################
6+
import sys
7+
68
from ethereum import utils
79
from ethereum.abi import is_numeric
810
import copy
@@ -83,16 +85,29 @@ def __init__(self, **kwargs):
8385
# Preprocesses code, and determines which locations are in the middle
8486
# of pushdata and thus invalid
8587
def preprocess_code(code):
86-
assert isinstance(code, str)
88+
assert isinstance(code, (str, bytes))
89+
90+
# python3 does not require ord() on byte strings
91+
if sys.version_info.major == 2:
92+
if isinstance(code, bytes):
93+
code = str(code)
94+
95+
def t_ord(char):
96+
return ord(char)
97+
else:
98+
assert isinstance(code, bytes)
99+
def t_ord(char):
100+
return char
101+
87102
i = 0
88103
ops = []
89104
while i < len(code):
90-
o = copy.copy(opcodes.opcodes.get(ord(code[i]), ['INVALID', 0, 0, 0]) + [ord(code[i]), 0])
105+
o = copy.copy(opcodes.opcodes.get(t_ord(code[i]), ['INVALID', 0, 0, 0]) + [t_ord(code[i]), 0])
91106
ops.append(o)
92107
if o[0][:4] == 'PUSH':
93108
for j in range(int(o[0][4:])):
94109
i += 1
95-
byte = ord(code[i]) if i < len(code) else 0
110+
byte = t_ord(code[i]) if i < len(code) else 0
96111
o[-1] = (o[-1] << 8) + byte
97112
if i < len(code):
98113
ops.append(['INVALID', 0, 0, 0, byte, 0])

0 commit comments

Comments
 (0)