@@ -397,23 +397,29 @@ def __init__(self, contract_interface):
397
397
if is_string (contract_interface ):
398
398
contract_interface = json_decode (contract_interface )
399
399
400
+ self .fallback_data = None
400
401
self .constructor_data = None
401
402
self .function_data = {}
402
403
self .event_data = {}
403
404
404
405
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' :
417
423
normalized_name = normalize_name (description ['name' ])
418
424
419
425
decode_types = [
@@ -427,9 +433,10 @@ def __init__(self, contract_interface):
427
433
'decode_types' : decode_types ,
428
434
'is_constant' : description .get ('constant' , False ),
429
435
'signature' : signature ,
436
+ 'payable' : description .get ('payable' , False ),
430
437
}
431
438
432
- elif description [ 'type' ] == 'event' :
439
+ elif entry_type == 'event' :
433
440
normalized_name = normalize_name (description ['name' ])
434
441
435
442
indexed = [
@@ -449,7 +456,7 @@ def __init__(self, contract_interface):
449
456
'anonymous' : description .get ('anonymous' , False ),
450
457
}
451
458
452
- elif description [ 'type' ] == 'constructor' :
459
+ elif entry_type == 'constructor' :
453
460
if self .constructor_data is not None :
454
461
raise ValueError ('Only one constructor is supported.' )
455
462
@@ -458,6 +465,11 @@ def __init__(self, contract_interface):
458
465
'signature' : signature ,
459
466
}
460
467
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
+
461
473
else :
462
474
raise ValueError ('Unknown type {}' .format (description ['type' ]))
463
475
@@ -530,7 +542,7 @@ def decode_event(self, log_topics, log_data):
530
542
# topics[0]: keccak(EVENT_NAME+"("+EVENT_ARGS.map(canonical_type_of).join(",")+")")
531
543
# If the event is declared as anonymous the topics[0] is not generated;
532
544
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' )
534
546
535
547
event_id_ = log_topics [0 ]
536
548
0 commit comments