Skip to content

Commit

Permalink
Decode only ContractEmitted events from the origin contract (#380)
Browse files Browse the repository at this point in the history
* Decode only ContractEmitted events from the origin contract

* Make new argument optional
  • Loading branch information
h4nsu authored Feb 22, 2024
1 parent a95a079 commit 84485c1
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions substrateinterface/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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):
Expand All @@ -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),
Expand Down Expand Up @@ -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)

0 comments on commit 84485c1

Please sign in to comment.