diff --git a/main/management/commands/bitsocket.py b/main/management/commands/bitsocket.py index c738be1d..414b3538 100644 --- a/main/management/commands/bitsocket.py +++ b/main/management/commands/bitsocket.py @@ -71,7 +71,7 @@ def run(): if subscription.exists(): txn_qs = Transaction.objects.filter( - address=bchaddress, + address__address=bchaddress, txid=txn_id, index=index ) diff --git a/main/management/commands/slpstream_fountainhead.py b/main/management/commands/slpstream_fountainhead.py index f93bc7dd..808b099b 100644 --- a/main/management/commands/slpstream_fountainhead.py +++ b/main/management/commands/slpstream_fountainhead.py @@ -68,7 +68,7 @@ def run(): amount = amount / (10 ** token.decimals) txn_id = info['tx']['h'] txn_qs = Transaction.objects.filter( - address=slp_address, + address__address=slp_address, txid=txn_id, index=index ) diff --git a/main/tasks.py b/main/tasks.py index a64e23b3..6216f5ec 100644 --- a/main/tasks.py +++ b/main/tasks.py @@ -1,5 +1,6 @@ import math, logging, json, time, requests from watchtower.settings import MAX_RESTB_RETRIES +from bitcash.transaction import calc_txid from celery import shared_task from main.models import ( BlockHeight, @@ -510,7 +511,7 @@ def get_bch_utxos(self, address): block, created = BlockHeight.objects.get_or_create(number=block) transaction_obj = Transaction.objects.filter( txid=tx_hash, - address=address, + address__address=address, amount=amount, index=index ) @@ -542,7 +543,7 @@ def get_bch_utxos(self, address): # Mark other transactions of the same address as spent txn_check = Transaction.objects.filter( - address=address, + address__address=address, spent=False ).exclude( id__in=saved_utxo_ids @@ -580,7 +581,7 @@ def get_slp_utxos(self, address): transaction_obj = Transaction.objects.filter( txid=tx_hash, - address=address, + address__address=address, token=token_obj, amount=amount, index=index @@ -613,7 +614,7 @@ def get_slp_utxos(self, address): # Mark other transactions of the same address as spent txn_check = Transaction.objects.filter( - address=address, + address__address=address, spent=False ).exclude( id__in=saved_utxo_ids @@ -652,18 +653,23 @@ def get_token_meta_data(self, token_id): self.retry(countdown=5) -@shared_task(bind=True, queue='broadcast', max_retries=5) +@shared_task(bind=True, queue='broadcast', max_retries=10) def broadcast_transaction(self, transaction): - try: - obj = BCHDQuery() + txid = calc_txid(transaction) + txn_check = Transaction.objects.filter(txid=txid) + if txn_check.exists(): + return True, txid + else: try: - txid = obj.broadcast_transaction(transaction) - if txid: - return True, txid - else: - self.retry(countdown=1) - except Exception as exc: - error = exc.details() - return False, error - except AttributeError: - self.retry(countdown=1) + obj = BCHDQuery() + try: + txid = obj.broadcast_transaction(transaction) + if txid: + return True, txid + else: + self.retry(countdown=1) + except Exception as exc: + error = exc.details() + return False, error + except AttributeError: + self.retry(countdown=1) diff --git a/main/views/view_broadcast.py b/main/views/view_broadcast.py index ae98d393..8f46bc5a 100644 --- a/main/views/view_broadcast.py +++ b/main/views/view_broadcast.py @@ -5,6 +5,7 @@ from main import serializers from main.tasks import broadcast_transaction + class BroadcastViewSet(generics.GenericAPIView): serializer_class = serializers.BroadcastSerializer permission_classes = [AllowAny,] diff --git a/requirements.txt b/requirements.txt index 3608fe15..10e6e642 100644 --- a/requirements.txt +++ b/requirements.txt @@ -6,6 +6,7 @@ atomicwrites==1.4.0 attrs==20.1.0 backcall==0.1.0 billiard==3.6.2.0 +BitCash==0.6.4 celery==4.4.0 certifi==2019.11.28 chardet==3.0.4