Пример #1
0
 def query_unconfirmed_deposits(self):
     r = bitcoind.total_received(self.address, minconf=0)
     if r > self.least_received:
         transaction_amount = r - self.least_received
         if settings.BITCOIN_TRANSACTION_SIGNALING:
             if self.wallet:
                 balance_changed.send(sender=self.wallet, changed=(transaction_amount), bitcoinaddress=self)
         updated = BitcoinAddress.objects.select_for_update().filter(id=self.id, least_received=self.least_received).update(least_received=r)
         if updated:
             self.least_received = r
Пример #2
0
 def query_unconfirmed_deposits(self):
     r = bitcoind.total_received(self.address, minconf=0)
     if r > self.least_received:
         transaction_amount = r - self.least_received
         if settings.BITCOIN_TRANSACTION_SIGNALING:
             if self.wallet:
                 balance_changed.send(sender=self.wallet, changed=(transaction_amount), bitcoinaddress=self)
         updated = BitcoinAddress.objects.select_for_update().filter(id=self.id, least_received=self.least_received).update(least_received=r)
         if updated:
             self.least_received = r
Пример #3
0
    def query_bitcoind(self, minconf=settings.BITCOIN_MINIMUM_CONFIRMATIONS, triggered_tx=None):
        with CacheLock('query_bitcoind'):
            r = bitcoind.total_received(self.address, minconf=minconf)

            if r > self.least_received_confirmed and \
                minconf >= settings.BITCOIN_MINIMUM_CONFIRMATIONS:
                transaction_amount = r - self.least_received_confirmed
                if settings.BITCOIN_TRANSACTION_SIGNALING:
                    if self.wallet:
                        balance_changed_confirmed.send(sender=self.wallet,
                            changed=(transaction_amount), bitcoinaddress=self, txid=triggered_tx)


                updated = BitcoinAddress.objects.select_for_update().filter(id=self.id, least_received_confirmed=safe_decimal_zero(self.least_received_confirmed)).update(least_received_confirmed=r)

                if self.least_received < r:
                    BitcoinAddress.objects.select_for_update().filter(id=self.id,
                        least_received=self.least_received).update(least_received=r)

                if self.wallet and updated:
                    dps = DepositTransaction.objects.filter(address=self, transaction=None,
                        amount__lte=transaction_amount, wallet=self.wallet).order_by("-amount", "-id")
                    total_confirmed_amount = Decimal(0)
                    confirmed_dps = []
                    for dp in dps:
                        if dp.amount <= transaction_amount - total_confirmed_amount:
                            DepositTransaction.objects.filter(id=dp.id).update(confirmations=minconf)
                            total_confirmed_amount += dp.amount
                            confirmed_dps.append(dp.id)
                    if total_confirmed_amount < transaction_amount:
                        dp = DepositTransaction.objects.create(address=self, amount=transaction_amount - total_confirmed_amount, wallet=self.wallet,
                            confirmations=minconf, txid=triggered_tx)
                        confirmed_dps.append(dp.id)
                    if self.migrated_to_transactions and updated:
                        wt = WalletTransaction.objects.create(to_wallet=self.wallet, amount=transaction_amount, description=self.address,
                            deposit_address=self)
                        DepositTransaction.objects.select_for_update().filter(address=self, wallet=self.wallet,
                            id__in=confirmed_dps, transaction=None).update(transaction=wt)
                    update_wallet_balance.delay(self.wallet.id)

            elif r > self.least_received:
                transaction_amount = r - self.least_received
                if settings.BITCOIN_TRANSACTION_SIGNALING:
                    if self.wallet:
                        balance_changed.send(sender=self.wallet, changed=(transaction_amount), bitcoinaddress=self)
                # self.least_received = r
                # self.save()

                updated = BitcoinAddress.objects.select_for_update().filter(id=self.id, least_received=safe_decimal_zero(self.least_received)).update(least_received=r)
                if self.wallet and minconf==0 and updated:
                    DepositTransaction.objects.create(address=self, amount=transaction_amount, wallet=self.wallet,
                        confirmations=0, txid=triggered_tx)
            return r
Пример #4
0
    def query_bitcoin_deposit(self, deposit_tx):
        if deposit_tx.transaction:
            print "Already has a transaction!"
            return
        with CacheLock("query_bitcoind"):
            r = bitcoind.total_received(self.address, minconf=settings.BITCOIN_MINIMUM_CONFIRMATIONS)
            received_amount = r - self.least_received_confirmed

            if received_amount >= deposit_tx.amount and not deposit_tx.under_execution:
                if settings.BITCOIN_TRANSACTION_SIGNALING:
                    if self.wallet:
                        balance_changed_confirmed.send(
                            sender=self.wallet, changed=(deposit_tx.amount), bitcoinaddress=self
                        )

                updated = (
                    BitcoinAddress.objects.select_for_update()
                    .filter(id=self.id, least_received_confirmed=self.least_received_confirmed)
                    .update(least_received_confirmed=self.least_received_confirmed + deposit_tx.amount)
                )

                if self.wallet and updated:
                    DepositTransaction.objects.select_for_update().filter(id=deposit_tx.id).update(under_execution=True)
                    deposit_tx.under_execution = True
                    self.least_received_confirmed = self.least_received_confirmed + deposit_tx.amount
                    if self.least_received < self.least_received_confirmed:
                        updated = (
                            BitcoinAddress.objects.select_for_update()
                            .filter(id=self.id)
                            .update(least_received=self.least_received_confirmed)
                        )
                    if self.migrated_to_transactions:
                        wt = WalletTransaction.objects.create(
                            to_wallet=self.wallet,
                            amount=deposit_tx.amount,
                            description=self.address,
                            deposit_address=self,
                        )
                        deposit_tx.transaction = wt
                        DepositTransaction.objects.select_for_update().filter(id=deposit_tx.id).update(transaction=wt)
                    self.wallet.update_last_balance(deposit_tx.amount)
                else:
                    print "transaction not updated!"
            else:
                print "This path should not occur, but whatever."
                # raise Exception("Should be never this way")
            return r
Пример #5
0
 def query_bitcoind(self, minconf=settings.BITCOIN_MINIMUM_CONFIRMATIONS):
     r = bitcoind.total_received(self.address, minconf=minconf)
     if r > self.least_received:
         if settings.BITCOIN_TRANSACTION_SIGNALING:
             if self.wallet:
                 balance_changed.send(sender=self.wallet, changed=(r - self.least_received), bitcoinaddress=self)
         self.least_received = r
         self.save()
     if r > self.least_received_confirmed and \
         minconf >= settings.BITCOIN_MINIMUM_CONFIRMATIONS:
         if settings.BITCOIN_TRANSACTION_SIGNALING:
             if self.wallet:
                 balance_changed_confirmed.send(sender=self.wallet, 
                     changed=(r - self.least_received_confirmed), bitcoinaddress=self)
         self.least_received_confirmed = r
         self.save()
     return r
Пример #6
0
 def query_bitcoind(self, minconf=settings.BITCOIN_MINIMUM_CONFIRMATIONS):
     r = bitcoind.total_received(self.address, minconf=minconf)
     if r > self.least_received:
         if settings.BITCOIN_TRANSACTION_SIGNALING:
             if self.wallet:
                 balance_changed.send(sender=self.wallet, changed=(r - self.least_received), bitcoinaddress=self)
         # self.least_received = r
         # self.save()
         BitcoinAddress.objects.filter(id=self.id).update(least_received=r)
     if r > self.least_received_confirmed and \
         minconf >= settings.BITCOIN_MINIMUM_CONFIRMATIONS:
         if settings.BITCOIN_TRANSACTION_SIGNALING:
             if self.wallet:
                 balance_changed_confirmed.send(sender=self.wallet,
                     changed=(r - self.least_received_confirmed), bitcoinaddress=self)
         # self.least_received_confirmed = r
         # self.save()
         BitcoinAddress.objects.filter(id=self.id).update(least_received_confirmed=r)
         if self.wallet:
             Wallet.objects.filter(id=self.wallet_id).update(last_balance=self.wallet.total_balance_sql())
     return r
Пример #7
0
 def getbalance(self, minconf=1):
     return bitcoind.total_received(self.address, minconf=minconf)
Пример #8
0
 def getbalance(self, minconf=1):
     return bitcoind.total_received(self.address, minconf=minconf)