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

Commit 79e78c3

Browse files
authored
Merge pull request #354 from ethereum/fix_lazy_encoding_352
Failsafe lazy encode
2 parents 51c77db + 5a0c9f4 commit 79e78c3

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

ethereum/blocks.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import time
77
from itertools import count
88
import sys
9+
from collections import Iterable
910
import rlp
1011
from rlp.sedes import big_endian_int, Binary, binary, CountableList
1112
from rlp.utils import decode_hex, encode_hex
@@ -38,8 +39,21 @@ class lazy_encode(object):
3839
def __init__(self, data):
3940
self.data = data
4041

42+
def encode_entry(self, entry):
43+
assert isinstance(entry, Iterable)
44+
if len(entry) == 3:
45+
name, addr, v = entry
46+
if name == 'code':
47+
return [name, encode_hex(addr), encode_hex(v)]
48+
else:
49+
return [name, encode_hex(addr), v]
50+
elif len(entry) == 4:
51+
name, addr, k, v = entry
52+
return [name, encode_hex(addr), encode_hex(k), encode_hex(v)]
53+
assert False, ("unexpected entry format", entry)
54+
4155
def __repr__(self):
42-
return repr([[k, encode_hex(a), v if k != 'code' else encode_hex(v)] for k, a, v in self.data])
56+
return repr([self.encode_entry(entry) for entry in self.data])
4357

4458
def __str__(self):
4559
return str(repr(self))

0 commit comments

Comments
 (0)