Ejemplo n.º 1
0
def crypto_currency_get_account(request, CurrencyTitle):
    CurrencyIn = Currency.objects.get(title=CurrencyTitle)
    # TODO add working with ref through Account class
    Crypton = CryptoAccount(CurrencyTitle, "")
    CurIns = Currency.objects.get(title = CurrencyTitle)
    tmpl = loader.get_template("new_addresses.html")
        
    bulk_add = []
    Addresses = {}
    try:               
        for i in xrange(1, 500):
            FreeAccount = PoolAccounts(currency = CurIns, status = "created")                      
            FreeAccount.pub_date = date.today() 
            NewAdress  = Crypton.getnewaddress()
            FreeAccount.address = NewAdress 

            try:
                FreeAccount.save()
                print "new address %s"  % NewAdress   
                bulk_add.append(NewAdress)
            except:
                print "repeat address %s" % (NewAdress)
    except:
        print "caught exception"
        traceback.print_exc()
    print "continue to work"    
    Dict  = {"addressess" : "\n".join(bulk_add) }
    return http_tmpl_context(request, tmpl, Dict)
Ejemplo n.º 2
0
def home(Req):
    if not Req.user.is_authenticated():
        return login_page_with_redirect(Req)
    else:
        t = loader.get_template("finance.html")
        Dict = {}
        # it is not an actual information
        user_id =  Req.user.id

        All = Accounts.objects.filter(user_id=user_id).order_by('-currency__ordering')

        OrdersBalances = {}
       
        ResAcc = []
        for i in All:
            item = {}
            
            crypto_account  =  CryptoAccount(i.currency.title, "")
            try:
                i.balance = crypto_account.getbalance()
                item["balance"] = i.balance
            except :
                traceback.print_exc()
                item["balance"] = "not Avalible"
                
            currency_id = i.currency.id
            item["currency"] = i.currency
            ResAcc.append(item)
            
        Dict["page_accounts"] = ResAcc
        return tmpl_context(Req, t, Dict)
Ejemplo n.º 3
0
def process_in_crypto(CurrencyTitle):
    List = None
    crypto_acc = "trade_stock"
    if CurrencyTitle in ("ZEC"):
        crypto_acc = ""
    Crypton = CryptoAccount(CurrencyTitle, crypto_acc)
    print "process %s" % CurrencyTitle
    TimeLastBlock = None
    TopBlock = int(Crypton.getblockcount())
    print "top block %i" % TopBlock
    try:
        TimeLastBlock = VolatileConsts.objects.get(
            Name="last_process_block_%s" % CurrencyTitle)
        TimeLastBlock.Value = int(TimeLastBlock.Value)

    except VolatileConsts.DoesNotExist:
        count = TopBlock - 100
        TimeLastBlock = VolatileConsts(Name="last_process_block_%s" %
                                       CurrencyTitle,
                                       Value=str(count))
        TimeLastBlock.save()

    Time = int(TimeLastBlock.Value)
    print "start process block %i " % Time

    user_system = User.objects.get(id=1)
    CurrencyInstance = Currency.objects.get(title=CurrencyTitle)
    getcontext().prec = crypton.settings.TRANS_PREC
    block_hash = Crypton.getblockhash(Time - 200)
    print "block %s" % block_hash
    List = Crypton.listsinceblock(block_hash)
    List = List["transactions"]
    process_in_crypto_low(List, user_system, CurrencyInstance)
    TimeLastBlock.Value = str(TopBlock)
    TimeLastBlock.save()
Ejemplo n.º 4
0
def check_crypto_balance(Currency, Correction="0", check_wallet=True):
    cursor = connection.cursor()
    cursor.execute(
        "SELECT sum(balance) FROM main_accounts WHERE currency_id=%i AND balance>0"
        % Currency.id)
    s = cursor.fetchone() * 1
    if s == (None, ):
        s = Decimal("0.0")
    else:
        (s, ) = s

    cursor.execute(
        "SELECT sum(amnt) FROM main_cryptotransfers WHERE debit_credit='out' \
			AND status in ('processing','processing2','created') AND pub_date>='2015-05-08' and currency_id=%i "
        % Currency.id)

    s1 = cursor.fetchone() * 1
    if s1 == (None, ):
        s1 = Decimal("0.0")
    else:
        (s1, ) = s1

    cursor.execute(
        "SELECT sum(amnt) FROM main_cryptotransfers WHERE debit_credit='in' \
			AND status in ('processing', 'processing2') AND confirms>0 AND pub_date>='2015-05-08' and currency_id=%i "
        % Currency.id)

    s2 = cursor.fetchone() * 1
    if s2 == (None, ):
        s2 = Decimal("0.0")
    else:
        (s2, ) = s2

    Crypton = None
    Balance = None
    if check_wallet:
        if Currency.title in ("KRB", ):

            Crypton = CryptoAccountKrb(Currency.title, "trade_stock")
            Balance = Crypton.getbalance()

        if Currency.title in ("XMR", ):
            rpc_url = CryptoSettings[Currency.title]["host"]
            req = {"jsonrpc": "2.0", "method": "getbalance", "id": 1}
            resp = requests.post(rpc_url, data=json.dumps(req))
            print resp.json()
            Balance = float(resp.json()["result"]["balance"]) / PREC_KRB
            Balance = "%.12f" % (Balance)

        if Currency.title in ("ZEC", "BCH", "DOGE", "TLR", "FNO"):

            Crypton = CryptoAccount(Currency.title, "")
            Balance = Crypton.getbalance()

        if Currency.title in ("XRP", ):
            Crypton = CryptoAccountXrp(Currency.title, "")
            Balance = Crypton.getbalance(CryptoSettings[Currency.title]["acc"])

        if Currency.title in ("XEM", ):
            Crypton = CryptoAccountXem(Currency.title, "")
            Balance = Crypton.getbalance(CryptoSettings[Currency.title]["acc"])

        if Currency.title in ("LTC", "NVC", "DOGE", "ITI", "DASH", "PPC",
                              "CLR", "SIB"):

            Crypton = CryptoAccount(Currency.title, "trade_stock")

            Balance = Crypton.getbalance()

        change_volitile_const("balance_corr_" + Currency.title, Correction)
        change_volitile_const("balance_out_" + Currency.title, str(Balance))
    print "balance in system %s" % s
    print "balance on wallet " + str(Balance)
    print s1 + s
    if check_wallet:
        Delta = (Decimal(Balance) - s1 - s - s2 + Decimal(Correction))
        print "Delta is %s " % Delta
        return Delta > 0
    return True
Ejemplo n.º 5
0
from blockchain.blockexplorer import get_address
from sdk.crypto import CryptoAccount
import time
with open("keys1") as f:
    L = f.readlines()
    Sum = 0

    Dict = {}
    for address in L:
        if Dict.has_key(address):
            continue

        address = address.replace("\n", "")
        Dict[address] = 1

        D = CryptoAccount("BTC")
        #Res = get_address(address)
        print "%s,%s" % (address, D.dumpprivkey(address))
        #print address
        #print Res.final_balance

        #Sum += Res.final_balance
        #time.sleep(1)
Ejemplo n.º 6
0
def check_btc_balance(verbose=False):
    cursor = connection.cursor()
    cursor.execute(
        "SELECT sum(balance) FROM main_accounts WHERE currency_id=2 AND balance>0 "
    )
    s = cursor.fetchone() * 1
    if s == (None, ):
        s = Decimal("0.0")
    else:
        (s, ) = s
    main_account = Accounts.objects.get(id=13)

    blockchain.util.TIMEOUT = 300

    cursor.execute(
        "SELECT sum(if(debit_credit='in',-1*amnt, amnt)) "
        "FROM main_cryptotransfers WHERE status in ('processing','created','processing2')   AND currency_id=2 AND pub_date>='2015-05-08' "
    )

    s1 = cursor.fetchone() * 1
    if s1 == (None, ):
        s1 = Decimal("0.0")
    else:
        (s1, ) = s1
    SERVICE_URL = settings.blockchaininfo_service
    (Balance1, Balance2, Balance3, Balance4, Balance5, Balance6,
     Balance8) = (0, 0, 0, 0, 0, 0, 0)
    Balance7 = 0
    Balance9 = 0
    Balance10 = 0
    Balance11 = 0
    Balancecold = sato2Dec(get_balance("1AMTTKEAav9aQDotyhNg4Z7YSUBYTTA6ds",
                                       0))
    Balancecold = sato2Dec(get_balance("19jHRHwuHnQQVajRrW976aCXYYdgij8r43",
                                       0)) + Balancecold
    Balancecold = sato2Dec(get_balance("17iAu7iSSwo9VGeNn6826Lz1qLPq152xAW",
                                       0)) + Balancecold
    Balancecold = sato2Dec(get_balance("15c3H6jhQys8b8M5vszx2s21UNDH3caz9P",
                                       0)) + Balancecold
    Balancecold = sato2Dec(get_balance("19YxpMLUAdZoJpUBqwURcJzd2zs4knMvGV",
                                       0)) + Balancecold

    Balance1 = sato2Dec(get_balance("167GWdfvG4JtkFErq4qBBLqKYFK26dhgDJ",
                                    0)) + Balance1
    Balance1 = sato2Dec(get_balance("1Q1woBCCGiuELYzVvS3hCgSs6pFKuqHNpt",
                                    0)) + Balance1
    Balance1 = sato2Dec(get_balance("19TaiL4j288Zgm1AQXUwMcyLup7vki54Fs",
                                    0)) + Balance1
    Balance1 = sato2Dec(get_balance("13EDdpizTP3grQQAnpCtSJNTTwkDkV9VeB",
                                    0)) + Balance1
    Balance1 = sato2Dec(get_balance("1AXKnEK3P1tiHEBAVpDzg4k3yXosR5oKL8",
                                    0)) + Balance1
    Balance1 = sato2Dec(get_balance("1GjthoqTvBq1N8KkKVEDHV9b8snmt2ehcS",
                                    0)) + Balance1
    Balance1 = sato2Dec(get_balance("1LvDnHktCL77r16eimv7Fr9d5xDieb1wFC",
                                    0)) + Balance1
    Balancecold = sato2Dec(get_balance("15jsdKn3L8ExQngY8HRRUz3prof8mAn8yr",
                                       0)) + Balancecold
    HotWalletBalance = sato2Dec(
        get_balance("1LNYCGkXtJscvMHHucEfpxWMBnf33Ke18W", 0))

    Crypton = Wallet("2b835907-d012-4552-830c-6116ab0178f2",
                     "#Prikol13_",
                     service_url=SERVICE_URL,
                     api_code="b720f286-9b3f-452c-b93c-969c8dd3967f")
    Crypton1 = Wallet("772bb645-48f5-4328-9c3d-3838202132d6",
                      "xxx_21_34_Zb",
                      service_url=SERVICE_URL,
                      api_code="b720f286-9b3f-452c-b93c-969c8dd3967f")
    Crypton2 = Wallet("ee23c1bd-d3dd-4661-aef5-8e342c7f5960",
                      "xxx_21_34_Zb",
                      service_url=SERVICE_URL,
                      api_code="b720f286-9b3f-452c-b93c-969c8dd3967f")
    Crypton3 = Wallet("e6202826-bb24-435c-8350-b4a942b4380b",
                      "xxx_21_34_Zb",
                      service_url=SERVICE_URL,
                      api_code="b720f286-9b3f-452c-b93c-969c8dd3967f")
    Crypton4 = Wallet("3ccaa767-770f-476f-a836-9db1c005055e",
                      "_quenobi8610",
                      service_url=SERVICE_URL,
                      api_code="b720f286-9b3f-452c-b93c-969c8dd3967f")
    Crypton5 = Wallet("caa19b23-198a-4aad-a9c0-3f80efe37118",
                      "dirty_43_13",
                      service_url=SERVICE_URL,
                      api_code="b720f286-9b3f-452c-b93c-969c8dd3967f")
    Crypton6 = Wallet("14ef48bb-4d71-4bc4-be34-75ba0978202f",
                      "dirty_43_13",
                      service_url=SERVICE_URL,
                      api_code="b720f286-9b3f-452c-b93c-969c8dd3967f")
    Crypton7 = Wallet("913d6442-fc77-4b7b-b5f8-af272e458897",
                      "xxx_21_34_Zb",
                      service_url=SERVICE_URL,
                      api_code="b720f286-9b3f-452c-b93c-969c8dd3967f")
    Crypton8 = Wallet("5432b01c-f67e-473e-aa4c-29cd9682b259",
                      "xxx_21_34_Zb",
                      service_url=SERVICE_URL,
                      api_code="b720f286-9b3f-452c-b93c-969c8dd3967f")  #
    Crypton9 = Wallet("a2ba7138-2bd3-4898-b68b-d0908d40bc4d",
                      "xxx_21_34_Zb",
                      api_code="b720f286-9b3f-452c-b93c-969c8dd3967f",
                      service_url=SERVICE_URL)  #

    Crypton10 = Wallet("d8d5ce8a-6ff9-4f7e-80f3-08cac5788781",
                       "xxx_21_34_Zb",
                       api_code="b720f286-9b3f-452c-b93c-969c8dd3967f",
                       service_url=SERVICE_URL)  #

    Crypton11 = Wallet("eb836197-285e-44ee-a8cf-5642a02e6250",
                       "#Prikol13_",
                       api_code="b720f286-9b3f-452c-b93c-969c8dd3967f",
                       service_url=SERVICE_URL)  #
    Crypton12 = Wallet("c800e14e-95d4-4fcf-816b-696fbaaf5741",
                       "xxx_21_34_Zb",
                       api_code="b720f286-9b3f-452c-b93c-969c8dd3967f",
                       service_url=SERVICE_URL)

    Crypton13 = Wallet("e60c37e7-4375-44ea-b167-a63b453c14a1",
                       "#Prikol13_",
                       api_code="b720f286-9b3f-452c-b93c-969c8dd3967f",
                       service_url=SERVICE_URL)

    Crypton14 = Wallet("118344b4-5d26-4cfe-871a-0c3393ee5db0",
                       "#Prikol13_",
                       api_code="b720f286-9b3f-452c-b93c-969c8dd3967f",
                       service_url=SERVICE_URL)
    Crypton15 = Wallet("f252bb25-6b99-4e49-a5cf-41489eefb728",
                       "#Prikol13_",
                       api_code="b720f286-9b3f-452c-b93c-969c8dd3967f",
                       service_url=SERVICE_URL)
    Crypton16 = Wallet("5a778945-fbb4-4692-b448-fd5b513c008d",
                       "#Prikol13_",
                       api_code="b720f286-9b3f-452c-b93c-969c8dd3967f",
                       service_url=SERVICE_URL)
    Balance2 = sato2Dec(Crypton.get_balance())
    print "Balance of hot wallet 1 " + str(Balance2)

    Balance3 = sato2Dec(Crypton1.get_balance()) + sato2Dec(
        Crypton4.get_balance())
    print "Balance of hot wallet 2 " + str(Balance3)
    Balance4 = sato2Dec(Crypton2.get_balance())
    print "Balance of hot wallet 3 " + str(Balance4)
    Balance5 = sato2Dec(Crypton3.get_balance())
    print "Balance of hot wallet 4 " + str(Balance5)
    Balance6 = sato2Dec(Crypton5.get_balance())
    print "Balance of hot wallet 5 " + str(Balance6)
    Balance7 = sato2Dec(Crypton6.get_balance())
    print "Balance of hot wallet 6 " + str(Balance7)
    Balance8 = sato2Dec(Crypton7.get_balance())
    print "Balance of hot wallet 7 " + str(Balance8)

    Balance9 = sato2Dec(Crypton8.get_balance())
    print "Balance of hot wallet 8 " + str(Balance9)
    Balance10 = sato2Dec(Crypton9.get_balance())
    print "Balance of hot wallet 9 " + str(Balance10)

    Balance11 = sato2Dec(Crypton10.get_balance())
    print "Balance of hot wallet 10 " + str(Balance11)

    Balance12 = sato2Dec(Crypton11.get_balance())
    print "Balance of hot wallet 12 " + str(Balance12)

    Balance13 = sato2Dec(Crypton12.get_balance())
    print "Balance of hot wallet 13 " + str(Balance13)
    Balance14 = sato2Dec(Crypton13.get_balance())
    print "Balance of hot wallet 14 " + str(Balance14)
    Balance15 = sato2Dec(Crypton14.get_balance())
    print "Balance of hot wallet 15 " + str(Balance15)

    Balance16 = sato2Dec(Crypton15.get_balance())
    print "Balance of hot wallet 16 " + str(Balance16)
    Balance17 = sato2Dec(Crypton16.get_balance())
    print "Balance of hot wallet 17 " + str(Balance17)
    Dismiss = Decimal("0.0")
    Crypton = CryptoAccount("BTC", "trade_stock")
    LChange = Crypton.listaddressgroupings()
    BalanceCore = Decimal(str(Crypton.getbalance()))
    if False:
        for adres in LChange[0]:
            if not adres[0] in ("1LNYCGkXtJscvMHHucEfpxWMBnf33Ke18W",
                                "1CzLixrLpf6LRiiqH5jMZ7dD3GP2gDJ4xw",
                                "1FLCVHDDwJmimjgch5s4CtjpbNn5pQ3mAi"):
                BalanceCore += Decimal(str(adres[1]))

    BalanceOnHots = BalanceCore + Balance11 + Balance10 + Balance1 + Balance2 + Balance3 + Balance4 + Balance5 + Balance6 + Balance7 + Balance8 + Balance9 + Balance12 + Balance13 + Balance14 + Balance15 + Balance16 + Balance17

    print "our core wallet " + str(BalanceCore)
    print "Correction " + str(Dismiss)
    print "balance of cold wallet " + str(Balancecold)
    print "balance on hots wallet " + str(BalanceOnHots)
    print "balance of accounts " + str(s)
    print "main accounts balance " + str(main_account.balance)
    print "checking consistens %s" % (s + main_account.balance)
    print "balance of processing  " + str(s1)
    print "sum on walletes " + str(Balancecold + BalanceOnHots)
    print "sum in system " + str(s1 + s)
    change_volitile_const("balance_corr_BTC", Dismiss)
    change_volitile_const("balance_out_BTC", str(Balancecold + BalanceOnHots))

    Delta = Balancecold + BalanceOnHots - s - s1 + Dismiss
    print "Delta is %s " % Delta
    return Delta >= 0