Skip to content

Commit

Permalink
Fallback for detecting successful broadcast, multiple bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
joemarct committed Jun 26, 2021
1 parent 5371cc6 commit 0ffdc3a
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 19 deletions.
2 changes: 1 addition & 1 deletion main/management/commands/bitsocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def run():
if subscription.exists():

txn_qs = Transaction.objects.filter(
address=bchaddress,
address__address=bchaddress,
txid=txn_id,
index=index
)
Expand Down
2 changes: 1 addition & 1 deletion main/management/commands/slpstream_fountainhead.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
40 changes: 23 additions & 17 deletions main/tasks.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
1 change: 1 addition & 0 deletions main/views/view_broadcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,]
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 0ffdc3a

Please sign in to comment.