From 84485c1f7774016ed2f93380b3a6ec041c28b2c1 Mon Sep 17 00:00:00 2001 From: Michal Handzlik Date: Thu, 22 Feb 2024 16:24:28 +0100 Subject: [PATCH] Decode only ContractEmitted events from the origin contract (#380) * Decode only ContractEmitted events from the origin contract * Make new argument optional --- substrateinterface/contracts.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/substrateinterface/contracts.py b/substrateinterface/contracts.py index 89425e3..14945d4 100644 --- a/substrateinterface/contracts.py +++ b/substrateinterface/contracts.py @@ -446,11 +446,12 @@ def __init__(self, *args, **kwargs): """ self.__contract_events = None self.contract_metadata = kwargs.pop('contract_metadata') + self.contract_address = kwargs.pop('contract_address') super(ContractExecutionReceipt, self).__init__(*args, **kwargs) @classmethod def create_from_extrinsic_receipt(cls, receipt: ExtrinsicReceipt, - contract_metadata: ContractMetadata) -> "ContractExecutionReceipt": + contract_metadata: ContractMetadata, contract_address: str = None) -> "ContractExecutionReceipt": """ Promotes a ExtrinsicReceipt object to a ContractExecutionReceipt. It uses the provided ContractMetadata to decode "ContractExecution" events @@ -469,7 +470,8 @@ def create_from_extrinsic_receipt(cls, receipt: ExtrinsicReceipt, extrinsic_hash=receipt.extrinsic_hash, block_hash=receipt.block_hash, finalized=receipt.finalized, - contract_metadata=contract_metadata + contract_metadata=contract_metadata, + contract_address=contract_address ) def process_events(self): @@ -482,7 +484,7 @@ def process_events(self): for event in self.triggered_events: if self.substrate.implements_scaleinfo(): - if event.value['module_id'] == 'Contracts' and event.value['event_id'] == 'ContractEmitted': + if event.value['module_id'] == 'Contracts' and event.value['event_id'] == 'ContractEmitted' and event.value['attributes']['contract'] == self.contract_address: # Create contract event contract_event_obj = ContractEvent( data=ScaleBytes(event['event'][1][1]['data'].value_object), @@ -855,4 +857,4 @@ def exec(self, keypair: Keypair, method: str, args: dict = None, extrinsic, wait_for_inclusion=wait_for_inclusion, wait_for_finalization=wait_for_finalization ) - return ContractExecutionReceipt.create_from_extrinsic_receipt(receipt, self.metadata) + return ContractExecutionReceipt.create_from_extrinsic_receipt(receipt, self.metadata, self.contract_address)