@@ -677,6 +677,17 @@ async def _on_head_message(self, message: List[Dict[str, Any]]) -> None:
677677 @classmethod
678678 def convert_operation (cls , operation_json : Dict [str , Any ], type_ : Optional [str ] = None ) -> OperationData :
679679 """Convert raw operation message from WS/REST into dataclass"""
680+ sender_json = operation_json .get ('sender' ) or {}
681+ target_json = operation_json .get ('target' ) or {}
682+ initiator_json = operation_json .get ('initiator' ) or {}
683+ parameter_json = operation_json .get ('parameter' ) or {}
684+ originated_contract_json = operation_json .get ('originatedContract' ) or {}
685+
686+ entrypoint , parameter = parameter_json .get ('entrypoint' ), parameter_json .get ('value' )
687+ # NOTE: TzKT returns None for `default` entrypoint
688+ if entrypoint is None and parameter_json :
689+ entrypoint = 'default'
690+
680691 return OperationData (
681692 type = type_ or operation_json ['type' ],
682693 id = operation_json ['id' ],
@@ -685,27 +696,21 @@ def convert_operation(cls, operation_json: Dict[str, Any], type_: Optional[str]
685696 block = operation_json .get ('block' ),
686697 hash = operation_json ['hash' ],
687698 counter = operation_json ['counter' ],
688- sender_address = operation_json [ 'sender' ][ 'address' ] if operation_json .get ('sender' ) else None ,
689- target_address = operation_json [ 'target' ][ 'address' ] if operation_json .get ('target' ) else None ,
690- initiator_address = operation_json [ 'initiator' ][ 'address' ] if operation_json .get ('initiator' ) else None ,
699+ sender_address = sender_json .get ('address' ) ,
700+ target_address = target_json .get ('address' ) ,
701+ initiator_address = initiator_json .get ('address' ) ,
691702 amount = operation_json .get ('amount' ) or operation_json .get ('contractBalance' ),
692703 status = operation_json ['status' ],
693704 has_internals = operation_json .get ('hasInternals' ),
694705 sender_alias = operation_json ['sender' ].get ('alias' ),
695706 nonce = operation_json .get ('nonce' ),
696- target_alias = operation_json ['target' ].get ('alias' ) if operation_json .get ('target' ) else None ,
697- initiator_alias = operation_json ['initiator' ].get ('alias' ) if operation_json .get ('initiator' ) else None ,
698- entrypoint = operation_json ['parameter' ].get ('entrypoint' ) if operation_json .get ('parameter' ) else None ,
699- parameter_json = operation_json ['parameter' ].get ('value' ) if operation_json .get ('parameter' ) else None ,
700- originated_contract_address = operation_json ['originatedContract' ]['address' ]
701- if operation_json .get ('originatedContract' )
702- else None ,
703- originated_contract_type_hash = operation_json ['originatedContract' ]['typeHash' ]
704- if operation_json .get ('originatedContract' )
705- else None ,
706- originated_contract_code_hash = operation_json ['originatedContract' ]['codeHash' ]
707- if operation_json .get ('originatedContract' )
708- else None ,
707+ target_alias = target_json .get ('alias' ),
708+ initiator_alias = initiator_json .get ('alias' ),
709+ entrypoint = entrypoint ,
710+ parameter_json = parameter ,
711+ originated_contract_address = originated_contract_json .get ('address' ),
712+ originated_contract_type_hash = originated_contract_json .get ('typeHash' ),
713+ originated_contract_code_hash = originated_contract_json .get ('codeHash' ),
709714 storage = operation_json .get ('storage' ),
710715 diffs = operation_json .get ('diffs' ) or (),
711716 )
0 commit comments