What I would like to do in psuedo code is:
def import_transaction_deposit_crypto(Importer):
logger = get_nexchange_logger(__name__, True, True)
existent_addresses = Address.objects.filter(
currency__is_crypto=True,
type=Address.DEPOSIT,
currency__wallet__in=Importer.RELATED_NODES
).tx_to_set.count()
Example value of importer:
class LitecoinTxImporter:
RELATED_NODES = 'ltc_rpc_1'
tx_to
is a related_field (reverse relation):
class Address(BtcBase, SoftDeletableModel):
address_to = models.ForeignKey('core.Address',
related_name='txs_to')
The idea is to count all 'already imported' transactions that belong to a specific RPC node (wallet), in order to feed it to the from
parameter of the listtransactions
RPC endpoint (generally speaking, for pagination purposes).
This is documented here with a perfectly matching example:
# Build an annotated queryset
>>> from django.db.models import Count
>>> q = Book.objects.annotate(Count('authors'))
# Interrogate the first object in the queryset
>>> q[0]
<Book: The Definitive Guide to Django>
>>> q[0].authors__count
2
You could start the filtering from Address
:
Adress.objects.filter(address_to__curency__is_crpyto=True, ...).count()