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

Commit 584c0ba

Browse files
authored
Merge pull request #408 from LefterisJP/solc_v40
Make solc wrapper solidity v4.0 compatible
2 parents 085ce48 + 91f385e commit 584c0ba

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

ethereum/abi.py

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -397,23 +397,29 @@ def __init__(self, contract_interface):
397397
if is_string(contract_interface):
398398
contract_interface = json_decode(contract_interface)
399399

400+
self.fallback_data = None
400401
self.constructor_data = None
401402
self.function_data = {}
402403
self.event_data = {}
403404

404405
for description in contract_interface:
405-
encode_types = [
406-
element['type']
407-
for element in description['inputs']
408-
]
409-
410-
signature = [
411-
(element['type'], element['name'])
412-
for element in description['inputs']
413-
]
414-
415-
# type can be omitted, defaulting to function
416-
if description.get('type', 'function') == 'function':
406+
entry_type = description.get('type', 'function')
407+
encode_types = []
408+
signature = []
409+
410+
# If it's a function/constructor/event
411+
if entry_type != 'fallback' and 'inputs' in description:
412+
encode_types = [
413+
element['type']
414+
for element in description.get('inputs')
415+
]
416+
417+
signature = [
418+
(element['type'], element['name'])
419+
for element in description.get('inputs')
420+
]
421+
422+
if entry_type == 'function':
417423
normalized_name = normalize_name(description['name'])
418424

419425
decode_types = [
@@ -427,9 +433,10 @@ def __init__(self, contract_interface):
427433
'decode_types': decode_types,
428434
'is_constant': description.get('constant', False),
429435
'signature': signature,
436+
'payable': description.get('payable', False),
430437
}
431438

432-
elif description['type'] == 'event':
439+
elif entry_type == 'event':
433440
normalized_name = normalize_name(description['name'])
434441

435442
indexed = [
@@ -449,7 +456,7 @@ def __init__(self, contract_interface):
449456
'anonymous': description.get('anonymous', False),
450457
}
451458

452-
elif description['type'] == 'constructor':
459+
elif entry_type == 'constructor':
453460
if self.constructor_data is not None:
454461
raise ValueError('Only one constructor is supported.')
455462

@@ -458,6 +465,11 @@ def __init__(self, contract_interface):
458465
'signature': signature,
459466
}
460467

468+
elif entry_type == 'fallback':
469+
if self.fallback_data is not None:
470+
raise ValueError('Only one fallback function is supported.')
471+
self.fallback_data = {'payable': description['payable']}
472+
461473
else:
462474
raise ValueError('Unknown type {}'.format(description['type']))
463475

@@ -530,7 +542,7 @@ def decode_event(self, log_topics, log_data):
530542
# topics[0]: keccak(EVENT_NAME+"("+EVENT_ARGS.map(canonical_type_of).join(",")+")")
531543
# If the event is declared as anonymous the topics[0] is not generated;
532544
if not len(log_topics) or log_topics[0] not in self.event_data:
533-
raise ValueError('Unknow log type')
545+
raise ValueError('Unknown log type')
534546

535547
event_id_ = log_topics[0]
536548

0 commit comments

Comments
 (0)