Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Uxio0 committed Dec 18, 2023
1 parent 6280f19 commit f8857a3
Showing 1 changed file with 58 additions and 28 deletions.
86 changes: 58 additions & 28 deletions safe_transaction_service/history/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Type, Union

from django.db.models import Model
from django.db.models.signals import post_save
from django.db.models.signals import post_delete, post_save
from django.dispatch import receiver
from django.utils import timezone

Expand Down Expand Up @@ -112,30 +112,7 @@ def safe_master_copy_clear_cache(
SafeMasterCopy.objects.get_version_for_address.cache_clear()


@receiver(
post_save,
sender=ModuleTransaction,
dispatch_uid="module_transaction.process_webhook",
)
@receiver(
post_save,
sender=MultisigConfirmation,
dispatch_uid="multisig_confirmation.process_webhook",
)
@receiver(
post_save,
sender=MultisigTransaction,
dispatch_uid="multisig_transaction.process_webhook",
)
@receiver(
post_save, sender=ERC20Transfer, dispatch_uid="erc20_transfer.process_webhook"
)
@receiver(
post_save, sender=ERC721Transfer, dispatch_uid="erc721_transfer.process_webhook"
)
@receiver(post_save, sender=InternalTx, dispatch_uid="internal_tx.process_webhook")
@receiver(post_save, sender=SafeContract, dispatch_uid="safe_contract.process_webhook")
def process_webhook(
def _process_webhook(
sender: Type[Model],
instance: Union[
TokenTransfer,
Expand All @@ -145,10 +122,14 @@ def process_webhook(
SafeContract,
],
created: bool,
**kwargs,
) -> None:
deleted: bool,
):
assert not (
created and deleted
), "A instance cannot be created and deleted at the same time"

logger.debug("Start building payloads for created=%s object=%s", created, instance)
payloads = build_webhook_payload(sender, instance)
payloads = build_webhook_payload(sender, instance, deleted=deleted)
logger.debug(
"End building payloads %s for created=%s object=%s", payloads, created, instance
)
Expand Down Expand Up @@ -177,6 +158,55 @@ def process_webhook(
)


@receiver(
post_save,
sender=ModuleTransaction,
dispatch_uid="module_transaction.process_webhook",
)
@receiver(
post_save,
sender=MultisigConfirmation,
dispatch_uid="multisig_confirmation.process_webhook",
)
@receiver(
post_save,
sender=MultisigTransaction,
dispatch_uid="multisig_transaction.process_webhook",
)
@receiver(
post_save, sender=ERC20Transfer, dispatch_uid="erc20_transfer.process_webhook"
)
@receiver(
post_save, sender=ERC721Transfer, dispatch_uid="erc721_transfer.process_webhook"
)
@receiver(post_save, sender=InternalTx, dispatch_uid="internal_tx.process_webhook")
@receiver(post_save, sender=SafeContract, dispatch_uid="safe_contract.process_webhook")
def process_webhook(
sender: Type[Model],
instance: Union[
TokenTransfer,
InternalTx,
MultisigConfirmation,
MultisigTransaction,
SafeContract,
],
created: bool,
**kwargs,
) -> None:
return _process_webhook(sender, instance, created, False)


@receiver(
post_delete,
sender=MultisigTransaction,
dispatch_uid="multisig_transaction.process_delete_webhook",
)
def process_delete_webhook(
sender: Type[Model], instance: MultisigTransaction, *args, **kwargs
):
return _process_webhook(sender, instance, False, True)


@receiver(
post_save,
sender=SafeLastStatus,
Expand Down

0 comments on commit f8857a3

Please sign in to comment.