diff --git a/main/models.py b/main/models.py index bb92f0b5..5e9315b7 100644 --- a/main/models.py +++ b/main/models.py @@ -35,6 +35,7 @@ def __str__(self): else: return str(self.name) + class BlockHeight(models.Model): number = models.IntegerField(default=0, unique=True, db_index=True) transactions_count = models.IntegerField(default=0) @@ -59,6 +60,7 @@ def save(self, *args, **kwargs): def __str__(self): return str(self.number) + class Transaction(models.Model): txid = models.CharField(max_length=200, db_index=True) address = models.CharField(max_length=500,null=True, db_index=True) @@ -90,6 +92,7 @@ class Transaction(models.Model): def __str__(self): return self.txid + class Recipient(models.Model): web_url = models.CharField(max_length=500,null=True, blank=True) telegram_id = models.CharField(max_length=100,null=True, blank=True) @@ -103,6 +106,7 @@ def __str__(self): else: return 'N/A' + class SlpAddress(models.Model): address = models.CharField(max_length=200, unique=True, db_index=True) transactions = models.ManyToManyField( @@ -118,6 +122,7 @@ class Meta: def __str__(self): return self.address + class BchAddress(models.Model): address = models.CharField(max_length=200, unique=True, db_index=True) transactions = models.ManyToManyField( @@ -134,6 +139,7 @@ class Meta: def __str__(self): return self.address + class Subscription(models.Model): recipient = models.ForeignKey( Recipient, diff --git a/main/signals.py b/main/signals.py index 70e72f48..2469e858 100644 --- a/main/signals.py +++ b/main/signals.py @@ -3,7 +3,9 @@ from main.tasks import ( save_record, slpdbquery_transaction, - bitdbquery_transaction + bitdbquery_transaction, + client_acknowledgement, + send_telegram_message ) from django.dispatch import receiver from rest_framework.authtoken.models import Token @@ -83,7 +85,14 @@ def transaction_post_save(sender, instance=None, created=False, **kwargs): blockheight_id, tx_output['index'] ) - save_record(*args) + obj_id, created = save_record(*args) + if created: + third_parties = client_acknowledgement(obj_id) + for platform in third_parties: + if 'telegram' in platform: + message = platform[1] + chat_id = platform[2] + send_telegram_message(message, chat_id) elif instance.address.startswith('simpleledger:'): # Make sure that any corresponding BCH transaction is saved @@ -118,4 +127,11 @@ def transaction_post_save(sender, instance=None, created=False, **kwargs): blockheight_id, tx_output['index'] ) - save_record(*args) + obj_id, created = save_record(*args) + if created: + third_parties = client_acknowledgement(obj_id) + for platform in third_parties: + if 'telegram' in platform: + message = platform[1] + chat_id = platform[2] + send_telegram_message(message, chat_id) diff --git a/main/tasks.py b/main/tasks.py index 8d55134e..1a38f7aa 100644 --- a/main/tasks.py +++ b/main/tasks.py @@ -288,8 +288,7 @@ def bitdbquery_transaction(self, transaction, total, block_number, block_id, ale index= _in['e']['i'] input_scanner(txid, index, block_id=block_id) - - + @shared_task(bind=True, queue='bitdbquery', max_retries=30) def bitdbquery(self, block_id): try: @@ -356,6 +355,7 @@ def bitdbquery(self, block_id): REDIS_STORAGE.set('PENDING-BLOCKS', json.dumps(pending_blocks)) REDIS_STORAGE.set('READY', 1) + @shared_task(bind=True, queue='slpdbquery_transactions') def slpdbquery_transaction(self, transaction, tx_count, total, alert=True): source = 'slpdb-query' @@ -474,6 +474,7 @@ def manage_block_transactions(self): active_block = str(REDIS_STORAGE.get('ACTIVE-BLOCK')) if active_block: return f'REDIS IS TOO BUSY FOR BLOCK {str(active_block)}.' + @shared_task(bind=True, queue='get_latest_block') def get_latest_block(self): # This task is intended to check new blockheight every 5 seconds through BitDB Query