Пример #1
0
    def handle(self, *args, **options):
        import blockchain

        blockchain.util.TIMEOUT = 60
        Last = None
        CurrencyInstance = Currency.objects.get(title="BTC")
        AccountList = PoolAccounts.objects.filter(currency_id=2)
        OwnAccounts = {}
        print "get all addresses"
        for i in AccountList:
            if i.address == '' or i.address is None or i.user is None:
                continue
            OwnAccounts[i.address] = i.user

        while True:
            try:
                Last = VolatileConsts.objects.get(Name="last_btc_process_block")
            except:
                print "there is no previouse info"
                sys.exit(0)

            PrevValue = int(Last.Value)
            time.sleep(1)
            NewBlock = PrevValue + 1
            LatestBlock = blockexplorer.get_latest_block()
            print "start process new block %i %i" % (NewBlock, LatestBlock.height)

            if LatestBlock.height == NewBlock or LatestBlock.height < NewBlock:
                print "there is uncofirmed block do nothing"
                sys.exit(0)
                # try:
            for Block in blockexplorer.get_block_height(NewBlock):
                for Trans in Block.transactions:
                    for output in Trans.outputs:
                        if OwnAccounts.has_key(output.address):
                            if is_out(Trans.inputs, OwnAccounts):
                                break
                            else:
                                Decimal = sato2Dec(output.value)
                                try:
                                    TransObj = CryptoTransfers.objects.get(crypto_txid=Trans.hash)
                                    print "trans %s is existed to %s  amnt %s %i" % (
                                    TransObj.crypto_txid, TransObj.user.username, TransObj.amnt, TransObj.id)
                                except  CryptoTransfers.DoesNotExist:
                                    print "trans %s  to save  %s  amnt %s" % (Trans.hash, output.address, Decimal)
                                    TransObj = CryptoTransfers(crypto_txid=Trans.hash,
                                                               status="processing",
                                                               amnt=Decimal,
                                                               currency=CurrencyInstance,
                                                               account=output.address,
                                                               user=OwnAccounts[output.address],
                                                               confirms=0
                                    )
                                    TransObj.sign_record(crypton.settings.CRYPTO_SALT)
                                    TransObj.save()

                Last.Value = NewBlock
                Last.save()
Пример #2
0
def crypto_currency_withdraw_submit(Req):
    
    
    Dict = {"use_f2a": False}     
    
    if Req.session.has_key("use_f2a"):
             Dict["use_f2a"] =  Req.session["use_f2a"]
            
    Form = CurrencyTransferForm(data = Req.POST, user = Req.user )  
    getcontext().prec = settings.TRANS_PREC
    
    if Form.is_valid():
        # Save 
        Key = generate_key("currency_withdraw")
                
        Amnt  = Decimal(Form.cleaned_data["amnt"]) - Form.comission

        transfer = CryptoTransfers(
                                 account = Form.cleaned_data["wallet"],
                                 currency = Form.currency_instance,
                                 amnt = Amnt,
                                 comission = Form.comission,
                                 user = Req.user,
                                 confirm_key = Key,
                                 debit_credit = "out"
                              )
        transfer.save()
        
        #if settings.DEBUG is False:        
        send_mail(_(u'Подтверждение вывода  ') + settings.BASE_HOST,
                                    confirm_crypto_withdraw_email(Form.cleaned_data, Key),
                                    settings.EMAIL_HOST_USER,
                                   [ Req.user.email ],
                                     fail_silently = False)  
        
        return redirect("/finance/confirm_withdraw_msg")                
    else :
        t = loader.get_template("simple_form.html")   
        Dict["form"] = Form.as_p()
        CurrencyIn = Currency.objects.get(title = Form.cleaned_data["currency"]) 
        
        Dict["currency"] = Form.cleaned_data["currency"]
        TradePair = TradePairs.objects.get(currency_on = CurrencyIn,
                                           currency_from  = CurrencyIn )      
        Dict["common_help_text"] = settings.attention_be_aware_crypto % ( str(TradePair.min_trade_base) )        
        Dict["action"] = "/finance/crypto_currency_withdraw_submit"
        Dict["action_title"] = settings.withdraw_transfer        
        Dict["pin_load"] = not Dict["use_f2a"]
        return tmpl_context(Req, t, Dict)
Пример #3
0
def crypto_currency_withdraw_submit(Req):
    Dict = {"use_f2a": False}
    if Req.session.has_key("use_f2a"):
        Dict["use_f2a"] = Req.session["use_f2a"]
    Form = CurrencyTransferForm(data=Req.POST, user=Req.user)
    getcontext().prec = settings.TRANS_PREC

    if Form.is_valid():
        # Save 
        Key = generate_key("currency_withdraw")
        Amnt = Decimal(Form.cleaned_data["amnt"]) - Form.comission
        transfer = CryptoTransfers(account=Form.cleaned_data["wallet"],
                                   currency=Form.currency_instance,
                                   amnt=Amnt,
                                   pub_date=datetime.datetime.now(),
                                   comission=Form.comission,
                                   user=Req.user,
                                   confirm_key=Key,
                                   debit_credit="out")
        transfer.save()
        #if settings.DEBUG is False:
        send_mail(_(u'Подтверждение вывода  ') + settings.BASE_HOST,
                  confirm_crypto_withdraw_email(Form.cleaned_data, Key),
                  [Req.user.email],
                  fail_silently=False)

        return redirect("/finance/confirm_withdraw_msg")
    else:
        t = loader.get_template("simple_form.html")
        Dict["form"] = Form.as_p()
        CurrencyIn = Currency.objects.get(title=Form.cleaned_data["currency"])

        Dict["currency"] = Form.cleaned_data["currency"]
        TradePair = TradePairs.objects.get(currency_on=CurrencyIn,
                                           currency_from=CurrencyIn)
        Dict["common_help_text"] = settings.attention_be_aware_crypto % ( str(TradePair.min_trade_base) )
        Dict["action"] = "/finance/crypto_currency_withdraw_submit"
        Dict["action_title"] = settings.withdraw_transfer
        Dict["pin_load"] = not Dict["use_f2a"]
        return tmpl_context(Req, t, Dict)
Пример #4
0
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 
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  trans.has_key("blocktime")  and trans["blocktime"]<Time:
#			print "old transactions ";
#			print "blocktime is %i " % trans["blocktime"]
                        continue

		#if trans["amount"]<0.0001:
		#	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:
#                               notify_admin_withdraw(u"unrecognized crypto incoming to %s %s %s" % (trans["address"],
 #                                                                                                    Decimal,
  #                                                                                                   CurrencyTitle
   #                                                                                                  ) ) 
                               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()
#				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()
Пример #6
0
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] = i
    MissTranses = [
        "b7985ff9ae2c031d2a1a2aa2864036dff423e4a7e226f20ae6a05b8d10f12162",
        "e362eff1219e019a5891d288d3fbd6121ae127e3149f5566d8d3aebd71bd418e",
        "2f0d76ce32f5e182ebd0793dbd8000ea4e70b56c14462b4a32dd1bcb83621c32",
        "ffd420f3b20d516e44039cbae5a92d894258cadf7b6223ebd8b77e7b7bdcbc2e",
        "f661f7282a0280c0a8a73938c2726a9da8ab95f3ad17bd1fb8abccd76e510782",
        "5281dc88bed3f694e9968446d9003b68aa45bc4a6822f256a1d2c0d01c57fd29",
        "9c7d126f79f6e956c8de771fe585b3f6159f5df40fbccf1c3c33cdca0e853095"
    ]

    ForAccount = "1KRgYSAChvP5UFUQBQfqAHih2kEYW1CThD"

    for Trans in MissTranses:
        time.sleep(1)
        print "process adress %s" % (Trans)
        trans = None
        trans = get_trans(Trans)

        Txid = trans["hash"]

        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"], ForAccount)
        except:
            print "get error during processing the %s" % trans
            continue

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

        print "confirmations %i" % (Confirmations)
        print " amount of %s" % (Decimal)
        TransObj = None
        try:
            TransObj = CryptoTransfers.objects.get(crypto_txid=Trans,
                                                   account=ForAccount)
            print "trans %s is existed to %s  amnt %s %i" % (
                TransObj.crypto_txid, TransObj.user.username, TransObj.amnt,
                TransObj.id)
            print "it's not a missed trans"
            continue

        except CryptoTransfers.DoesNotExist:
            suffix = ForAccount[:-10]
            print "trans %s  to save  %s  amnt %s" % (Trans.hash,
                                                      output.address, Decimal)
            TransObj = CryptoTransfers(crypto_txid=Trans + "_" + suffix,
                                       status="processing",
                                       amnt=Decimal,
                                       currency=CurrencyInstance,
                                       account=ForAccount,
                                       user=OwnAccounts[ForAccount],
                                       confirms=0)
            TransObj.save()

        print "#%i receive %s to %s amount of %s" % (
            Trans.id, Txid, Trans.user.username, Trans.amnt)
        print "this trans is %s" % (Trans.status)
        continue
        if Trans.status == "processing" or Trans.status == "created":
            print "update confirmations"
            Trans.status = "processing"
            Trans.confirms = Confirmations
            Trans.save()

        if Confirmations >= CryptoSettings["BTC"][
                "min_confirmation"] and Trans.status != "processed":
            Trans.confirms = Confirmations
            crypton_in(Trans, user_system)
            Trans.status = "processed"
            Trans.save()
Пример #7
0
                print "block get"
                for Trans in Block.transactions:
                        for output in Trans.outputs :
                            if OwnAccounts.has_key( output.address):
                               if is_out(Trans.inputs, OwnAccounts ):
                                   break
                               else:
                                    Decimal = sato2Dec(output.value)
                                    try :
                                            TransObj = CryptoTransfers.objects.get(crypto_txid = Trans.hash) 
                                            print "trans %s is existed to %s  amnt %s" % (TransObj.crypto_txid, TransObj.user.username, TransObj.amnt)  
                                    except  CryptoTransfers.DoesNotExist:   
                                            print "trans %s  to save  %s  amnt %s" % (Trans.hash, output.address, Decimal)
                                            TransObj =  CryptoTransfers(crypto_txid = Trans.hash,
                                                                    status="processing",
                                                                    amnt = Decimal,
                                                                    currency = CurrencyInstance ,
                                                                    account = output.address,
                                                                    user = OwnAccounts[ output.address ],
                                                                    confirms = 0   
                                                                    )
                                            TransObj.save()
           
                Last.Value = NewBlock
                Last.save()
            #except:
	#	print "cant finish operation"