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

Commit 679c564

Browse files
committed
use byte strings
1 parent 6690191 commit 679c564

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

ethereum/abi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ def encode_single(typ, arg):
344344
return zpad(arg, 32)
345345
elif len(arg) == 40:
346346
return zpad(decode_hex(arg), 32)
347-
elif len(arg) == 42 and arg[:2] == '0x':
347+
elif len(arg) == 42 and arg[:2] in {'0x', b'0x'}:
348348
return zpad(decode_hex(arg[2:]), 32)
349349
else:
350350
raise EncodingError("Could not parse address: %r" % arg)

ethereum/blocks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -794,7 +794,7 @@ def _delta_item(self, address, param, value):
794794
def mk_transaction_receipt(self, tx):
795795
"""Create a receipt for a transaction."""
796796
if self.number >= self.config["METROPOLIS_FORK_BLKNUM"]:
797-
return Receipt('\x00' * 32, self.gas_used, self.logs)
797+
return Receipt(b'\x00' * 32, self.gas_used, self.logs)
798798
else:
799799
return Receipt(self.state_root, self.gas_used, self.logs)
800800

@@ -984,7 +984,7 @@ def get_storage_bytes(self, address, index):
984984
if storage:
985985
return rlp.decode(storage)
986986
else:
987-
return ''
987+
return b''
988988

989989
def get_storage_data(self, address, index):
990990
bytez = self.get_storage_bytes(address, index)

ethereum/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def sha3(seed):
117117
sha3_count[0] += 1
118118
return sha3_256(to_string(seed))
119119

120-
assert encode_hex(sha3('')) == b'c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470'
120+
assert encode_hex(sha3(b'')) == b'c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470'
121121

122122

123123
def privtoaddr(x, extended=False):
@@ -145,9 +145,9 @@ def check_and_strip_checksum(x):
145145
def normalize_address(x, allow_blank=False):
146146
if is_numeric(x):
147147
return int_to_addr(x)
148-
if allow_blank and (x == '' or x == b''):
148+
if allow_blank and x in {'', b''}:
149149
return b''
150-
if len(x) in (42, 50) and x[:2] == '0x':
150+
if len(x) in (42, 50) and x[:2] in {'0x', b'0x'}:
151151
x = x[2:]
152152
if len(x) in (40, 48):
153153
x = decode_hex(x)
@@ -171,7 +171,7 @@ def zunpad(x):
171171

172172

173173
def int_to_addr(x):
174-
o = [''] * 20
174+
o = [b''] * 20
175175
for i in range(20):
176176
o[19 - i] = ascii_chr(x & 0xff)
177177
x >>= 8

ethereum/vm.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ def vm_execute(ext, msg, code):
482482
if compustate.gas < gas_payment:
483483
return vm_exception('OUT OF GAS')
484484
compustate.gas -= gas_payment
485-
data = ''.join(map(chr, mem[mstart: mstart + msize]))
485+
data = b''.join(map(chr, mem[mstart: mstart + msize]))
486486
ext.set_storage_data(msg.to, data)
487487
ext.add_refund(refund)
488488
elif op == 'SSIZE':

0 commit comments

Comments
 (0)