Beispiel #1
0
def process_in_crypto(Time, CurrencyTitle):
    
        Crypton = CryptoAccount(CurrencyTitle, "trade_stock")
        List = Crypton.listtransactions()
        user_system =   User.objects.get(id = 1)
        CurrencyInstance = Currency.objects.get(title = CurrencyTitle)
        getcontext().prec = crypton.settings.TRANS_PREC
        for trans in List :
                Txid = trans["txid"]
#		print "receive transactions %s" % (str(trans))
                if not trans.has_key("blocktime") or  trans["blocktime"]<Time:
#			print "old transactions ";
                        continue
		#if trans["amount"]<0.0001:
		#	continue  
                if trans["category"] == "receive":
                        Account  = None
                        Trans = None
                        Decimal = format_numbers_strong(trans["amount"])

                        try :
                               Account = PoolAccounts.objects.filter(address = trans["address"], currency = CurrencyInstance )
   
                               Trans = CryptoTransfers.objects.get(crypto_txid = Txid, currency = CurrencyInstance )  
                        except Accounts.DoesNotExist:
                               notify_admin_withdraw(u"unrecognized crypto incoming to %s %s %s" % (trans["address"],
                                                                                                     Decimal,
                                                                                                     CurrencyTitle
                                                                                                     ) ) 
                               continue
                        except  CryptoTransfers.DoesNotExist:
                                
                               if Account is not None:
                                        
                                        Trans =  CryptoTransfers(crypto_txid = Txid,
                                                                        status="created",
                                                                        amnt = Decimal,
                                                                        currency = CurrencyInstance ,
                                                                        account = trans["address"],
                                                                        user = Account.user,
                                                                        confirms = 0
                                                                        )
                                        Trans.save()
                
                        print "#%i receive %s to %s amount of %s" % (Trans.id, Txid, trans["address"], Trans.amnt )
                        print "confirmations %i" % (trans["confirmations"] )                        
                        print "this trans is %s" % (Trans.status)
                        if (Trans.status == "processing" or Trans.status == "created" ) and trans["confirmations"] > CryptoSettings["BTC"]["min_confirmation"]:
                                print "processing it %s" % (str(trans))
                                Trans.confirms = int(trans["confirmations"])
                                Trans.status = "processing"
                                Trans.save()
#				print "in in"
                                crypton_in(Trans, user_system)
                                
                        if Trans.status == "processing" or Trans.status == "created":     
 #                               print "update confirmations"
                                Trans.status = "processing"
                                Trans.confirms = int(trans["confirmations"])
                                Trans.save()
Beispiel #2
0
def process_in_crypto(Time, CurrencyTitle):
    Crypton = CryptoAccount(CurrencyTitle, "trade_stock")
    List = Crypton.listtransactions()
    user_system = User.objects.get(id=1)
    CurrencyInstance = Currency.objects.get(title=CurrencyTitle)
    getcontext().prec = crypton.settings.TRANS_PREC
    for trans in List:
        Txid = trans["txid"]
        if trans.has_key("blocktime") and trans["blocktime"] < Time:
            print "old transactions ";
            print "blocktime is %i " % trans["blocktime"]
            continue

        if trans["category"] == "receive":
            Account = None
            Trans = None
        New = False
        Decimal = format_numbers_strong(trans["amount"])
        try:
            Account = Accounts.objects.get(reference=trans["address"])
            Trans = CryptoTransfers.objects.get(crypto_txid=Txid, currency=CurrencyInstance)
        except Accounts.DoesNotExist:
            continue
        except CryptoTransfers.DoesNotExist:
            Trans = CryptoTransfers(crypto_txid=Txid,
                                    status="created",
                                    amnt=Decimal,
                                    currency=CurrencyInstance,
                                    account=trans["address"],
                                    user=Account.user,
                                    confirms=0)
            Trans.save()
        print "in one trans to our accounts"
        print "#%i receive %s to %s amount of %s" % (Trans.id, Txid, trans["address"], trans['amount'] )
        print "confirmations %i" % (trans["confirmations"] )
        print "this trans is %s" % (Trans.status)
        if (Trans.status == "processing" or Trans.status == "created")\
            and trans["confirmations"] > CryptoSettings[CurrencyTitle]["min_confirmation"] :
            print "processing it %s" % (str(trans))
            Trans.confirms = int(trans["confirmations"])
            Trans.status = "processing"
            Trans.save()
            crypton_in(Trans, user_system)

    if Trans.status == "processing" or Trans.status == "created":
        Trans.status = "processing"
        Trans.confirms = int(trans["confirmations"])
        Trans.save()
def process_block_info(Time):
    user_system = User.objects.get(id=1)
    CurrencyInstance = Currency.objects.get(title="BTC")
    getcontext().prec = crypton.settings.TRANS_PREC
    LastBlock = get_last_block()
    print "current block height is %i " % (LastBlock)
    AccountList = Accounts.objects.filter(currency=CurrencyInstance).order_by('balance')
    OwnAccounts = {}
    for i in AccountList:
        OwnAccounts[i.reference] = 1

    for Account in AccountList:
        Address = Account.reference
        if Address is None:
            continue

        print "process adress %s" % (Address)

        try:
            TransList = get_adress_list(Address)
        except:
            print "get error during processing the "
            continue

        for trans in TransList:
            Txid = trans["hash"]
            print "find trans %s for %s " % (Txid, Address )

            if trans["time"] < Time:
                print "this trans is old"
                continue

            print str(trans)

            try:
                Confirmations = LastBlock - trans["block_height"] + 1
            except:
                continue

            if is_out(trans["inputs"], OwnAccounts):
                print "it is out trans for us %s" % (Txid)
                continue

            try:
                Decimal = get_in_acc(trans["out"], Address)
            except:
                print "get error during processing the "
                continue

            if Decimal == 0:
                print "it is out trans for %s " % (Address)
                continue

            Trans = None
            print "confirmations %i" % ( Confirmations )
            print " amount of %s" % (Decimal )

            try:
                Trans = CryptoTransfers.objects.get(crypto_txid=Txid)
            except  CryptoTransfers.DoesNotExist:
                Trans = CryptoTransfers(crypto_txid=Txid,
                                        status="created",
                                        amnt=Decimal,
                                        currency=CurrencyInstance,
                                        account=Address,
                                        user=Account.user,
                                        confirms=Confirmations
                )
                Trans.save()

            print "#%i receive %s to %s amount of %s" % (Trans.id, Txid, Address, Trans.amnt )
            print "this trans is %s" % ( Trans.status )
            continue
            if Confirmations > CryptoSettings["BTC"]["min_confirmation"] and Trans.status != "processed":
                print "processing it"
                Trans.confirms = Confirmations
                Trans.status = "processing"
                Trans.save()
                crypton_in(Trans, user_system)
                Trans.status = "processed"
                Trans.save()

            if Trans.status == "processing" or Trans.status == "created":
                print "update confirmations"
                Trans.status = "processing"
                Trans.confirms = Confirmations
                Trans.save()