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

Commit 97b4a6e

Browse files
committed
Merge pull request #253 from BlockchainSociety/develop
update strings formatting to be python3 friendly
2 parents 0484f38 + b90a503 commit 97b4a6e

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

ethereum/blocks.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -339,10 +339,10 @@ def check_pow(self, nonce=None, debugmode=False):
339339
mining_output = hashimoto_light(current_full_size, cache, header_hash, nonce)
340340
diff = self.difficulty
341341
if debugmode:
342-
print 'Mining hash: %s' % encode_hex(header_hash)
343-
print 'Seed: %s' % encode_hex(seed)
344-
print 'Mixhash: %s' % encode_hex(mining_output['mix digest'])
345-
print 'Result: %s' % encode_hex(mining_output['result'])
342+
print('Mining hash: {}'.format(encode_hex(header_hash)))
343+
print('Seed: {}'.format(encode_hex(seed)))
344+
print('Mixhash: {}'.format(encode_hex(mining_output['mix digest'])))
345+
print('Result: {}'.format(encode_hex(mining_output['result'])))
346346
if mining_output['mix digest'] != self.mixhash:
347347
return False
348348
return utils.big_endian_to_int(mining_output['result']) <= 2**256 / (diff or 1)
@@ -492,7 +492,7 @@ def __init__(self, header, transaction_list=[], uncles=[], db=None,
492492
state_unknown = (header.prevhash != GENESIS_PREVHASH and
493493
header.state_root != trie.BLANK_ROOT and
494494
(len(header.state_root) != 32 or
495-
'validated:' + self.hash not in db) and
495+
b'validated:' + self.hash not in db) and
496496
not making)
497497
if state_unknown:
498498
assert transaction_list is not None
@@ -566,7 +566,7 @@ def must_le(what, a, b):
566566
"database" % self)
567567
if (not self.is_genesis() and self.nonce and not self.header.check_pow()):
568568
raise ValueError("PoW check failed")
569-
self.db.put('validated:' + self.hash, '1')
569+
self.db.put(b'validated:' + self.hash, '1')
570570

571571
@classmethod
572572
def init_from_header(cls, header_rlp, db):

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)